From 0ac0c1d913eb5b61e506712560002e096b0ebe06 Mon Sep 17 00:00:00 2001 From: Hyo Date: Mon, 17 Mar 2025 10:14:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20user,=20auto,=20customer=20DTO?= =?UTF-8?q?=20=EA=B0=9C=ED=8E=B8=20=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/presentation/auth.dto.ts | 23 +++- src/auth/presentation/user.dto.ts | 100 ++++++++++++-- src/customer/presentation/customer.dto.ts | 152 +++++++++++++++++++--- 3 files changed, 246 insertions(+), 29 deletions(-) diff --git a/src/auth/presentation/auth.dto.ts b/src/auth/presentation/auth.dto.ts index 0b2d51a..8731c51 100644 --- a/src/auth/presentation/auth.dto.ts +++ b/src/auth/presentation/auth.dto.ts @@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsNotEmpty, IsOptional } from 'class-validator'; import { UserDto } from './user.dto'; import { CrudGroup } from '../../common/validation/validation.data'; +import { Expose } from "class-transformer"; export class AuthDto extends UserDto { @ApiProperty({ @@ -9,14 +10,32 @@ export class AuthDto extends UserDto { type: String, }) @IsOptional() - accessToken?: string; + private _accessToken?: string; @ApiProperty({ description: 'Refresh Token', type: String, }) @IsOptional() - refreshToken?: string; + private _refreshToken?: string; + + @Expose() + get accessToken(): string | undefined { + return this._accessToken; + } + + set accessToken(value: string) { + this._accessToken = value; + } + + @Expose() + get refreshToken(): string | undefined { + return this._refreshToken; + } + + set refreshToken(value: string) { + this._refreshToken = value; + } } export interface OtpRequest { diff --git a/src/auth/presentation/user.dto.ts b/src/auth/presentation/user.dto.ts index a913222..a2a959e 100644 --- a/src/auth/presentation/user.dto.ts +++ b/src/auth/presentation/user.dto.ts @@ -3,6 +3,7 @@ import { Builder } from 'builder-pattern'; import { IsIn, IsNotEmpty, IsOptional } from 'class-validator'; import { CrudGroup } from '../../common/validation/validation.data'; import { Customer } from '../../customer/customer.domain'; +import { Expose } from "class-transformer"; // 고객, 업체, 기사 공통 사용 DTO export type UserType = 'customer' | 'driver' | 'business'; @@ -24,7 +25,7 @@ export class UserDto { description: '인증 제공자 타입', required: true, }) - authProvider?: AuthProvider; + protected _authProvider?: AuthProvider; @ApiProperty({ description: '사용자가 고객인지, 기사인지, 업체인지 확인하는 타입입니다.', @@ -33,7 +34,7 @@ export class UserDto { @IsIn(['customer', 'driver', 'business'], { groups: [UserGroup.login] }) @IsOptional() @IsNotEmpty({ groups: [UserGroup.login] }) - userType?: UserType; + protected _userType?: UserType; @ApiProperty({ description: @@ -42,29 +43,110 @@ export class UserDto { }) @IsNotEmpty({ groups: [CrudGroup.create] }) @IsOptional() - userId?: number; + protected _userId?: number; @ApiProperty({ description: '사용자 전화번호입니다. 현재는 customer, business에서만 사용합니다.', required: false, }) - phoneNumber?: string; + protected _phoneNumber?: string; @ApiProperty({ description: '사용자 UUID입니다.', required: false, }) - uuid?: string; + protected _uuid?: string; @ApiProperty({ description: '사용자 이름입니다.', }) - name?: string; + protected _name?: string; - customerId?: number; - driverId?: number; - businessId?: number; + protected _customerId?: number; + protected _driverId?: number; + protected _businessId?: number; + + @Expose() + get authProvider(): AuthProvider | undefined { + return this._authProvider; + } + + set authProvider(value: AuthProvider) { + this._authProvider = value; + } + + @Expose() + get userType(): UserType | undefined { + return this._userType; + } + + set userType(value: UserType) { + this._userType = value; + } + + @Expose() + get userId(): number | undefined { + return this._userId; + } + + set userId(value: number) { + this._userId = value; + } + + @Expose() + get phoneNumber(): string | undefined { + return this._phoneNumber; + } + + set phoneNumber(value: string | undefined) { + this._phoneNumber = value; + } + + @Expose() + get uuid(): string | undefined { + return this._uuid; + } + + set uuid(value: string) { + this._uuid = value; + } + + @Expose() + get name(): string | undefined { + return this._name; + } + + set name(value: string) { + this._name = value; + } + + @Expose() + get customerId(): number | undefined { + return this._customerId; + } + + set customerId(value: number) { + this._customerId = value; + } + + @Expose() + get driverId(): number | undefined { + return this._driverId; + } + + set driverId(value: number) { + this._driverId = value; + } + + @Expose() + get businessId(): number | undefined { + return this._businessId; + } + + set businessId(value: number) { + this._businessId = value; + } static from(customer: Customer): UserDto { return Builder(UserDto) diff --git a/src/customer/presentation/customer.dto.ts b/src/customer/presentation/customer.dto.ts index 1085de0..c6c1ff9 100644 --- a/src/customer/presentation/customer.dto.ts +++ b/src/customer/presentation/customer.dto.ts @@ -12,17 +12,38 @@ import { ApiProperty } from '@nestjs/swagger'; import { AuthDto } from '../../auth/presentation/auth.dto'; import { AuthProvider } from '../../auth/presentation/user.dto'; import { PresignedUrlDto } from '../../common/cloud/aws/s3/presentation/presigned-url.dto'; +import { Expose } from 'class-transformer'; -export class CustomerDto extends AuthDto { - @ApiProperty({ - description: 'Mongle Server에서의 고객 식별자', - required: false, - readOnly: true, - }) - @IsNumber() - @IsOptional() - override customerId?: number; +type CustomerType = { + get uuid(): string | undefined; + set uuid(value: string); + + get customerName(): string; + set customerName(value: string); + + get customerPhoneNumber(): string | undefined; + set customerPhoneNumber(value: string); + + get customerLocation(): Point | undefined; + set customerLocation(value: Point); + get customerAddress(): string | undefined; + set customerAddress(value: string); + + get customerDetailAddress(): string | undefined; + set customerDetailAddress(value: string); + + get authProvider(): AuthProvider; + set authProvider(value: AuthProvider); + + get profileImageUrl(): string | undefined; + set profileImageUrl(value: string); + + get presignedUrlDto(): PresignedUrlDto | undefined; + set presignedUrlDto(value: PresignedUrlDto); +}; + +export class BaseCustomerDto extends AuthDto implements CustomerType { @ApiProperty({ description: 'ResourceServer에서 제공한 유저 식별자', required: true, @@ -30,7 +51,7 @@ export class CustomerDto extends AuthDto { }) @IsNotEmpty() @Length(1, 44) - override uuid?: string; + protected override _uuid?: string; @ApiProperty({ description: '고객 이름', @@ -39,7 +60,7 @@ export class CustomerDto extends AuthDto { }) @IsNotEmpty() @Length(1, 30) - customerName: string; + protected _customerName: string; @ApiProperty({ description: '고객 전화번호', @@ -52,7 +73,7 @@ export class CustomerDto extends AuthDto { @Matches(/^(01[016789]{1})-[0-9]{3,4}-[0-9]{4}$/, { message: 'This is not Phone number ex) xxx-xxxx-xxxx', }) - customerPhoneNumber?: string; + protected _customerPhoneNumber?: string; @ApiProperty({ description: '고객 위치', @@ -60,7 +81,7 @@ export class CustomerDto extends AuthDto { required: false, }) @IsOptional() - customerLocation?: Point; + protected _customerLocation?: Point; @ApiProperty({ description: '고객 위치 주소', @@ -68,7 +89,7 @@ export class CustomerDto extends AuthDto { required: false, }) @IsOptional() - customerAddress?: string; + protected _customerAddress?: string; @ApiProperty({ description: '고객 위치 상세주소', @@ -76,7 +97,7 @@ export class CustomerDto extends AuthDto { required: false, }) @IsOptional() - customerDetailAddress?: string; + protected _customerDetailAddress?: string; @ApiProperty({ description: '인증 제공자 타입', @@ -84,16 +105,111 @@ export class CustomerDto extends AuthDto { }) @IsNotEmpty() @IsEnum(AuthProvider) - override authProvider: AuthProvider; + protected override _authProvider: AuthProvider; @ApiProperty({ description: '프로필 이미지 URL', }) - profileImageUrl?: string; + protected _profileImageUrl?: string; @ApiProperty({ description: '프로필 이미지 업데이트용 DTO', }) @ValidateNested() - presignedUrlDto?: PresignedUrlDto; + protected _presignedUrlDto?: PresignedUrlDto; + + @Expose() + override get uuid(): string | undefined { + return this._uuid; + } + + override set uuid(value: string) { + super.uuid = value; + } + + @Expose() + get customerName(): string { + return this._customerName; + } + set customerName(value: string) { + this._customerName = value; + } + + @Expose() + get customerPhoneNumber(): string | undefined { + return this._customerPhoneNumber; + } + set customerPhoneNumber(value: string | undefined) { + this._customerPhoneNumber = value; + } + + + @Expose() + get customerLocation(): Point | undefined { + return this._customerLocation; + } + set customerLocation(value: Point) { + this._customerLocation = value; + } + + @Expose() + get customerAddress(): string | undefined { + return this._customerAddress; + } + set customerAddress(value: string) { + this._customerAddress = value; + } + + @Expose() + get customerDetailAddress(): string | undefined { + return this._customerDetailAddress; + } + set customerDetailAddress(value: string) { + this._customerDetailAddress = value; + } + + @Expose() + override get authProvider(): AuthProvider { + return this._authProvider; + } + override set authProvider(value: AuthProvider) { + this._authProvider = value; + } + + @Expose() + get profileImageUrl(): string | undefined { + return this._profileImageUrl; + } + set profileImageUrl(value: string) { + this._profileImageUrl = value; + } + + @Expose() + get presignedUrlDto(): PresignedUrlDto | undefined { + return this._presignedUrlDto; + } + set presignedUrlDto(value: PresignedUrlDto) { + this._presignedUrlDto = value; + } +} + +export class CreateCustomerDto extends BaseCustomerDto { } + +export class CustomerDto extends BaseCustomerDto { + @ApiProperty({ + description: 'Mongle Server에서의 고객 식별자', + required: false, + readOnly: true, + }) + @IsNumber() + @IsOptional() + protected override _customerId: number; + + @Expose() + override get customerId(): number { + return this._customerId; + } + override set customerId(value: number) { + this._customerId = value; + } } From fe3e8b61cde66a4223fd64d5159b3c7339a81786 Mon Sep 17 00:00:00 2001 From: Hyo Date: Mon, 17 Mar 2025 19:59:54 +0900 Subject: [PATCH 2/2] todo --- src/customer/customer.domain.ts | 2 +- src/customer/presentation/customer.dto.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/customer/customer.domain.ts b/src/customer/customer.domain.ts index 89638c4..6fa2850 100644 --- a/src/customer/customer.domain.ts +++ b/src/customer/customer.domain.ts @@ -13,7 +13,7 @@ import { IDateHolder } from '../common/holder/date.holder'; import { PresignedUrlDto } from '../common/cloud/aws/s3/presentation/presigned-url.dto'; import { ImageDto } from '../common/image/presentation/image.dto'; -export interface ICustomer extends AuthDto { +export interface ICustomer extends AuthDto { // TODO: 도메인이 dto implement 중 (getter 가져오고 있음) customerId?: number; customerName: string; customerPhoneNumber?: string; diff --git a/src/customer/presentation/customer.dto.ts b/src/customer/presentation/customer.dto.ts index c6c1ff9..a3ccb9a 100644 --- a/src/customer/presentation/customer.dto.ts +++ b/src/customer/presentation/customer.dto.ts @@ -73,7 +73,7 @@ export class BaseCustomerDto extends AuthDto implements CustomerType { @Matches(/^(01[016789]{1})-[0-9]{3,4}-[0-9]{4}$/, { message: 'This is not Phone number ex) xxx-xxxx-xxxx', }) - protected _customerPhoneNumber?: string; + protected _customerPhoneNumber?: string; // TODO: UserDto의 phoneNumber override로 변경하기 @ApiProperty({ description: '고객 위치',