Compare commits

...

3 Commits

Author SHA1 Message Date
ac850adfcf issue #
- 팔로우 DTO 구현 중
2025-12-17 23:50:37 +09:00
geonhee-min
b4525bd13d 1.0.23 2025-12-17 09:49:47 +09:00
geonhee-min
963c78c35a issue #
- 커스텀 데코레이터, class-validator 적용
2025-12-17 09:49:42 +09:00
14 changed files with 143 additions and 4 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@baekyangdan/core-utils",
"version": "1.0.22",
"version": "1.0.23",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@baekyangdan/core-utils",
"version": "1.0.22",
"version": "1.0.23",
"license": "ISC",
"dependencies": {
"@swc/core": "^1.15.5",

View File

@@ -1,6 +1,6 @@
{
"name": "@baekyangdan/core-utils",
"version": "1.0.22",
"version": "1.0.23",
"description": "Common Repo",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@@ -0,0 +1,12 @@
type Decorator = (target: Object, propertyKey: string | symbol) => void;
export function composeDecorators(...decorators: Decorator[]): Decorator {
return (
target: Object,
property: string | symbol
) => {
for (const decorator of decorators) {
decorator(target, property);
}
}
}

View File

@@ -0,0 +1,11 @@
import { getMessage } from "../type/class-validator/MessageType";
import { composeDecorators } from "./composer";
import { IsNotEmpty } from "class-validator";
export function IsRequired() {
const notEmptyMessage = getMessage('REQUIRED');
return composeDecorators(
IsNotEmpty({ message: notEmptyMessage })
);
}

View File

@@ -0,0 +1,23 @@
import { getMessage } from "../type/class-validator/MessageType";
import { composeDecorators } from "./composer";
import { IsIn, IsArray } from "class-validator";
export function IsValid(allowedValues: ReadonlyArray<any>, isArray: boolean = false) {
const allowedValuesString = allowedValues.join(', ');
if (isArray) {
return composeDecorators(
IsArray({ message: `TYPE: The type of $property must be array.`}),
IsIn(allowedValues, {
each: true,
message: `${getMessage('INVALID_ARRAY')} Valid values: ${allowedValuesString}`
})
);
}
return composeDecorators(
IsIn(allowedValues, {
message: `${getMessage('INVALID')} Valid values: ${allowedValuesString}`
})
);
}

View File

@@ -0,0 +1,16 @@
import { IsRequired } from "src/scheduler/decorator/required-decorator";
import { IsString } from 'class-validator';
import { getMessage } from "src/scheduler/type/class-validator/MessageType";
import type { BaseResponseDTO } from "../../base/base-response.dto"
export class FollowList {
@IsRequired()
@IsString({ message: getMessage('TYPE') })
id!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
name!: string;
}
export type FollowListResponse = BaseResponseDTO<FollowList[]>;

View File

@@ -2,26 +2,72 @@ import type { BaseResponseDTO } from '@BaseResponseDTO';
import type { Status } from 'src/scheduler/type/schedule/ScheduleStatus';
import type { Type } from 'src/scheduler/type/schedule/ScheduleType';
import { Type as TransformType } from 'class-transformer';
import { IsRequired } from 'src/scheduler/decorator/required-decorator';
import { IsArray, IsBoolean, IsDate, IsOptional, IsString, ValidateIf } from 'class-validator';
import { getMessage } from 'src/scheduler/type/class-validator/MessageType';
export class ScheduleDetail {
@IsRequired()
@IsString({ message: getMessage('TYPE')})
id!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE')})
name!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
status!: Status;
@ValidateIf(o => o.content !== undefined && o.content !== null)
@IsString({ message: getMessage('TYPE') })
content?: string;
@IsRequired()
@IsBoolean({ message: getMessage('TYPE')})
isDeleted!: boolean;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
type!: Type;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
createdAt!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
owner!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
style!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
startTime!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE') })
endTime!: string;
@ValidateIf(o => o.dayList !== undefined && o.dayList !== null)
@IsString({ message: getMessage('TYPE') })
dayList?: string;
participantList?: string;
@ValidateIf(o => o.participantList !== undefined && o.participantList !== null)
@IsArray()
@IsString({ each: true, message: getMessage('TYPE') })
participantList?: string[];
@TransformType(() => Date)
@IsRequired()
@IsDate({ message: getMessage('TYPE') })
startDate!: Date;
@TransformType(() => Date)
@IsRequired()
@IsDate({ message: getMessage('TYPE') })
endDate!: Date;
}

View File

@@ -2,18 +2,39 @@ import type { BaseResponseDTO } from '@BaseResponseDTO';
import type { Status } from "src/scheduler/type/schedule/ScheduleStatus";
import type { Type } from "src/scheduler/type/schedule/ScheduleType";
import { Type as TransformType } from 'class-transformer';
import { IsDate, IsString } from 'class-validator';
import { IsRequired } from 'src/scheduler/decorator/required-decorator';
import { getMessage } from 'src/scheduler/type/class-validator/MessageType';
export class ScheduleList {
@IsRequired()
@IsString({ message: getMessage('TYPE') })
name!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE')})
id!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE')})
type!: Type;
@IsRequired()
@IsString({ message: getMessage('TYPE')})
style!: string;
@IsRequired()
@IsString({ message: getMessage('TYPE')})
status!: Status;
@TransformType(() => Date)
@IsRequired()
@IsDate()
startDate!: Date;
@TransformType(() => Date)
@IsRequired()
@IsDate()
endDate!: Date;
}

View File

@@ -0,0 +1,10 @@
export type MessageType = 'REQUIRED' | 'TYPE' | 'INVALID' | 'INVALID_ARRAY';
export const getMessage = (type: MessageType) => {
switch (type) {
case 'REQUIRED': return `REQUIRED: $property is required entity.`;
case 'TYPE': return `TYPE: The type of $property is invalid.`;
case 'INVALID': return `INVALID: The value of $property($value) is invalid.`;
case 'INVALID_ARRAY': return `INVALID_ARRAY: The $property array includes invalid value($value).`
}
}