๐Ÿ“ฆ cityzenKIM / toy_project_board

๐Ÿ“„ Users.ts ยท 73 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { Posts } from './Posts';
import { Comments } from './Comments';
import { ApiProperty } from '@nestjs/swagger';

export enum UserRoleType {
  USER = 'ROLE_USER',
  ADMIN = 'ROLE_ADMIN',
  ANONYMOUS = 'ROLE_ANONYMOUS',
}
@Entity({ schema: 'shop', name: 'users' })
export class Users {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @ApiProperty({
    example: 'abc123@naver.com',
    required: true,
  })
  @IsEmail()
  @Column('varchar', { name: 'email', unique: true, length: 30 })
  email: string;

  @ApiProperty({
    example: '๋ฉ”์‹œ',
    required: true,
  })
  @IsString()
  @IsNotEmpty()
  @Column('varchar', { name: 'nickname', length: 30 })
  nickname: string;

  @ApiProperty({
    example: '12345',
    required: true,
  })
  @IsString()
  @IsNotEmpty()
  @Column('varchar', { name: 'password', length: 100, select: false })
  password: string;

  @Column({
    type: 'enum',
    enum: UserRoleType,
    default: UserRoleType.USER,
  })
  role: UserRoleType;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @DeleteDateColumn()
  deletedAt: Date | null;

  @OneToMany(() => Posts, (posts) => posts.user)
  Posts: Posts[];

  @OneToMany(() => Comments, (comment) => comment.user)
  comments: Comments[];
}