fix: refs #8222 fix deleteZone #3239

Closed
carlossa wants to merge 6 commits from 8222-refactDeleteZone into master
2 changed files with 9 additions and 6 deletions
Showing only changes of commit 0bb7fa99fd - Show all commits

View File

@ -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);
if (hasRefFk)
throw new UserError('There are tickets to be invoiced');

View File

@ -14,9 +14,11 @@ describe('zone deletezone()', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const zoneId = 4;
const originalTickets = await models.Ticket.find({
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;