feat: Introduce base model to implement created_at & updated_at logic

This commit is contained in:
Faruk AYDIN
2021-10-06 23:40:14 +02:00
committed by Ali BARIN
parent ae3d24e233
commit 2e524eabd3
2 changed files with 25 additions and 3 deletions

View File

@@ -0,0 +1,21 @@
import { Model, QueryContext, ModelOptions } from 'objection';
class Base extends Model {
created_at!: string;
updated_at!: string;
async $beforeInsert(queryContext: QueryContext) {
await super.$beforeInsert(queryContext);
this.created_at = new Date().toISOString();
this.updated_at = new Date().toISOString();
}
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext) {
await super.$beforeUpdate(opt, queryContext);
this.updated_at = new Date().toISOString();
}
}
export default Base;