2018-08-02 07:49:00 +00:00
|
|
|
let UserError = require('../../helpers').UserError;
|
|
|
|
|
2018-06-28 13:24:27 +00:00
|
|
|
module.exports = Self => {
|
2018-07-11 11:52:04 +00:00
|
|
|
Self.remoteMethod('new', {
|
2018-06-28 13:24:27 +00:00
|
|
|
description: 'Create a newticket and returns the new ID',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'params',
|
|
|
|
type: 'object',
|
|
|
|
required: true,
|
2018-07-24 09:27:04 +00:00
|
|
|
description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed, userId',
|
2018-06-28 13:24:27 +00:00
|
|
|
http: {source: 'body'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'number',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2018-07-11 11:52:04 +00:00
|
|
|
path: `/new`,
|
2018-06-28 13:24:27 +00:00
|
|
|
verb: 'post'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-11 11:52:04 +00:00
|
|
|
Self.new = async params => {
|
2018-06-28 13:24:27 +00:00
|
|
|
let existsAddress = await Self.app.models.Address.findOne({where: {id: params.addressFk, clientFk: params.clientFk}});
|
|
|
|
if (!existsAddress)
|
2018-08-02 07:49:00 +00:00
|
|
|
throw new UserError(`This address doesn't exist`);
|
2018-06-28 13:24:27 +00:00
|
|
|
|
2018-07-24 09:27:04 +00:00
|
|
|
let query = `CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @pe);
|
|
|
|
SELECT @pe newTicketId;`;
|
2018-06-28 13:24:27 +00:00
|
|
|
let result = await Self.rawSql(query, [
|
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
2018-07-11 11:52:04 +00:00
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk | 442,
|
2018-06-28 13:24:27 +00:00
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
2018-07-11 11:52:04 +00:00
|
|
|
params.routeFk | null,
|
2018-07-24 09:27:04 +00:00
|
|
|
params.landed,
|
|
|
|
params.userId
|
2018-06-28 13:24:27 +00:00
|
|
|
]);
|
2018-07-24 09:27:04 +00:00
|
|
|
|
|
|
|
return result[1][0].newTicketId;
|
2018-06-28 13:24:27 +00:00
|
|
|
};
|
|
|
|
};
|