2019-07-29 11:12:36 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2024-03-20 19:54:24 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2019-07-29 11:12:36 +00:00
|
|
|
|
2019-05-21 07:03:57 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
require('../methods/ticket-weekly/filter')(Self);
|
2019-07-29 11:12:36 +00:00
|
|
|
|
|
|
|
Self.rewriteDbError(function(err) {
|
|
|
|
if (err.code === 'ER_DUP_ENTRY')
|
|
|
|
return new UserError(`This ticket is already on weekly tickets`);
|
|
|
|
return err;
|
|
|
|
});
|
2024-03-20 19:54:24 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2019-05-21 07:03:57 +00:00
|
|
|
};
|