3520_wareshouse_back #2218
|
@ -0,0 +1,40 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('hasUncheckedTicket', {
|
||||||
|
description:
|
||||||
|
'Get boolean if the collection of ticket has a ticket not checked',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'ticketFk',
|
||||||
|
type: 'integer',
|
||||||
|
required: true,
|
||||||
|
description: 'Ticket id'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'boolean',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/hasUncheckedTicket`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.hasUncheckedTicket = async(ticketFk, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const result = await Self.rawSql(`
|
||||||
|
SELECT tc2.ticketFk
|
||||||
|
FROM vn.ticketCollection tc
|
||||||
|
JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk
|
||||||
|
LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk
|
||||||
|
JOIN vn.state s ON s.id = ts.stateFk
|
||||||
|
JOIN vn.state s2 ON s2.code = 'CHECKED'
|
||||||
|
WHERE tc.ticketFk = ? AND s.order < s2.id
|
||||||
|
LIMIT 1;`,
|
||||||
|
[ticketFk], myOptions);
|
||||||
|
return result.length > 0 && result[0]['ticketFk'] > 0;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('ticketCollection hasUncheckedTicket()', () => {
|
||||||
|
it('should return false because there are not tickets not checked', async() => {
|
||||||
|
const ticketFk = 1;
|
||||||
|
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true because there is a ticket not checked', async() => {
|
||||||
|
const ticketFk = 1;
|
||||||
|
const stateFkCurrent = 16;
|
||||||
|
const stateFkUpdated = 7;
|
||||||
|
|
||||||
|
const tx = await models.TicketTracking.beginTransaction({});
|
||||||
|
const myOptions = {transaction: tx};
|
||||||
|
const filter = {where: {
|
||||||
|
ticketFk: 1,
|
||||||
|
stateFk: stateFkCurrent}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const ticketTracking = await models.TicketTracking.findOne(filter, myOptions);
|
||||||
|
await ticketTracking.updateAttributes({
|
||||||
|
stateFk: stateFkUpdated
|
||||||
|
}, myOptions);
|
||||||
sergiodt marked this conversation as resolved
Outdated
|
|||||||
|
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/ticket-collection/hasUncheckedTicket')(Self);
|
||||||
|
};
|
|
@ -13,6 +13,9 @@
|
||||||
},
|
},
|
||||||
"usedShelves": {
|
"usedShelves": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"collectionFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
@ -20,6 +23,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Ticket",
|
"model": "Ticket",
|
||||||
"foreignKey": "ticketFk"
|
"foreignKey": "ticketFk"
|
||||||
|
},
|
||||||
|
"collection": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Collection",
|
||||||
|
"foreignKey": "collectionFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
, myOptions