diff --git a/modules/ticket/back/models/ticket-service.js b/modules/ticket/back/models/ticket-service.js index cdb57650a..aa94c42e3 100644 --- a/modules/ticket/back/models/ticket-service.js +++ b/modules/ticket/back/models/ticket-service.js @@ -1,16 +1,13 @@ const UserError = require('vn-loopback/util/user-error'); -const LoopBackContext = require('loopback-context'); module.exports = Self => { Self.observe('before save', async ctx => { - const loopBackContext = LoopBackContext.getCurrentContext(); - const httpCtx = {req: loopBackContext.active}; const models = Self.app.models; let changes = ctx.currentInstance || ctx.instance; if (changes) { let ticketId = changes.ticketFk; - let isEditable = await models.Ticket.isEditable(httpCtx, ticketId); - if (!isEditable) + let isLocked = await models.Ticket.isLocked(ticketId); + if (isLocked) throw new UserError(`The current ticket can't be modified`); if (changes.ticketServiceTypeFk) { @@ -21,13 +18,11 @@ module.exports = Self => { }); Self.observe('before delete', async ctx => { - const loopBackContext = LoopBackContext.getCurrentContext(); - const httpCtx = {req: loopBackContext.active}; const models = Self.app.models; const service = await models.TicketService.findById(ctx.where.id); - const isEditable = await models.Ticket.isEditable(httpCtx, service.ticketFk); + const isLocked = await models.Ticket.isLocked(service.ticketFk); - if (!isEditable) + if (isLocked) throw new UserError(`The current ticket can't be modified`); }); }; diff --git a/package-lock.json b/package-lock.json index 68004c13c..1c02e021a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17073,9 +17073,9 @@ } }, "ssri": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", - "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz", + "integrity": "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==", "dev": true, "requires": { "figgy-pudding": "^3.5.1"