This commit is contained in:
parent
0b88194f09
commit
bbc26d8ba4
|
@ -1,17 +1,11 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('updateExpedtionState', {
|
||||
Self.remoteMethod('addExpeditionState', {
|
||||
description: 'Update an expedition state',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'expeditions',
|
||||
type: [
|
||||
{
|
||||
expeditionFk: 'number',
|
||||
stateCode: 'string'
|
||||
}
|
||||
],
|
||||
type: ['object'],
|
||||
required: true,
|
||||
description: 'Array of objects containing expeditionFk and stateCode'
|
||||
}
|
||||
|
@ -23,6 +17,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.updateExpedtionState = async(expeditions, options) => {
|
||||
console.log('Expeditions!!!!!!!!', expeditions);
|
||||
const models = Self.app.models;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
@ -35,22 +30,22 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
if (expeditions.length === 0)
|
||||
return false;
|
||||
|
||||
const promises = [];
|
||||
try {
|
||||
const conn = Self.dataSource.connector;
|
||||
for (const expedition of expeditions) {
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT id FROM vn.expeditionStateType WHERE code = ?`,
|
||||
[expedition.stateCode]
|
||||
const expeditionStateType = await models.expeditionStateType.findOne(
|
||||
{
|
||||
fields: ['id'],
|
||||
where: {code: expedition.stateCode}
|
||||
}
|
||||
);
|
||||
const result = await conn.query(stmt);
|
||||
if (result.length === 0)
|
||||
throw new Error(`The state code '${exp.stateCode}' does not exist.`);
|
||||
|
||||
const typeFk = result[0].id;
|
||||
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({
|
||||
expeditionFk: expedition.expeditionFk,
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
"ExpeditionState": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ExpeditionStateType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Packaging": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function(Self) {
|
||||
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "ExpeditionStateType",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "expeditionStateType"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"code": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue