updated transactions
gitea/salix/dev There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2019-09-18 15:11:09 +02:00
parent 86ef44c90d
commit 335f92173c
2 changed files with 18 additions and 18 deletions

View File

@ -25,24 +25,24 @@ module.exports = Self => {
}
});
Self.send = async(ctx, data, transaction) => {
Self.send = async(ctx, data, options) => {
const accessToken = ctx.options && ctx.options.accessToken || ctx.req && ctx.req.accessToken;
const userId = accessToken.userId;
const models = Self.app.models;
const sender = await models.Account.findById(userId, transaction);
const recipient = await models.Account.findById(data.recipientFk, transaction);
const sender = await models.Account.findById(userId, options);
const recipient = await models.Account.findById(data.recipientFk, options);
await Self.create({
sender: sender.name,
recipient: recipient.name,
message: data.message
}, transaction);
}, options);
return await models.MessageInbox.create({
sender: sender.name,
recipient: recipient.name,
finalRecipient: recipient.name,
message: data.message
}, transaction);
}, options);
};
};

View File

@ -22,18 +22,18 @@ module.exports = Self => {
const models = Self.app.models;
const resolvedState = 3;
const claimEnds = await models.ClaimEnd.find({
include: {
relation: 'claimDestination',
fields: ['addressFk']
},
where: {claimFk: params.claimFk}
});
let tx = await Self.beginTransaction({});
try {
let options = {transaction: tx};
const claimEnds = await models.ClaimEnd.find({
include: {
relation: 'claimDestination',
fields: ['addressFk']
},
where: {claimFk: params.claimFk}
}, options);
for (let i = 0; i < claimEnds.length; i++) {
const claimEnd = claimEnds[i];
const destination = claimEnd.claimDestination();
@ -42,7 +42,7 @@ module.exports = Self => {
if (!addressFk)
continue;
let sale = await getSale(claimEnd.saleFk);
let sale = await getSale(claimEnd.saleFk, options);
let ticketFk = await getTicketId({
addressFk: addressFk,
companyFk: sale.ticket().companyFk,
@ -51,7 +51,7 @@ module.exports = Self => {
let address = await models.Address.findOne({
where: {id: addressFk}
});
}, options);
if (!ticketFk) {
ticketFk = await createTicket(ctx, {
@ -84,7 +84,7 @@ module.exports = Self => {
}
}
let claim = await Self.findById(params.claimFk);
let claim = await Self.findById(params.claimFk, null, options);
claim = await claim.updateAttributes({
claimStateFk: resolvedState
}, options);
@ -98,7 +98,7 @@ module.exports = Self => {
}
};
async function getSale(saleFk) {
async function getSale(saleFk, options) {
return await Self.app.models.Sale.findOne({
include: [
{
@ -116,7 +116,7 @@ module.exports = Self => {
}
}],
where: {id: saleFk}
});
}, options);
}
async function getTicketId(params, options) {