fix: refs #7906 remake method #3109
|
@ -240,5 +240,6 @@
|
||||||
"There is already a tray with the same height": "There is already a tray with the same height",
|
"There is already a tray with the same height": "There is already a tray with the same height",
|
||||||
"The height must be greater than 50cm": "The height must be greater than 50cm",
|
"The height must be greater than 50cm": "The height must be greater than 50cm",
|
||||||
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm",
|
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm",
|
||||||
"The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line"
|
"The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line",
|
||||||
|
"There are tickets for this area, delete them first": "There are tickets for this area, delete them first"
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,5 +382,6 @@
|
||||||
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha",
|
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha",
|
||||||
"No valid travel thermograph found": "No se encontró un termógrafo válido",
|
"No valid travel thermograph found": "No se encontró un termógrafo válido",
|
||||||
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea",
|
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea",
|
||||||
"type cannot be blank": "Se debe rellenar el tipo"
|
"type cannot be blank": "Se debe rellenar el tipo",
|
||||||
|
"There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero"
|
||||||
}
|
}
|
|
@ -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',
|
||||||
|
@ -49,26 +50,12 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
carlossa marked this conversation as resolved
|
|||||||
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 worker = await models.Worker.findOne({
|
|
||||||
where: {id: userId}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions);
|
if (ticketList.length > 0)
|
||||||
|
throw new UserError('There are tickets for this area, delete them first');
|
||||||
|
|
||||||
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);
|
await models.Zone.destroyById(id, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -8,9 +8,9 @@ describe('zone deletezone()', () => {
|
||||||
__: value => value
|
__: value => value
|
||||||
};
|
};
|
||||||
alexm
commented
Fica un test q prove el nou error "here are tickets for this area, delete them first" Fica un test q prove el nou error "here are tickets for this area, delete them first"
|
|||||||
const ctx = {req: activeCtx};
|
const ctx = {req: activeCtx};
|
||||||
const zoneId = 9;
|
const zoneId = 4;
|
||||||
|
const zoneId2 = 3;
|
||||||
let ticketIDs;
|
let ticketIDs;
|
||||||
let originalTicketStates;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
@ -35,18 +35,8 @@ describe('zone deletezone()', () => {
|
||||||
await models.Zone.deleteZone(ctx, zoneId, options);
|
await models.Zone.deleteZone(ctx, zoneId, options);
|
||||||
|
|
||||||
const updatedZone = await models.Zone.findById(zoneId, null, options);
|
const updatedZone = await models.Zone.findById(zoneId, null, options);
|
||||||
const anUpdatedTicket = await models.Ticket.findById(ticketIDs[0], null, options);
|
|
||||||
|
|
||||||
const updatedTicketStates = await models.TicketState.find({
|
|
||||||
where: {
|
|
||||||
ticketFk: {inq: ticketIDs},
|
|
||||||
code: 'FIXING'
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(updatedZone).toBeNull();
|
expect(updatedZone).toBeNull();
|
||||||
expect(anUpdatedTicket.zoneFk).toBeNull();
|
|
||||||
expect(updatedTicketStates.length).toBeGreaterThan(originalTicketStates.length);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -54,4 +44,20 @@ describe('zone deletezone()', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not delete the zone if it has tickets', async() => {
|
||||||
|
const tx = await models.Zone.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.Zone.deleteZone(ctx, zoneId2, options);
|
||||||
|
await tx.rollback();
|
||||||
carlossa marked this conversation as resolved
alexm
commented
Fijat be Fijat be
|
|||||||
|
} catch (e) {
|
||||||
|
error = e.message;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toEqual('There are tickets for this area, delete them first');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Quitar