chore: refs #7663 fix logic
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-08-13 13:49:00 +02:00
parent 85f064c869
commit 52d62710e6
1 changed files with 14 additions and 5 deletions

View File

@ -16,13 +16,17 @@ module.exports = Self => {
required: true,
description: 'The weight value',
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/setWeight`,
verb: 'POST'
}
});
Self.setWeight = async(ctx, ticketId, weight, invoiceable, options) => {
Self.setWeight = async(ctx, ticketId, weight, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
@ -36,10 +40,10 @@ module.exports = Self => {
}
try {
const ticket = await Self.findById(ticketId, null, myOptions);
if (ticket.weight) throw new UserError('Weight already set');
const canEdit = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'updateAttributes');
const ticket = await Self.findById(ticketId, null, myOptions);
const client = await models.Client.findById(ticket.clientFk, {
include: {relation: 'salesPersonUser'}},
myOptions);
@ -51,7 +55,10 @@ module.exports = Self => {
where: {workerFk: {inq: [userId, salesPersonUser.id]}}
}, myOptions);
if (workerDepartments[0].departmentFk != workerDepartments[1].departmentFk)
if (
workerDepartments.length == 2 &&
workerDepartments[0].departmentFk != workerDepartments[1].departmentFk
)
throw new UserError('You don\'t have enough privileges');
}
@ -63,10 +70,12 @@ module.exports = Self => {
const [{taxArea}] = await Self.rawSql('SELECT clientTaxArea(?,?) taxArea',
[ticket.clientFk, ticket.warehouseFk], myOptions);
if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice)
if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice) {
await Self.invoiceTicketsAndPdf(ctx, [ticketId], null, myOptions);
return true;
}
if (tx) await tx.commit();
return false;
} catch (e) {
if (tx) await tx.rollback();
throw e;