Passed
Pull Request — master (#75)
by Mathieu
01:18
created

server/src/Domain/FairCalendar/Event.entity.ts   A

Complexity

Total Complexity 8
Complexity/F 1

Size

Lines of Code 102
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 87
mnd 0
bc 0
fnc 8
dl 0
loc 102
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A Event.getId 0 3 1
A Event.getDate 0 3 1
A Event.getType 0 3 1
A Event.getSummary 0 3 1
A Event.getTask 0 3 1
A Event.getUser 0 3 1
A Event.getProject 0 3 1
A Event.getTime 0 3 1
1
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from 'typeorm';
2
import {User} from '../User/User.entity';
3
import {Task} from '../Task/Task.entity';
4
import {Project} from '../Project/Project.entity';
5
6
export enum EventType {
7
  MISSION = 'mission',
8
  SUPPORT = 'support',
9
  DOJO = 'dojo',
10
  FORMATION_CONFERENCE = 'formationConference',
11
  HOLIDAY = 'holiday',
12
  WORK_FREE = 'workFree',
13
  MEDICAL_LEAVE = 'medicalLeave',
14
  OTHER = 'other'
15
}
16
17
@Entity()
18
export class Event {
19
  // Times spent are stored in base 100
20
  public static readonly MAXIMUM_TIMESPENT_PER_DAY: number = 100;
21
  public static readonly WORKED_TYPES: string[] = [
22
    EventType.MISSION,
23
    EventType.SUPPORT,
24
    EventType.DOJO,
25
    EventType.FORMATION_CONFERENCE
26
  ];
27
28
  @PrimaryGeneratedColumn('uuid')
29
  private id: string;
30
31
  @Column('enum', {enum: EventType, nullable: false})
32
  private type: EventType;
33
34
  @Column({type: 'integer', nullable: false})
35
  private time: number;
36
37
  @Column({type: 'date', nullable: false})
38
  private date: string;
39
40
  @Column({type: 'varchar', nullable: true})
41
  private summary: string;
42
43
  @ManyToOne(type => Project, {nullable: true})
44
  private project: Project;
45
46
  @ManyToOne(type => Task, {nullable: true})
47
  private task: Task;
48
49
  @ManyToOne(type => User, {nullable: false})
50
  private user: User;
51
52
  constructor(
53
    type: EventType,
54
    user: User,
55
    time: number,
56
    date: string,
57
    project?: Project,
58
    task?: Task,
59
    summary?: string
60
  ) {
61
    this.type = type;
62
    this.user = user;
63
    this.time = time;
64
    this.date = date;
65
    this.project = project;
66
    this.task = task;
67
    this.summary = summary;
68
  }
69
70
  public getId(): string {
71
    return this.id;
72
  }
73
74
  public getType(): string {
75
    return this.type;
76
  }
77
78
  public getTime(): number {
79
    return this.time;
80
  }
81
82
  public getDate(): string {
83
    return this.date;
84
  }
85
86
  public getSummary(): string | null {
87
    return this.summary;
88
  }
89
90
  public getProject(): Project | null {
91
    return this.project;
92
  }
93
94
  public getTask(): Task | null {
95
    return this.task;
96
  }
97
98
  public getUser(): User {
99
    return this.user;
100
  }
101
}
102