refs #6921 feat: addFromDelivery
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Sergio De la torre 2024-04-18 10:01:22 +02:00
parent 76fb9bf7a8
commit e909d64757
2 changed files with 12 additions and 30 deletions

View File

@ -24,31 +24,19 @@ module.exports = Self => {
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);
const observationTypeDropOff = await models.ObservationType.findOne({
where: {code: 'dropOff'}
}, myOptions);
await models.TicketObservation.create({
ticketFk: ticketFk,
observationTypeFk: observationTypeDropOff.id,
description: note
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;
}
}, myOptions);
};
};

View File

@ -6,25 +6,19 @@ describe('ticketObservation addDropOff()', () => {
const code = 'dropOff';
it('should return a dropOff note', async() => {
const myOptions = {};
const tx = await models.TicketObservation.beginTransaction({});
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await models.TicketObservation.beginTransaction({});
myOptions.transaction = tx;
}
try {
const options = {transaction: tx};
await models.TicketObservation.addDropOff(
ticketFk, note, myOptions);
ticketFk, note, options);
const observationTypeDropOff = await models.TicketObservation.find({
where: {
ticketFk,
code
}
}, myOptions);
}, options);
expect(observationTypeDropOff.length).toEqual(1);