UNPKG

dino-core

Version:

A dependency injection framework for NodeJS applications

49 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Entity = void 0; const object_helper_1 = require("../../helper/object.helper"); const Archetype_1 = require("./Archetype"); /** * Define an entity in the common sense of DDD (Domain-Driven Design). * The properties passed to the constructor will be set with the provided value * and will only be accessible for reading and writing. */ class Entity { constructor(id, props) { this.id = id; for (const key in props) { Object.defineProperty(this, key, { value: props[key], writable: true, enumerable: true, configurable: true }); } } getId() { return this.id; } /** * Compare two entities for equality * > if other object is not defined return false * > if this object and other object are not of the same type then return false * > if the id of this object properties is not same as the id of other object then return false * > otherwise return true * @param other the other archetype to compare * @returns true if the two entities are same, false otherwise */ equals(other) { if (!object_helper_1.ObjectHelper.isDefined(other)) { return false; } if (!object_helper_1.ObjectHelper.instanceOf(other, Entity)) { return false; } return this.id.equals(other.id); } static create(id, props) { return (0, Archetype_1.wrapWithPropertyGetterAndSetterHandler)(new this(id, props)); } } exports.Entity = Entity; //# sourceMappingURL=Entity.js.map