32 lines
917 B
JavaScript
32 lines
917 B
JavaScript
const UserError = require('vn-loopback/util/user-error');
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('recalculateComponents', {
|
|
description: 'Calculates the price of a sale and its components',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'id',
|
|
description: 'The ticket id',
|
|
type: 'number',
|
|
required: true,
|
|
http: {source: 'path'}
|
|
}],
|
|
returns: {
|
|
type: 'Number',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/recalculateComponents`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.recalculateComponents = async(ctx, id) => {
|
|
const isEditable = await Self.isEditable(ctx, id);
|
|
|
|
if (!isEditable)
|
|
throw new UserError(`The current ticket can't be modified`);
|
|
|
|
return Self.rawSql('CALL vn.ticket_recalcComponents(?, NULL)', [id]);
|
|
};
|
|
};
|