feat: Cachable and date session model.

This commit is contained in:
Ahmed Bouhuolia
2020-05-20 06:51:34 +02:00
parent 10f636d2bc
commit 90dc83c70a
18 changed files with 638 additions and 200 deletions

View File

@@ -0,0 +1,30 @@
import moment from 'moment';
export default (Model) => {
return class DateSession extends Model {
static get timestamps() {
return ['createdAt', 'updatedAt'];
}
$beforeUpdate(opt, context) {
const maybePromise = super.$beforeUpdate(opt, context);
return Promise.resolve(maybePromise).then(() => {
if (DateSession.timestamps[1]) {
this[DateSession.timestamps[1]] = moment().format('YYYY/MM/DD HH:mm:ss');
}
});
}
$beforeInsert(context) {
const maybePromise = super.$beforeInsert(context);
return Promise.resolve(maybePromise).then(() => {
if (DateSession.timestamps[0]) {
this[DateSession.timestamps[0]] = moment().format('YYYY/MM/DD HH:mm:ss');
}
});
}
}
}