import { Entity , Column , PrimaryGeneratedColumn , ManyToOne } from 'typeorm' ; import { User } from '../User/User.entity' ; export enum Status { PENDING = 'pending' , ACCEPTED = 'accepted' , REFUSED = 'refused' } export enum Type { PAID = 'paid' , UNPAID = 'unpaid' , SPECIAL = 'special' , MEDICAL = 'medical' } @ Entity ( ) export class LeaveRequest { @ PrimaryGeneratedColumn ( 'uuid' ) private id : string ; @ Column ( 'enum' , { enum : Status , nullable : false } ) private status : Status ; @ Column ( 'enum' , { enum : Type , nullable : false } ) private type : Type ; @ Column ( { type : 'timestamp' , nullable : false } ) private startDate : string ; @ Column ( { type : 'boolean' , nullable : false , default : true } ) private startsAllDay : boolean ; @ Column ( { type : 'timestamp' , nullable : false } ) private endDate : string ; @ Column ( { type : 'boolean' , nullable : false , default : true } ) private endsAllDay : boolean ; @ Column ( { type : 'varchar' , nullable : true } ) private comment : string ; @ Column ( { type : 'varchar' , nullable : true } ) private moderationComment : string ; @ Column ( { type : 'timestamp' , nullable : true } ) private moderateAt : string ; @ ManyToOne ( type => User , { nullable : true , onDelete : 'SET NULL' } ) private moderator : User ; @ ManyToOne ( type => User , { nullable : false , onDelete : 'CASCADE' } ) private user : User ; constructor ( user , type , startDate , startsAllDay , endDate , endsAllDay , comment ? ) { this . status = Status . PENDING ; this . user = user ; this . type = type ; this . startDate = startDate ; this . startsAllDay = startsAllDay ; this . endDate = endDate ; this . endsAllDay = endsAllDay ; this . comment = comment ; } public getId ( ) { return this . id ; } public getUser ( ) { return this . user ; } public getStatus ( ) { return this . status ; } public getType ( ) { return this . type ; } public getStartDate ( ) { return this . startDate ; } public isStartsAllDay ( ) { return this . startsAllDay ; } public getEndDate ( ) { return this . endDate ; } public isEndsAllDay ( ) { return this . endsAllDay ; } public getComment ( ) { return this . comment ; } public getModerator ( ) { return this . moderator ; } public getModerateAt ( ) { return this . moderateAt ; } public getModerationComment ( ) { return this . moderationComment ; } public refuse ( moderator , date , moderationComment ? ) { this . status = Status . REFUSED ; this . moderator = moderator ; this . moderateAt = date ; this . moderationComment = moderationComment ; } public accept ( moderator , date , moderationComment ? ) { this . status = Status . ACCEPTED ; this . moderator = moderator ; this . moderateAt = date ; this . moderationComment = moderationComment ; } public update ( type , startDate , startsAllDay , endDate , endsAllDay , comment ? ) { this . type = type ; this . startDate = startDate ; this . startsAllDay = startsAllDay ; this . endDate = endDate ; this . endsAllDay = endsAllDay ; this . comment = comment ; } }