import { Entity , Column , PrimaryGeneratedColumn , ManyToOne } from 'typeorm' ; import { Customer } from '../Customer/Customer.entity' ; export enum InvoiceUnits { DAY = 'day' , HOUR = 'hour' } @ Entity ( ) export class Project { @ PrimaryGeneratedColumn ( 'uuid' ) private id : string ; @ Column ( { type : 'varchar' , nullable : false } ) private name : string ; @ Column ( { type : 'integer' , nullable : false , default : 420 , comment : 'Stored in minutes' } ) private dayDuration : number ; @ Column ( 'enum' , { enum : InvoiceUnits , nullable : false } ) private invoiceUnit : InvoiceUnits ; @ Column ( { type : 'timestamp' , default : ( ) => 'CURRENT_TIMESTAMP' } ) private createdAt : Date ; @ ManyToOne ( type => Customer , { nullable : false , onDelete : 'CASCADE' } ) private customer : Customer ; constructor ( name , dayDuration , invoiceUnit , customer ) { this . name = name ; this . dayDuration = dayDuration ; this . invoiceUnit = invoiceUnit ; this . customer = customer ; } public getId ( ) { return this . id ; } public getName ( ) { return this . name ; } public getDayDuration ( ) { return this . dayDuration ; } public getInvoiceUnit ( ) { return this . invoiceUnit ; } public getCreatedAt ( ) { return this . createdAt ; } public getCustomer ( ) { return this . customer ; } public getFullName ( ) { return `[${ this . customer . getName ( ) }] ${ this . getName ( ) }` ; } public update ( customer , dayDuration , invoiceUnit , name ) { this . customer = customer ; this . dayDuration = dayDuration ; this . invoiceUnit = invoiceUnit ; this . name = name ; } }