Passed
Push — master ( 9141d4...2cdb9e )
by Mathieu
02:07
created

Product.getPriceFromCents   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
  constructor(title: string, description: string, unitPrice: number) {
18
    this.title = title;
19
    this.description = description;
20
    this.unitPrice = unitPrice;
21
  }
22
23
  public getId(): string {
24
    return this.id;
25
  }
26
27
  public getTitle(): string {
28
    return this.title;
29
  }
30
31
  public getDescription(): string {
32
    return this.description;
33
  }
34
35
  public getUnitPrice(): number {
36
    return this.unitPrice;
37
  }
38
39
  public getPriceFromCents(): number {
40
    return this.unitPrice / 100;
41
  }
42
43
  public update(title: string, description: string, unitPrice: number): void {
44
    this.title = title;
45
    this.description = description;
46
    this.unitPrice = unitPrice;
47
  }
48
}
49