#7663 setWeight #2817

Merged
jorgep merged 24 commits from 7663-setWeight into dev 2024-09-11 07:40:32 +00:00
1 changed files with 14 additions and 5 deletions
Showing only changes of commit 52d62710e6 - Show all commits

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');
alexm marked this conversation as resolved
Review

Esta comprobación la han pedido?

Esta comprobación la han pedido?
Review

Sí, me dijo que solo se debe de poder establecer el peso del ticket si no tiene.

Sí, me dijo que solo se debe de poder establecer el peso del ticket si no tiene.
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');
jorgep marked this conversation as resolved Outdated
Outdated
Review

Yo daria un error mas especifico diciendo que no pueden pq no son del mismo equipo

Yo daria un error mas especifico diciendo que no pueden pq no son del mismo equipo
}
@ -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;