generated from Medici-Mansion/basic-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.2.5
- Loading branch information
Showing
8 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "shinnyang", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "", | ||
"author": { | ||
"name": "Medici", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum ServiceProvider { | ||
GOOGLE = 'google', | ||
KAKAO = 'kakao', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString, MaxLength } from 'class-validator'; | ||
import { IsString } from 'class-validator'; | ||
import { MaxByteLength } from '../validator/max-length-byte.validator'; | ||
|
||
export class ChangeNicknameDTO { | ||
@ApiProperty({ description: '번경할 닉네임', default: '츄츄' }) | ||
@IsString() | ||
@MaxLength(6) | ||
@MaxByteLength(12, { | ||
message: '닉네임이 너무 길어요.', | ||
}) | ||
nickname: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { registerDecorator, ValidationOptions } from 'class-validator'; | ||
|
||
const LINE_FEED = 10; // '\n' | ||
|
||
export function getByteLength(decimal: number) { | ||
return decimal >> 7 || LINE_FEED === decimal ? 2 : 1; | ||
} | ||
|
||
export function getLimitedByteText(inputText: string, maxByte: number) { | ||
const characters = inputText.split(''); | ||
|
||
return ( | ||
characters.reduce((acc, cur) => { | ||
const decimal = cur.charCodeAt(0); | ||
const byte = getByteLength(decimal); // 글자 한 개가 몇 바이트 길이인지 구해주기 | ||
return acc + byte; | ||
}, 0) <= maxByte | ||
); | ||
} | ||
|
||
export function MaxByteLength( | ||
max: number, | ||
validationOptions?: ValidationOptions, | ||
) { | ||
return function (object: object, propertyName: string) { | ||
registerDecorator({ | ||
name: 'MaxByteLength', | ||
target: object.constructor, | ||
async: false, | ||
propertyName: propertyName, | ||
constraints: [], // * 아래 validate 의 args.contraints로 넘어감 | ||
options: validationOptions, | ||
validator: { | ||
validate(value: any): boolean { | ||
return getLimitedByteText(value, max); | ||
}, | ||
}, | ||
}); | ||
}; | ||
} |