7299_testToMaster #2411

Merged
alexm merged 342 commits from 7299_testToMaster into master 2024-05-07 05:30:42 +00:00
5 changed files with 95 additions and 2 deletions
Showing only changes of commit 32e2827287 - 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

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

View File

@ -0,0 +1,54 @@
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 = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const observationTypeDropOff = await models.ObservationType.findOne({
where: {code: 'dropOff'}
}, myOptions);
await models.TicketObservation.create({
ticketFk: ticketFk,
observationTypeFk: observationTypeDropOff.id,
description: note
}, myOptions);
if (tx) await tx.commit();
} catch (error) {
if (tx) await tx.rollback();
throw error;
}
};
};

View File

@ -0,0 +1,37 @@
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 myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await models.TicketObservation.beginTransaction({});
myOptions.transaction = tx;
}
try {
await models.TicketObservation.addDropOff(
ticketFk, note, myOptions);
const observationTypeDropOff = await models.TicketObservation.find({
where: {
ticketFk,
code
}
}, myOptions);
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`);