salix/modules/ticket/back/models/ticket-request.js

18 lines
643 B
JavaScript

const LoopBackContext = require('loopback-context');
module.exports = function(Self) {
require('../methods/ticket-request/filter')(Self);
require('../methods/ticket-request/deny')(Self);
require('../methods/ticket-request/confirm')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext();
let filter = {where: {userFk: loopBackContext.active.accessToken.userId}};
let worker = await Self.app.models.Worker.findOne(filter);
ctx.instance.requesterFk = worker.id;
}
});
};