Skip to content

Commit 839f514

Browse files
committed
feat: add user provider
1 parent 9eb0bd5 commit 839f514

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const PROVIDER = {
2+
GOOGLE: 'google',
3+
KAKAO: 'kakao',
4+
APPLE: 'apple',
5+
} as const;
6+
7+
export type PROVIDER = (typeof PROVIDER)[keyof typeof PROVIDER];

src/users/entities/user.entity.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Category } from '../../categories/category.entity';
1515
import { Collection } from '../../collections/entities/collection.entity';
1616
import { CoreEntity } from '../../common/entities/core.entity';
1717
import { PaidPlan } from './paid-plan.entity';
18+
import { PROVIDER } from '../constant/provider.constant';
1819

1920
export enum UserRole {
2021
Client = 'Client',
@@ -26,12 +27,12 @@ export class User extends CoreEntity {
2627
@ApiProperty({ example: 'tester', description: 'User Name' })
2728
@Column()
2829
@IsString()
29-
name!: string;
30+
name: string;
3031

3132
@ApiProperty({ example: '[email protected]', description: 'User Email' })
3233
@Column({ unique: true })
3334
@IsEmail()
34-
email!: string;
35+
email: string;
3536

3637
@ApiProperty({ example: 'https://ex.com', description: 'User Profile Image' })
3738
@Column({ nullable: true })
@@ -44,7 +45,7 @@ export class User extends CoreEntity {
4445
@Matches(/^(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/, {
4546
message: 'Password must be at least 8 characters long, contain 1 number',
4647
})
47-
password!: string;
48+
password: string;
4849

4950
@ApiProperty({
5051
example: 'Client',
@@ -53,12 +54,15 @@ export class User extends CoreEntity {
5354
})
5455
@Column({ type: 'enum', enum: UserRole, default: UserRole.Client })
5556
@IsEnum(UserRole)
56-
role!: UserRole;
57+
role: UserRole;
58+
59+
@Column({ type: 'enum', enum: PROVIDER })
60+
provider: PROVIDER;
5761

5862
@ApiProperty({ description: 'User Verified' })
5963
@Column({ default: false })
6064
@IsBoolean()
61-
verified!: boolean;
65+
verified: boolean;
6266

6367
@ApiProperty({
6468
description: 'User Content List',
@@ -121,4 +125,27 @@ export class User extends CoreEntity {
121125
throw new InternalServerErrorException();
122126
}
123127
}
128+
129+
static of({
130+
email,
131+
name,
132+
profileImage,
133+
password,
134+
provider,
135+
}: {
136+
email: string;
137+
name: string;
138+
profileImage?: string;
139+
password: string;
140+
provider: PROVIDER;
141+
}): User {
142+
const user = new User();
143+
user.email = email;
144+
user.name = name;
145+
user.profileImage = profileImage;
146+
user.password = password;
147+
user.provider = provider;
148+
149+
return user;
150+
}
124151
}

0 commit comments

Comments
 (0)