fix: refs #8222 fix prDeleteZone #3269

Merged
carlossa merged 3 commits from 8222-refactorDeleteZone2 into master 2024-12-03 07:24:08 +00:00
4 changed files with 13 additions and 11 deletions

View File

@ -245,6 +245,6 @@
"Invalid or expired verification code": "Invalid or expired verification code",
"Payment method is required": "Payment method is required",
"The raid information is not correct": "The raid information is not correct",
"Sales already moved": "Sales already moved"
"Sales already moved": "Sales already moved",
"There are tickets to be invoiced": "There are tickets to be invoiced for this zone, please delete them first"
}

View File

@ -388,5 +388,6 @@
"ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}",
"The web user's email already exists": "El correo del usuario web ya existe",
"Sales already moved": "Ya han sido transferidas",
"The raid information is not correct": "La información de la redada no es correcta"
"The raid information is not correct": "La información de la redada no es correcta",
"There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero"
}

View File

@ -51,9 +51,9 @@ module.exports = Self => {
};
const ticketList = await models.Ticket.find(filter, myOptions);
if (ticketList.length > 0)
throw new UserError('There are tickets for this area, delete them first');
const hasRefFk = ticketList.some(ticket => ticket.refFk);
if (hasRefFk)
throw new UserError('There are tickets to be invoiced');
await models.Zone.destroyById(id, myOptions);

View File

@ -8,14 +8,14 @@ describe('zone deletezone()', () => {
__: value => value
};
const ctx = {req: activeCtx};
const zoneId = 4;
const zoneId2 = 3;
let ticketIDs;
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const zoneId = 4;
const originalTickets = await models.Ticket.find({
where: {
zoneFk: zoneId
@ -29,7 +29,7 @@ describe('zone deletezone()', () => {
it('should delete a zone and update their tickets', async() => {
const tx = await models.Zone.beginTransaction({});
const zoneId = 4;
try {
const options = {transaction: tx};
await models.Zone.deleteZone(ctx, zoneId, options);
@ -47,17 +47,18 @@ describe('zone deletezone()', () => {
it('should not delete the zone if it has tickets', async() => {
const tx = await models.Zone.beginTransaction({});
const zoneId = 1;
let error;
try {
const options = {transaction: tx};
await models.Zone.deleteZone(ctx, zoneId2, options);
await models.Zone.deleteZone(ctx, zoneId, options);
await tx.rollback();
} catch (e) {
error = e.message;
await tx.rollback();
}
expect(error).toEqual('There are tickets for this area, delete them first');
expect(error).toEqual('There are tickets to be invoiced');
});
});