fix: refs #7906 remake method
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
ed4dff1914
commit
520346d4a5
|
@ -1,3 +1,4 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('deleteZone', {
|
Self.remoteMethodCtx('deleteZone', {
|
||||||
description: 'Delete a zone',
|
description: 'Delete a zone',
|
||||||
|
@ -52,23 +53,25 @@ module.exports = Self => {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
const ticketList = await models.Ticket.find(filter, myOptions);
|
const ticketList = await models.Ticket.find(filter, myOptions);
|
||||||
const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions);
|
// const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions);
|
||||||
const worker = await models.Worker.findOne({
|
// const worker = await models.Worker.findOne({
|
||||||
where: {id: userId}
|
// where: {id: userId}
|
||||||
}, myOptions);
|
// }, 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) {
|
// for (ticket of ticketList) {
|
||||||
if (ticket.ticketState().alertLevel == 0) {
|
// if (ticket.ticketState().alertLevel == 0) {
|
||||||
promises.push(models.Ticket.state(ctx, {
|
// promises.push(models.Ticket.state(ctx, {
|
||||||
ticketFk: ticket.id,
|
// ticketFk: ticket.id,
|
||||||
stateFk: fixingState.id,
|
// stateFk: fixingState.id,
|
||||||
userFk: worker.id
|
// userFk: worker.id
|
||||||
}, myOptions));
|
// }, myOptions));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
await Promise.all(promises);
|
// await Promise.all(promises);
|
||||||
await models.Zone.destroyById(id, myOptions);
|
await models.Zone.destroyById(id, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
Loading…
Reference in New Issue