28 lines
521 B
TypeScript
28 lines
521 B
TypeScript
import { prop, pre, modelOptions } from '@typegoose/typegoose';
|
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
|
|
/**
|
|
* BaseModel
|
|
*/
|
|
@pre<BaseModel>('save', function(next) {
|
|
if (!this.createdAt || this.isNew) {
|
|
this.createdAt = this.updatedAt = new Date();
|
|
} else {
|
|
this.updatedAt = new Date();
|
|
}
|
|
next();
|
|
})
|
|
|
|
|
|
@modelOptions({schemaOptions: {id: false}})
|
|
export default class BaseModel extends TimeStamps {
|
|
|
|
_id?: string
|
|
|
|
@prop()
|
|
createdAt: Date
|
|
|
|
@prop()
|
|
updatedAt: Date
|
|
}
|