Passed
Pull Request — develop (#7)
by Tito
02:05
created

Entity.getId   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
1
import { UniqueEntityId } from "Utilities/Ids/UniqueEntityId";
2
3
/**
4
 * Abstract Entity class
5
 */
6
export abstract class Entity<T> {
7
  /**
8
   * Id of the entity
9
   */
10
  protected readonly _id: UniqueEntityId;
11
12
  /**
13
   * Collection of properties
14
   */
15
  protected readonly props: T;
16
17
  /**
18
   * @param T props
19
   * @param IEntityDefinition definition Needed for each specific entity overriding this entity.  The child entity should not expose this parameter in its own constructor
20
   * @param UniqueEntityId id If not sent, it generates a UUID
21
   */
22
  constructor(props: T, id?: UniqueEntityId) {
23
    this.props = props;
24
    this._id = id ? id : new UniqueEntityId();
25
  }
26
27
  /**
28
   * Gets the id in its natural type
29
   *
30
   * @returns string|number
31
   */
32
  public getId(): string | number {
33
    return this._id.toValue();
34
  }
35
36
  /**
37
   * Gets the id stringified
38
   *
39
   * @returns string
40
   */
41
  public getIdString(): string {
42
    return this._id.toString();
43
  }
44
}
45