7253-devToTest_2418 #2350

Merged
alexm merged 320 commits from 7253-devToTest_2418 into test 2024-04-23 08:02:46 +00:00
6 changed files with 86 additions and 3 deletions
Showing only changes of commit ccc9251d39 - Show all commits

View File

@ -527,7 +527,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`)
(4, 'SalesPerson', 'salesPerson'),
(5, 'Administrative', 'administrative'),
(6, 'Weight', 'weight'),
(7, 'InvoiceOut', 'invoiceOut');
(7, 'InvoiceOut', 'invoiceOut'),
(8, 'DropOff', 'dropOff');
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`)
VALUES

View File

@ -0,0 +1,4 @@
-- Place your SQL code here
USE vn;
INSERT INTO vn.observationType (description,code) VALUES ('Entrega','dropOff');

View File

@ -43,14 +43,15 @@ module.exports = Self => {
st.code ticketStateCode,
st.name ticketStateName,
wh.name warehouseName,
tob.description ticketObservation,
tob.description observationDelivery,
tob2.description observationDropOff,
tob2.id,
a.street,
a.postalCode,
a.city,
am.name agencyModeName,
u.nickname userNickname,
vn.ticketTotalVolume(t.id) volume,
tob.description,
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
c.phone clientPhone,
c.mobile clientMobile,
@ -72,6 +73,9 @@ module.exports = Self => {
LEFT JOIN observationType ot ON ot.code = 'delivery'
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.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 agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN account.user u ON u.id = r.workerFk

View File

@ -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);
};
};

View File

@ -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;
}
});
});

View File

@ -1,6 +1,7 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
require('../methods/ticket-observation/addDropOff')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`The observation type can't be repeated`);