mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Cachable and date session model.
This commit is contained in:
30
server/src/models/DateSession.js
Normal file
30
server/src/models/DateSession.js
Normal 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');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user