WIP: fix: refs #7906 remake method #3079

Draft
carlossa wants to merge 1 commits from 7906-remakeMethod into dev
1 changed files with 18 additions and 15 deletions
Showing only changes of commit 520346d4a5 - Show all commits

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('deleteZone', {
description: 'Delete a zone',
@ -52,23 +53,25 @@ module.exports = Self => {
const promises = [];
const ticketList = await models.Ticket.find(filter, myOptions);
const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions);
const worker = await models.Worker.findOne({
where: {id: userId}
}, myOptions);
// const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions);
// const worker = await models.Worker.findOne({
// where: {id: userId}
// }, myOptions);
if (ticketList.length > 0)
throw new UserError('You cannot delete a zone that is being used');
await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions);
// await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions);
for (ticket of ticketList) {
if (ticket.ticketState().alertLevel == 0) {
promises.push(models.Ticket.state(ctx, {
ticketFk: ticket.id,
stateFk: fixingState.id,
userFk: worker.id
}, myOptions));
}
}
await Promise.all(promises);
// for (ticket of ticketList) {
// if (ticket.ticketState().alertLevel == 0) {
// promises.push(models.Ticket.state(ctx, {
// ticketFk: ticket.id,
// stateFk: fixingState.id,
// userFk: worker.id
// }, myOptions));
// }
// }
// await Promise.all(promises);
await models.Zone.destroyById(id, myOptions);
if (tx) await tx.commit();