refactor para uso correcto de modelos loopback y ticketCalculateClon

This commit is contained in:
Carlos Jimenez 2018-10-02 09:41:30 +02:00
parent 91e85dc1ec
commit 2e018e61c4
1 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ module.exports = Self => {
});
async function addSalesToTicket(salesToRefund, newRefundTicket, transaction) {
let promises = [];
let formatedSales = [];
salesToRefund.forEach(sale => {
let formatedSale = {
itemFk: sale.sale().itemFk,
@ -33,22 +33,22 @@ module.exports = Self => {
isPicked: sale.sale().isPicked,
created: sale.sale().created
};
promises.push(Self.app.models.Sale.create(formatedSale, transaction));
formatedSales.push(formatedSale);
});
return await Promise.all(promises);
return await Self.app.models.Sale.create(formatedSales, transaction);
}
async function insertIntoClaimEnd(createdSales, claimId, workerId, transaction) {
let promises = [];
let formatedSales = [];
createdSales.forEach(sale => {
let formatedSale = {
saleFk: sale.id,
claimFk: claimId,
workerFk: workerId
};
promises.push(Self.app.models.ClaimEnd.create(formatedSale, transaction));
formatedSales.push(formatedSale);
});
return await Promise.all(promises);
return await Self.app.models.ClaimEnd.create(formatedSales, transaction);
}
async function saveObservation(observation, transaction) {
@ -119,7 +119,7 @@ module.exports = Self => {
let salesToRefund = await models.ClaimBeginning.find(salesFilter);
let createdSales = await addSalesToTicket(salesToRefund, newRefundTicket, {transaction: transaction});
insertIntoClaimEnd(createdSales, id, worker.id, {transaction: transaction});
await Self.rawSql('CALL vn.ticketCalculateClon(?)', [newRefundTicket], {transaction: transaction});
await Self.rawSql('CALL vn.ticketCalculateClon(?, ?)', [newRefundTicket, claim.ticketFk], {transaction: transaction});
await transaction.commit();
return newRefundTicket;
} catch (e) {