7299_testToMaster #2411
|
@ -527,7 +527,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`)
|
||||||
(4, 'SalesPerson', 'salesPerson'),
|
(4, 'SalesPerson', 'salesPerson'),
|
||||||
(5, 'Administrative', 'administrative'),
|
(5, 'Administrative', 'administrative'),
|
||||||
(6, 'Weight', 'weight'),
|
(6, 'Weight', 'weight'),
|
||||||
(7, 'InvoiceOut', 'invoiceOut');
|
(7, 'InvoiceOut', 'invoiceOut'),
|
||||||
|
(8, 'DropOff', 'dropOff');
|
||||||
|
|
||||||
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`)
|
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
INSERT INTO vn.observationType (description,code) VALUES ('Entrega','dropOff');
|
|
@ -43,14 +43,15 @@ module.exports = Self => {
|
||||||
st.code ticketStateCode,
|
st.code ticketStateCode,
|
||||||
st.name ticketStateName,
|
st.name ticketStateName,
|
||||||
wh.name warehouseName,
|
wh.name warehouseName,
|
||||||
tob.description ticketObservation,
|
tob.description observationDelivery,
|
||||||
|
tob2.description observationDropOff,
|
||||||
|
tob2.id,
|
||||||
a.street,
|
a.street,
|
||||||
a.postalCode,
|
a.postalCode,
|
||||||
a.city,
|
a.city,
|
||||||
am.name agencyModeName,
|
am.name agencyModeName,
|
||||||
u.nickname userNickname,
|
u.nickname userNickname,
|
||||||
vn.ticketTotalVolume(t.id) volume,
|
vn.ticketTotalVolume(t.id) volume,
|
||||||
tob.description,
|
|
||||||
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
|
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
|
||||||
c.phone clientPhone,
|
c.phone clientPhone,
|
||||||
c.mobile clientMobile,
|
c.mobile clientMobile,
|
||||||
|
@ -72,6 +73,9 @@ module.exports = Self => {
|
||||||
LEFT JOIN observationType ot ON ot.code = 'delivery'
|
LEFT JOIN observationType ot ON ot.code = 'delivery'
|
||||||
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id
|
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id
|
||||||
AND tob.observationTypeFk = ot.id
|
AND tob.observationTypeFk = ot.id
|
||||||
|
LEFT JOIN observationType ot2 ON ot2.code = 'dropOff'
|
||||||
|
LEFT JOIN ticketObservation tob2 ON tob2.ticketFk = t.id
|
||||||
|
AND tob2.observationTypeFk = ot2.id
|
||||||
LEFT JOIN address a ON a.id = t.addressFk
|
LEFT JOIN address a ON a.id = t.addressFk
|
||||||
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
LEFT JOIN account.user u ON u.id = r.workerFk
|
LEFT JOIN account.user u ON u.id = r.workerFk
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('addDropOff', {
|
||||||
|
description: 'Add a dropOff note in a ticket',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'ticketFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'ticket ID'
|
||||||
|
}, {
|
||||||
|
arg: 'note',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'note text'
|
||||||
|
}],
|
||||||
|
|
||||||
|
http: {
|
||||||
|
path: `/addDropOff`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.addDropOff = async(ticketFk, note, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const observationTypeDropOff = await models.ObservationType.findOne({
|
||||||
|
where: {code: 'dropOff'}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
await models.TicketObservation.create({
|
||||||
|
ticketFk: ticketFk,
|
||||||
|
observationTypeFk: observationTypeDropOff.id,
|
||||||
|
description: note
|
||||||
|
|
||||||
|
}, myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,31 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('ticketObservation addDropOff()', () => {
|
||||||
|
const ticketFk = 5;
|
||||||
|
const note = 'DropOff note';
|
||||||
|
const code = 'dropOff';
|
||||||
|
|
||||||
|
it('should return a dropOff note', async() => {
|
||||||
|
const tx = await models.TicketObservation.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.TicketObservation.addDropOff(
|
||||||
|
ticketFk, note, options);
|
||||||
|
|
||||||
|
const observationTypeDropOff = await models.TicketObservation.find({
|
||||||
|
where: {
|
||||||
|
ticketFk,
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(observationTypeDropOff.length).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,7 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
require('../methods/ticket-observation/addDropOff')(Self);
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
if (err.code === 'ER_DUP_ENTRY')
|
if (err.code === 'ER_DUP_ENTRY')
|
||||||
return new UserError(`The observation type can't be repeated`);
|
return new UserError(`The observation type can't be repeated`);
|
||||||
|
|
Loading…
Reference in New Issue