Skip to content

Commit

Permalink
[BE/#276] entity에 class validator 추가 (#277)
Browse files Browse the repository at this point in the history
* fix: 카테고리 entity class validator 추가

* fix: 학습 기록 class-validator 추가
  • Loading branch information
victolee0 authored Nov 30, 2023
1 parent 57c3bae commit e5341a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BE/src/categories/categories.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { ApiProperty } from '@nestjs/swagger';
import { UsersModel } from 'src/users/entity/users.entity';
import { StudyLogs } from 'src/study-logs/study-logs.entity';
import { IsString, Length, Matches } from 'class-validator';

@Entity()
export class Categories {
Expand All @@ -24,6 +25,8 @@ export class Categories {
type: 'char',
length: 50,
})
@IsString()
@Length(1, 50)
name: string;

@ApiProperty({
Expand All @@ -35,6 +38,9 @@ export class Categories {
type: 'char',
length: 8,
})
@IsString()
@Length(1, 8)
@Matches(/^[0-9A-F]{1,8}$/i, {message: '올바른 색상 코드가 아닙니다.'})
color_code: string;

@ManyToOne(() => UsersModel, (user) => user.categories, {
Expand Down
8 changes: 8 additions & 0 deletions BE/src/study-logs/study-logs.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ import {
} from 'typeorm';
import { UsersModel } from 'src/users/entity/users.entity';
import { Categories } from 'src/categories/categories.entity';
import { IsNumber, IsString, Matches } from 'class-validator';

@Entity()
export class StudyLogs {
@PrimaryGeneratedColumn()
id: number;

@Column({ type: 'date' })
@IsString()
@Matches(/^\d{4}-\d{2}-\d{2}$/i, { message: '올바른 날짜 형식이 아닙니다.' })
date: Date;

@Column({ type: 'datetime' })
@IsString()
@Matches(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i, {message: '올바른 시간 형식이 아닙니다.'})
created_at: Date;

@Column({ type: 'enum', enum: ['start', 'finish'] })
@IsString()
@Matches(/^(start|finish)$/i, {message: '올바른 타입이 아닙니다.'})
type: 'start' | 'finish';

@Column({ type: 'int', default: 0 })
@IsNumber()
learning_time: number;

@ManyToOne(() => UsersModel, (user) => user.study_logs, {
Expand Down

0 comments on commit e5341a0

Please sign in to comment.