salix/services/loopback/common/methods/ticket/componentUpdate.js

57 lines
1.6 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('componentUpdate', {
description: 'Save ticket sale components',
accessType: 'WRITE',
accepts: [{
arg: 'ticketFk',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}, {
arg: 'data',
type: 'Object',
required: true,
description: 'landed, addressFk, agencyModeFk, warehouseFk',
http: {source: 'body'}
}, {
arg: 'context',
type: 'object',
http: function(ctx) {
return ctx;
}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/:ticketFk/componentUpdate`,
verb: 'post'
}
});
Self.componentUpdate = async(ticketFk, data, ctx) => {
let userId = ctx.req.accessToken.userId;
let hasDeliveryRole = await Self.app.models.Account.hasRole(userId, 'delivery');
if (!hasDeliveryRole)
data.hasToBeUnrouted = true;
let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
let res = await Self.rawSql(query, [
ticketFk,
data.clientFk,
data.agencyModeFk,
data.addressFk,
data.warehouseFk,
data.shipped,
data.landed,
data.isDeleted,
data.hasToBeUnrouted,
data.option
]);
return res;
};
};