35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { Moment } from 'moment';
|
|
|
|
import { Deserializable } from './deserializable.model';
|
|
import { Serializable } from './serializable.model';
|
|
import * as moment from 'moment';
|
|
import { User } from './user.model';
|
|
|
|
export class Base implements Deserializable, Serializable {
|
|
id?: string;
|
|
createdAt?: Moment;
|
|
modifiedAt?: Moment;
|
|
createdById?: string;
|
|
modifiedById?: string;
|
|
createdBy?: User;
|
|
modifiedBy?: User;
|
|
|
|
constructor(data: Partial<Base> = {}) {
|
|
Object.assign(this, data);
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
deserialize(input: any): this {
|
|
if (input.createdAt) { input.createdAt = moment(input.createdAt).utc(true); }
|
|
if (input.modifiedAt) { input.modifiedAt = moment(input.modifiedAt).utc(true); }
|
|
if (input.createdBy) { input.createdBy = new User(input.createdBy); }
|
|
if (input.modifiedBy) { input.modifiedBy = new User(input.modifiedBy); }
|
|
Object.assign(this, input);
|
|
return this;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
serialize() : any {
|
|
return Object.assign({}, this);
|
|
}
|
|
} |