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-09-25 12:39:08 +00:00
|
|
|
Self.new = async(params, transaction) => {
|
2018-10-10 07:59:42 +00:00
|
|
|
let existsAddress = await Self.app.models.Address.findOne({
|
|
|
|
where: {
|
|
|
|
id: params.addressFk,
|
|
|
|
clientFk: params.clientFk}
|
|
|
|
});
|
|
|
|
|
2018-06-28 13:24:27 +00:00
|
|
|
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-09-26 13:48:33 +00:00
|
|
|
let query = `CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
|
|
|
|
SELECT @result 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,
|
2018-10-03 12:05:25 +00:00
|
|
|
params.agencyModeFk | null,
|
2018-07-11 11:52:04 +00:00
|
|
|
params.routeFk | null,
|
2018-07-24 09:27:04 +00:00
|
|
|
params.landed,
|
|
|
|
params.userId
|
2018-09-25 12:39:08 +00:00
|
|
|
], transaction);
|
2018-07-24 09:27:04 +00:00
|
|
|
|
2018-10-10 07:59:42 +00:00
|
|
|
return await Self.findOne({
|
|
|
|
where: {id: result[1][0].newTicketId}
|
|
|
|
}, transaction);
|
2018-06-28 13:24:27 +00:00
|
|
|
};
|
|
|
|
};
|