dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
2 changed files with 14 additions and 16 deletions
Showing only changes of commit 10361ba78e - Show all commits

View File

@ -5,23 +5,28 @@ module.exports = Self => {
accepts: [
{
arg: 'expeditions',
type: ['object'],
type: [{
expeditionFk: 'number',
stateCode: 'string',
}],
required: true,
description: 'Array of objects containing expeditionFk and stateCode'
}
],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/addExpeditionState`,
path: `/addState`,
verb: 'post'
}
});
Self.updateExpedtionState = async(expeditions, options) => {
console.log('Expeditions!!!!!!!!', expeditions);
Self.addExpeditionState = async(expeditions, options) => {
const models = Self.app.models;
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -32,22 +37,19 @@ module.exports = Self => {
const promises = [];
try {
const conn = Self.dataSource.connector;
for (const expedition of expeditions) {
const expeditionStateType = await models.expeditionStateType.findOne(
const expeditionStateType = await models.ExpeditionStateType.findOne(
{
fields: ['id'],
where: {code: expedition.stateCode}
}
);
const result = await conn.query(stmt);
if (!expeditionStateType.id)
throw new Error(`The state code '${expedition.stateCode}' does not exist.`);
const typeFk = result.id;
const newExpeditionState = models.Self.create({
const typeFk = expeditionStateType.id;
const newExpeditionState = models.ExpeditionState.create({
expeditionFk: expedition.expeditionFk,
typeFk,
});
@ -57,11 +59,10 @@ module.exports = Self => {
await Promise.all(promises);
if (tx) await tx.commit();
return true;
} catch (e) {
if (tx) await tx.rollback();
throw e;
return false;
}
};
};

View File

@ -1,3 +0,0 @@
module.exports = function(Self) {
};