import { isNullOrUndefined, isObject } from '../services/general.mjs' import { ICreatedBy, IId, IUpdatedBy } from './interfaces.mjs' export interface IIdCreated extends IId, ICreatedBy {} export interface IIdCreatedUpdated extends IIdCreated, IUpdatedBy {} export class IdCreated implements IIdCreated { id?: Tid createdby = 'IdCreated' created = new Date() constructor( id: Tid | IIdCreated | undefined, createdby = 'IdCreated', created = new Date() ) { if (id && isObject(id)) { this.copyFromDatabase(id as IIdCreated) } else { if (!isNullOrUndefined(id)) { this.id = id as Tid } this.created = created this.createdby = createdby } } copyFromDatabase(dbtp: IIdCreated) { this.id = dbtp.id this.createdby = dbtp.createdby this.created = dbtp.created } } export class IdCreatedUpdated extends IdCreated implements IIdCreatedUpdated { updatedby = 'IdCreatedUpdated' updated = new Date() constructor( id: Tid | IIdCreatedUpdated | undefined, createdby = 'IdCreatedUpdated', created = new Date(), updatedby = 'IdCreatedUpdated', updated = new Date() ) { super(id, createdby, created) if (id && isObject(id)) { this.copyFromDatabase(id as IIdCreatedUpdated) } else { this.updated = updated this.updatedby = updatedby } } copyFromDatabase(dbtp: IIdCreatedUpdated) { super.copyFromDatabase(dbtp) this.updatedby = dbtp.updatedby this.updated = dbtp.updated } }