fix: refs #8222 fix deleteZone #3239
|
@ -51,7 +51,7 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
const ticketList = await models.Ticket.find(filter, myOptions);
|
||||
const hasRefFk = ticketList.some(ticket => ticket.refFk !== null && ticket.refFk !== undefined);
|
||||
const hasRefFk = ticketList.some(ticket => ticket.refFk);
|
||||
carlossa marked this conversation as resolved
Outdated
|
||||
if (hasRefFk)
|
||||
throw new UserError('There are tickets to be invoiced');
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@ describe('zone deletezone()', () => {
|
|||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
const zoneId = 4;
|
||||
const originalTickets = await models.Ticket.find({
|
||||
jgallego
commented
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: 4
|
||||
zoneFk: zoneId
|
||||
}
|
||||
});
|
||||
ticketIDs = originalTickets.map(ticket => ticket.id);
|
||||
|
@ -27,12 +29,12 @@ 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, 4, options);
|
||||
await models.Zone.deleteZone(ctx, zoneId, options);
|
||||
|
||||
const updatedZone = await models.Zone.findById(4, null, options);
|
||||
const updatedZone = await models.Zone.findById(zoneId, null, options);
|
||||
|
||||
expect(updatedZone).toBeNull();
|
||||
|
||||
|
@ -45,11 +47,12 @@ 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, 1, options);
|
||||
await models.Zone.deleteZone(ctx, zoneId, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
|
|
Loading…
Reference in New Issue
hasRefFk suficient
const hasRefFk = ticketList.some(ticket => ticket.refFk)