salix/services/client/common/models/receipt.js

14 lines
426 B
JavaScript

module.exports = function(Self) {
require('../methods/receipt/filter')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
let token = ctx.options.accessToken;
let userId = token && token.userId;
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
ctx.instance.workerFk = worker.id;
}
});
};