This commit is contained in:
parent
80168900fe
commit
b2adde4ba3
|
@ -1,7 +1,7 @@
|
|||
let UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('updateDiscount', {
|
||||
Self.remoteMethodCtx('updateDiscount', {
|
||||
description: 'Changes the discount of a sale',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
|
@ -21,16 +21,12 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.updateDiscount = async params => {
|
||||
Self.updateDiscount = async(ctx, params) => {
|
||||
if (isNaN(params.editLines[0].discount))
|
||||
throw new UserError(`The value should be a number`);
|
||||
|
||||
let model = Self.app.models;
|
||||
let thisTicketIsEditable = await model.Ticket.isEditable(params.editLines[0].ticketFk);
|
||||
|
||||
if (!thisTicketIsEditable)
|
||||
throw new UserError(`The sales of this ticket can't be modified`);
|
||||
|
||||
let ticket = await model.Ticket.find({
|
||||
where: {
|
||||
id: params.editLines[0].ticketFk
|
||||
|
@ -41,9 +37,16 @@ module.exports = Self => {
|
|||
fields: ['salesPersonFk']
|
||||
}
|
||||
}],
|
||||
fields: ['id', 'clientFk']
|
||||
fields: ['id', 'clientFk', 'refFk']
|
||||
});
|
||||
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
|
||||
|
||||
if ((!thisTicketIsEditable && !isSalesAssistant) || (ticket.refFk && isSalesAssistant))
|
||||
throw new UserError(`The sales of this ticket can't be modified`);
|
||||
|
||||
|
||||
let componentToUse;
|
||||
let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'});
|
||||
|
||||
|
|
Loading…
Reference in New Issue