fix: refs #8222 fix deleteZone #3239
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE vn.ticket DROP FOREIGN KEY tickets_zone_fk;
|
||||||
|
ALTER TABLE vn.ticket ADD CONSTRAINT tickets_zone_fk FOREIGN KEY (zoneFk) REFERENCES vn.`zone`(id) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@ -246,5 +246,7 @@
|
||||||
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
|
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
|
||||||
"The raid information is not correct": "The raid information is not correct",
|
"The raid information is not correct": "The raid information is not correct",
|
||||||
"Payment method is required": "Payment method is required",
|
"Payment method is required": "Payment method is required",
|
||||||
"Sales already moved": "Sales already moved"
|
"Sales already moved": "Sales already moved",
|
||||||
|
"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 to be invoiced": "There are tickets to be invoiced for this zone, please delete them first"
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,6 +389,6 @@
|
||||||
"ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}",
|
"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",
|
"The web user's email already exists": "El correo del usuario web ya existe",
|
||||||
"Sales already moved": "Ya han sido transferidas",
|
"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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const ticketList = await models.Ticket.find(filter, myOptions);
|
const ticketList = await models.Ticket.find(filter, myOptions);
|
||||||
|
const hasRefFk = ticketList.some(ticket => ticket.refFk);
|
||||||
if (ticketList.length > 0)
|
if (hasRefFk)
|
||||||
throw new UserError('There are tickets for this area, delete them first');
|
throw new UserError('There are tickets to be invoiced');
|
||||||
|
|
||||||
await models.Zone.destroyById(id, myOptions);
|
await models.Zone.destroyById(id, myOptions);
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ describe('zone deletezone()', () => {
|
||||||
__: value => value
|
__: value => value
|
||||||
};
|
};
|
||||||
const ctx = {req: activeCtx};
|
const ctx = {req: activeCtx};
|
||||||
const zoneId = 4;
|
|
||||||
const zoneId2 = 3;
|
|
||||||
let ticketIDs;
|
let ticketIDs;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const zoneId = 4;
|
||||||
const originalTickets = await models.Ticket.find({
|
const originalTickets = await models.Ticket.find({
|
||||||
where: {
|
where: {
|
||||||
zoneFk: zoneId
|
zoneFk: zoneId
|
||||||
|
@ -29,7 +29,7 @@ describe('zone deletezone()', () => {
|
||||||
|
|
||||||
it('should delete a zone and update their tickets', async() => {
|
it('should delete a zone and update their tickets', async() => {
|
||||||
const tx = await models.Zone.beginTransaction({});
|
const tx = await models.Zone.beginTransaction({});
|
||||||
|
const zoneId = 4;
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
await models.Zone.deleteZone(ctx, zoneId, options);
|
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() => {
|
it('should not delete the zone if it has tickets', async() => {
|
||||||
const tx = await models.Zone.beginTransaction({});
|
const tx = await models.Zone.beginTransaction({});
|
||||||
|
const zoneId = 1;
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
await models.Zone.deleteZone(ctx, zoneId2, options);
|
await models.Zone.deleteZone(ctx, zoneId, options);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e.message;
|
error = e.message;
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toEqual('There are tickets for this area, delete them first');
|
expect(error).toEqual('There are tickets to be invoiced');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue