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

57 lines
1.6 KiB
JavaScript
Raw Normal View History

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'}
2018-05-31 09:56:52 +00:00
}, {
arg: 'context',
type: 'object',
http: function(ctx) {
return ctx;
}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/:ticketFk/componentUpdate`,
verb: 'post'
}
});
2018-05-31 09:56:52 +00:00
Self.componentUpdate = async(ticketFk, data, ctx) => {
let userId = ctx.req.accessToken.userId;
let hasDeliveryRole = await Self.app.models.Account.hasRole(userId, 'delivery');
2018-05-31 09:56:52 +00:00
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;
};
};