fix: refs #8222 fix deleteZone #3239

Closed
carlossa wants to merge 6 commits from 8222-refactDeleteZone into master
5 changed files with 16 additions and 11 deletions

View File

@ -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;

View File

@ -246,5 +246,7 @@
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
"The raid information is not correct": "The raid information is not correct",
"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"
}

View File

@ -389,6 +389,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);
carlossa marked this conversation as resolved Outdated

hasRefFk suficient

hasRefFk suficient
Outdated
Review

const hasRefFk = ticketList.some(ticket => ticket.refFk)

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;
carlossa marked this conversation as resolved Outdated

si sols es gasta baix, meneja els const cadascun a la seua seccio

si sols es gasta baix, meneja els const cadascun a la seua seccio
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const zoneId = 4;
const originalTickets = await models.Ticket.find({

en el proxim pr, crea de nou la constant, pero en cada una de les seccions

en el proxim pr, crea de nou la constant, pero en cada una de les seccions
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');
});
});