fix lastActiveTickets
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-09-30 13:35:37 +02:00
parent 1bff4e3c4e
commit 90e948aeda
2 changed files with 6 additions and 8 deletions

View File

@ -25,9 +25,6 @@ module.exports = Self => {
Self.lastActiveTickets = async(id, ticketId) => {
const ticket = await Self.app.models.Ticket.findById(ticketId);
let shipped = ticket.shipped;
shipped.setDate(shipped.getDate() + 15);
const query = `
SELECT t.id, t.shipped, a.name AS agencyName, w.name AS warehouseName, ad.city AS address
FROM vn.ticket t
@ -35,11 +32,12 @@ module.exports = Self => {
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
JOIN vn.warehouse w ON t.warehouseFk = w.id
JOIN vn.address ad ON t.addressFk = ad.id
WHERE t.shipped BETWEEN CURDATE() AND ? AND t.clientFk = ? AND ts.alertLevel = 0
WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0
AND t.id <> ? AND t.warehouseFk = ?
ORDER BY t.shipped
LIMIT 10`;
return Self.rawSql(query, [shipped, id, ticketId, ticket.warehouseFk]);
return Self.rawSql(query, [id, ticketId, ticket.warehouseFk]);
};
};

View File

@ -2,11 +2,11 @@ const app = require('vn-loopback/server/server');
describe('client lastActiveTickets()', () => {
it('should return the last three active tickets', async() => {
const clientId = 104;
const ticketId = 9;
const clientId = 109;
const ticketId = 19;
let result = await app.models.Client.lastActiveTickets(clientId, ticketId);
expect(result.length).toEqual(1);
expect(result.length).toEqual(3);
});
});