Merge pull request '3520_wareshouse_back' (!2218) from 3520_wareshouse_back into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2218
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-03-28 07:16:56 +00:00
commit c47989c6fe
4 changed files with 89 additions and 0 deletions

View File

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

View File

@ -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);
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions);
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/ticket-collection/hasUncheckedTicket')(Self);
};

View File

@ -13,6 +13,9 @@
},
"usedShelves": {
"type": "number"
},
"collectionFk": {
"type": "number"
}
},
"relations": {
@ -20,6 +23,11 @@
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
},
"collection": {
"type": "belongsTo",
"model": "Collection",
"foreignKey": "collectionFk"
}
}
}