部分公共代码db和const放到shared目录
This commit is contained in:
24
shared/db/BaseModel.ts
Normal file
24
shared/db/BaseModel.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { prop, pre } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* BaseModel
|
||||
*/
|
||||
@pre<BaseModel>('save', function(next) {
|
||||
if (!this.createdAt || this.isNew) {
|
||||
this.createdAt = this.updatedAt = new Date();
|
||||
} else {
|
||||
this.updatedAt = new Date();
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
export default class BaseModel {
|
||||
|
||||
_id?: string
|
||||
|
||||
@prop()
|
||||
createdAt: Date
|
||||
|
||||
@prop()
|
||||
updatedAt: Date
|
||||
}
|
||||
Reference in New Issue
Block a user