1
|
|
|
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; |
2
|
|
|
import { Customer } from '../Customer/Customer.entity'; |
3
|
|
|
|
4
|
|
|
export enum InvoiceUnits { |
5
|
|
|
DAY = 'day', |
6
|
|
|
HOUR = 'hour' |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
@Entity() |
10
|
|
|
export class Project { |
11
|
|
|
@PrimaryGeneratedColumn('uuid') |
12
|
|
|
private id: string; |
13
|
|
|
|
14
|
|
|
@Column({ type: 'varchar', nullable: false }) |
15
|
|
|
private name: string; |
16
|
|
|
|
17
|
|
|
@Column('enum', { enum: InvoiceUnits, nullable: false }) |
18
|
|
|
private invoiceUnit: InvoiceUnits; |
19
|
|
|
|
20
|
|
|
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) |
21
|
|
|
private createdAt: Date; |
22
|
|
|
|
23
|
|
|
@Column({ type: 'boolean', nullable: false, default: false }) |
24
|
|
|
private active: boolean; |
25
|
|
|
|
26
|
|
|
@ManyToOne(type => Customer, { nullable: false, onDelete: 'CASCADE' }) |
27
|
|
|
private customer: Customer; |
28
|
|
|
|
29
|
|
|
constructor( |
30
|
|
|
name: string, |
31
|
|
|
invoiceUnit: InvoiceUnits, |
32
|
|
|
active: boolean, |
33
|
|
|
customer: Customer |
34
|
|
|
) { |
35
|
|
|
this.name = name; |
36
|
|
|
this.invoiceUnit = invoiceUnit; |
37
|
|
|
this.customer = customer; |
38
|
|
|
this.active = active; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public getId(): string { |
42
|
|
|
return this.id; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public getName(): string { |
46
|
|
|
return this.name; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public getInvoiceUnit(): InvoiceUnits { |
50
|
|
|
return this.invoiceUnit; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public getCreatedAt(): Date { |
54
|
|
|
return this.createdAt; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public getCustomer(): Customer { |
58
|
|
|
return this.customer; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public getFullName(): string { |
62
|
|
|
return `[${this.customer.getName()}] ${this.getName()}`; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public isActive(): boolean { |
66
|
|
|
return this.active; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public update( |
70
|
|
|
customer: Customer, |
71
|
|
|
invoiceUnit: InvoiceUnits, |
72
|
|
|
name: string, |
73
|
|
|
active: boolean |
74
|
|
|
): void { |
75
|
|
|
this.customer = customer; |
76
|
|
|
this.invoiceUnit = invoiceUnit; |
77
|
|
|
this.name = name; |
78
|
|
|
this.active = active; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|