111 lines
3.2 KiB
JavaScript
111 lines
3.2 KiB
JavaScript
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('componentUpdate', {
|
|
description: 'Save ticket sale components',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'id',
|
|
type: 'Number',
|
|
required: true,
|
|
description: 'The ticket id',
|
|
http: {source: 'path'}
|
|
}, {
|
|
arg: 'clientId',
|
|
type: 'Number',
|
|
description: 'The client id',
|
|
required: true
|
|
}, {
|
|
arg: 'agencyModeId',
|
|
type: 'Number',
|
|
description: 'The agencyMode id',
|
|
required: true
|
|
}, {
|
|
arg: 'addressId',
|
|
type: 'Number',
|
|
description: 'The address id',
|
|
required: true
|
|
}, {
|
|
arg: 'zoneId',
|
|
type: 'Number',
|
|
description: 'The zone id',
|
|
required: true
|
|
}, {
|
|
arg: 'warehouseId',
|
|
type: 'Number',
|
|
description: 'The warehouse id',
|
|
required: true
|
|
}, {
|
|
arg: 'companyId',
|
|
type: 'Number',
|
|
description: 'The company id',
|
|
required: true
|
|
}, {
|
|
arg: 'shipped',
|
|
type: 'Date',
|
|
description: 'The shipped date',
|
|
required: true
|
|
}, {
|
|
arg: 'landed',
|
|
type: 'Date',
|
|
description: 'The landing date',
|
|
required: true
|
|
}, {
|
|
arg: 'isDeleted',
|
|
type: 'Boolean',
|
|
description: 'Ticket is deleted',
|
|
required: true
|
|
}, {
|
|
arg: 'option',
|
|
type: 'Number',
|
|
description: 'Action id',
|
|
required: true
|
|
}],
|
|
returns: {
|
|
type: ['Object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/componentUpdate`,
|
|
verb: 'post'
|
|
}
|
|
});
|
|
|
|
Self.componentUpdate = async(ctx, id, clientId, agencyModeId, addressId, zoneId, warehouseId,
|
|
companyId, shipped, landed, isDeleted, option) => {
|
|
const userId = ctx.req.accessToken.userId;
|
|
const models = Self.app.models;
|
|
const isEditable = await models.Ticket.isEditable(ctx, id);
|
|
|
|
if (!isEditable)
|
|
throw new UserError(`The sales of this ticket can't be modified`);
|
|
|
|
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
|
|
if (!isProductionBoss) {
|
|
const zoneShipped = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
|
|
|
|
if (!zoneShipped || zoneShipped.zoneFk != zoneId)
|
|
throw new UserError(`You don't have privileges to change the zone`);
|
|
}
|
|
|
|
// Force unroute
|
|
const hasToBeUnrouted = true;
|
|
let query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
|
let res = await Self.rawSql(query, [
|
|
id,
|
|
clientId,
|
|
agencyModeId,
|
|
addressId,
|
|
zoneId,
|
|
warehouseId,
|
|
companyId,
|
|
shipped,
|
|
landed,
|
|
isDeleted,
|
|
hasToBeUnrouted,
|
|
option
|
|
]);
|
|
return res;
|
|
};
|
|
};
|