Passed
Pull Request — master (#458)
by
unknown
02:54
created

es   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
2
import { User } from '../User/User.entity';
3
4
export enum Status {
5
  PENDING = 'pending',
6
  ACCEPTED = 'accepted',
7
  REFUSED = 'refused'
8
}
9
10
export enum Type {
11
  PAID = 'paid',
12
  UNPAID = 'unpaid',
13
  SPECIAL = 'special',
14
  MEDICAL = 'medical',
15
  ILLIMITED = 'illimited',
16
  POSTPONED_WORKED_FREE_DAY = 'postponedWorkedFreeDay',
17
  RELOCATION = 'relocation'
18
}
19
20
export function getSelectableLeaveRequestTypes() {
21
  const types = Object.values(Type);
22
23
  return types.filter(t => t !== Type.MEDICAL);
24
}
25
26
export interface ILeaveRequestModeration {
27
  getStatus(): string;
28
  getUserId(): string;
29
}
30
31
export interface ILeaveRequestOwnership {
32
  getUserId(): string;
33
}
34
35
export interface ILeaveRequestCancellation {
36
  getUserId(): string;
37
  getStartDate(): string;
38
}
39
40
@Entity()
41
export class LeaveRequest implements ILeaveRequestModeration {
42
  @PrimaryGeneratedColumn('uuid')
43
  private id: string;
44
45
  @Column('enum', { enum: Status, nullable: false })
46
  private status: Status;
47
48
  @Column('enum', { enum: Type, nullable: false })
49
  private type: Type;
50
51
  @Column({ type: 'timestamp', nullable: false })
52
  private startDate: string;
53
54
  @Column({ type: 'boolean', nullable: false, default: true })
55
  private startsAllDay: boolean;
56
57
  @Column({ type: 'timestamp', nullable: false })
58
  private endDate: string;
59
60
  @Column({ type: 'boolean', nullable: false, default: true })
61
  private endsAllDay: boolean;
62
63
  @Column({ type: 'varchar', nullable: true })
64
  private comment: string;
65
66
  @Column({ type: 'varchar', nullable: true })
67
  private moderationComment: string;
68
69
  @Column({ type: 'timestamp', nullable: true })
70
  private moderateAt: string;
71
72
  @ManyToOne(type => User, { nullable: true, onDelete: 'SET NULL' })
73
  private moderator: User;
74
75
  @ManyToOne(type => User, { nullable: false, onDelete: 'CASCADE' })
76
  private user: User;
77
78
  constructor(
79
    user: User,
80
    type: Type,
81
    startDate: string,
82
    startsAllDay: boolean,
83
    endDate: string,
84
    endsAllDay: boolean,
85
    comment?: string
86
  ) {
87
    this.status = Status.PENDING;
88
    this.user = user;
89
    this.type = type;
90
    this.startDate = startDate;
91
    this.startsAllDay = startsAllDay;
92
    this.endDate = endDate;
93
    this.endsAllDay = endsAllDay;
94
    this.comment = comment;
95
  }
96
97
  public getId(): string {
98
    return this.id;
99
  }
100
101
  public getUser(): User {
102
    return this.user;
103
  }
104
105
  public getUserId(): string {
106
    return this.user.getId();
107
  }
108
109
  public getStatus(): Status {
110
    return this.status;
111
  }
112
113
  public getType(): Type {
114
    return this.type;
115
  }
116
117
  public getStartDate(): string {
118
    return this.startDate;
119
  }
120
121
  public isStartsAllDay(): boolean {
122
    return this.startsAllDay;
123
  }
124
125
  public getEndDate(): string {
126
    return this.endDate;
127
  }
128
129
  public isEndsAllDay(): boolean {
130
    return this.endsAllDay;
131
  }
132
133
  public getComment(): string {
134
    return this.comment;
135
  }
136
137
  public getModerator(): User {
138
    return this.moderator;
139
  }
140
141
  public getModerateAt(): string {
142
    return this.moderateAt;
143
  }
144
145
  public getModerationComment(): string {
146
    return this.moderationComment;
147
  }
148
149
  public refuse(
150
    moderator: User,
151
    date: string,
152
    moderationComment?: string
153
  ): void {
154
    this.status = Status.REFUSED;
155
    this.moderator = moderator;
156
    this.moderateAt = date;
157
    this.moderationComment = moderationComment;
158
  }
159
160
  public accept(
161
    moderator: User,
162
    date: string,
163
    moderationComment?: string
164
  ): void {
165
    this.status = Status.ACCEPTED;
166
    this.moderator = moderator;
167
    this.moderateAt = date;
168
    this.moderationComment = moderationComment;
169
  }
170
171
  public update(
172
    type: Type,
173
    startDate: string,
174
    startsAllDay: boolean,
175
    endDate: string,
176
    endsAllDay: boolean,
177
    comment?: string
178
  ): void {
179
    this.type = type;
180
    this.startDate = startDate;
181
    this.startsAllDay = startsAllDay;
182
    this.endDate = endDate;
183
    this.endsAllDay = endsAllDay;
184
    this.comment = comment;
185
  }
186
}
187