Passed
Push — master ( 8559eb...809b5e )
by Mathieu
01:54
created

Product.getWeight   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
2
3
@Entity()
4
export class Product {
5
  @PrimaryGeneratedColumn('uuid')
6
  private id: string;
7
8
  @Column({ type: 'varchar', nullable: false })
9
  private title: string;
10
11
  @Column({ type: 'varchar', nullable: true })
12
  private description: string;
13
14
  @Column({ type: 'integer', nullable: false, default: 0 })
15
  private unitPrice: number;
16
17
  @Column({ type: 'integer', nullable: false, default: 0 })
18
  private weight: number;
19
20
  constructor(
21
    title: string,
22
    description: string,
23
    unitPrice: number,
24
    weight: number
25
  ) {
26
    this.title = title;
27
    this.description = description;
28
    this.unitPrice = unitPrice;
29
    this.weight = weight;
30
  }
31
32
  public getId(): string {
33
    return this.id;
34
  }
35
36
  public getTitle(): string {
37
    return this.title;
38
  }
39
40
  public getDescription(): string {
41
    return this.description;
42
  }
43
44
  public getUnitPrice(): number {
45
    return this.unitPrice;
46
  }
47
48
  public getWeight(): number {
49
    return this.weight;
50
  }
51
52
  public getPriceFromCents(): number {
53
    return this.unitPrice / 100;
54
  }
55
56
  public update(
57
    title: string,
58
    description: string,
59
    unitPrice: number,
60
    weight: number
61
  ): void {
62
    this.title = title;
63
    this.description = description;
64
    this.unitPrice = unitPrice;
65
    this.weight = weight;
66
  }
67
}
68