Skip to content

Commit

Permalink
refactor: delete type assertion in content entity
Browse files Browse the repository at this point in the history
  • Loading branch information
stae1102 committed Feb 11, 2024
1 parent 92b08c0 commit 2aa1652
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/contents/entities/content.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'class-validator';
import { CoreEntity } from '../../common/entities/core.entity';
import { User } from '../../users/entities/user.entity';
import { Column, Entity, ManyToOne, RelationId } from 'typeorm';
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { Category } from '../../categories/category.entity';
import { Transform } from 'class-transformer';
Expand All @@ -18,7 +18,7 @@ export class Content extends CoreEntity {
@Column()
@IsString({ message: 'String URL must be required.' })
@IsUrl()
link!: string;
link: string;

@ApiProperty({ description: 'Article Title', required: false })
@Column({ nullable: true })
Expand Down Expand Up @@ -63,18 +63,20 @@ export class Content extends CoreEntity {
favorite?: boolean;

@ApiProperty({ description: 'Article Category', required: false })
@ManyToOne((type) => Category, (category) => category.contents, {
@ManyToOne(() => Category, (category) => category.contents, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'categoryId', referencedColumnName: 'id' })
category?: Category;

@ManyToOne((type) => User, (user) => user.contents, {
@ManyToOne(() => User, (user) => user.contents, {
onDelete: 'CASCADE',
})
user!: User;
@JoinColumn({ name: 'userId', referencedColumnName: 'id' })
user: User;

@ApiProperty({ description: 'Owner ID' })
@RelationId((content: Content) => content.user)
userId!: number;
userId: number;
}

0 comments on commit 2aa1652

Please sign in to comment.