feat: Convert model files to JS

This commit is contained in:
Faruk AYDIN
2024-01-04 19:27:13 +01:00
parent b693c12500
commit 8819ddefa7
20 changed files with 140 additions and 363 deletions

View File

@@ -0,0 +1,40 @@
import { AjvValidator, Model, snakeCaseMappers } from 'objection';
import addFormats from 'ajv-formats';
import ExtendedQueryBuilder from './query-builder';
class Base extends Model {
static QueryBuilder = ExtendedQueryBuilder;
static get columnNameMappers() {
return snakeCaseMappers();
}
static createValidator() {
return new AjvValidator({
onCreateAjv: (ajv) => {
addFormats.default(ajv);
},
options: {
allErrors: true,
validateSchema: true,
ownProperties: true,
},
});
}
async $beforeInsert(queryContext) {
await super.$beforeInsert(queryContext);
this.createdAt = new Date().toISOString();
this.updatedAt = new Date().toISOString();
}
async $beforeUpdate(opts, queryContext) {
this.updatedAt = new Date().toISOString();
await super.$beforeUpdate(opts, queryContext);
}
}
export default Base;