boilerplate-nestjs-api-crud/src/mysqlcompany/contract/entities/contract.entity.ts

53 lines
1.0 KiB
TypeScript

import { ApiProperty } from '@nestjs/swagger';
import { Staff } from 'src/mysqlcompany/staffs/entities/staff.entity';
import {
Column,
Entity,
JoinColumn,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
@Entity('contracts')
export class Contract {
@ApiProperty({
type: Number,
name: '_id',
description: 'id of contract, auto-incremented',
})
// https://github.com/ppetzold/nestjs-paginate/issues/518
// when use 'id', will cause duplicated column issue
@PrimaryGeneratedColumn('increment', { name: '_id' })
id: number;
@ApiProperty({
type: String,
description: 'Contract title',
})
@Column({
type: 'varchar',
length: 255,
})
title: string;
@ApiProperty({
type: String,
name: 'details',
description: 'Contract details',
required: false,
})
@Column({
type: 'text',
nullable: true,
})
details: string;
@ApiProperty({
name: 'staff',
description: 'The staff of this contract',
type: () => Staff,
})
@OneToOne(() => Staff)
staff: Staff;
}