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

20 lines
707 B
JavaScript

const UserError = require('vn-loopback/util/user-error');
const LoopBackContext = require('loopback-context');
module.exports = Self => {
require('../methods/ticket-weekly/filter')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`This ticket is already on weekly tickets`);
return err;
});
Self.observe('after save', async ctx => {
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http;
await Self.app.models.Ticket.setDeleted(httpRequest, ctx.instance.ticketFk, ctx.options);
});
};