@nivinjoseph/n-domain
Version:
Domain Driven Design and Event Sourcing based framework for business layer implementation
61 lines (44 loc) • 1.39 kB
text/typescript
import { given } from "@nivinjoseph/n-defensive";
import { serialize } from "@nivinjoseph/n-util";
import { DomainObject } from "../../src/index.js";
("Test")
export class TestDomainObject extends DomainObject
{
private readonly _id: string;
private readonly _name: string;
public get id(): string { return this._id; }
public get name(): string { return this._name; }
public constructor(data: Data)
{
super(data);
const { id, name } = data;
given(id, "id").ensureHasValue().ensureIsString();
this._id = id;
given(name, "name").ensureHasValue().ensureIsString();
this._name = name;
}
// public static deserialize(data: Serialized): TestDomainObject
// {
// given(data, "data").ensureHasValue().ensureIsObject();
// return new TestDomainObject(data.id, data.name);
// }
// public serialize(): Serialized
// {
// return {
// id: this._id,
// name: this._name
// };
// }
public updateName(name: string): TestDomainObject
{
given(name, "name").ensureHasValue().ensureIsString();
return new TestDomainObject({id: this._id, name});
}
}
interface Data
{
id: string;
name: string;
}