Building a REST API with NestJS and Prisma: Authentication
https://www.prisma.io/blog/nestjs-prisma-rest-api-7D056s1BmOL0
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
867 B
40 lines
867 B
import { Article } from '@prisma/client'
|
|
import { ApiProperty } from '@nestjs/swagger'
|
|
import { UserEntity } from 'src/users/entities/user.entity'
|
|
|
|
export class ArticleEntity implements Article {
|
|
@ApiProperty()
|
|
id: number
|
|
|
|
@ApiProperty()
|
|
title: string
|
|
|
|
@ApiProperty({ required: false, nullable: true })
|
|
description: string | null
|
|
|
|
@ApiProperty()
|
|
body: string
|
|
|
|
@ApiProperty()
|
|
published: boolean
|
|
|
|
@ApiProperty()
|
|
createdAt: Date
|
|
|
|
@ApiProperty()
|
|
updatedAt: Date
|
|
|
|
@ApiProperty({ required: false, nullable: true })
|
|
authorId: number | null;
|
|
|
|
@ApiProperty({ required: false, type: UserEntity })
|
|
author?: UserEntity
|
|
|
|
constructor({ author, ...data }: Partial<ArticleEntity>) {
|
|
Object.assign(this, data)
|
|
|
|
if (author) {
|
|
this.author = new UserEntity(author)
|
|
}
|
|
}
|
|
}
|