trying to solve sequelize uuid bug
This commit is contained in:
parent
8500175cef
commit
af1d804cb1
|
@ -12,6 +12,8 @@ The Floriday service project should perform the following tasks:
|
||||||
This is done using the [Sequelize](https://sequelize.org/) ORM and storing the data as it is received from the API,
|
This is done using the [Sequelize](https://sequelize.org/) ORM and storing the data as it is received from the API,
|
||||||
so it can be compared with the previous data.
|
so it can be compared with the previous data.
|
||||||
|
|
||||||
|
# EVERY UUID GENERATED IN THIS PROJECT IS PREPENDED W/ 'Vn-' BECAUSE OF A BUG IN SEQUELIZE
|
||||||
|
|
||||||
## Guidelines
|
## Guidelines
|
||||||
|
|
||||||
- In case a new model is created, it should follow the following structure:
|
- In case a new model is created, it should follow the following structure:
|
||||||
|
|
24
index.js
24
index.js
|
@ -4,16 +4,32 @@ import * as vnUtils from './utils.js';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
import models from './models/index.js';
|
import { models } from './models/index.js';
|
||||||
|
|
||||||
|
import suppliers from './suppliersGln.js';
|
||||||
|
|
||||||
let tokenExpirationDate = await vnUtils.getClientToken(models);
|
let tokenExpirationDate = await vnUtils.getClientToken(models);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (process.env.QUERYSUPPLIERS) {
|
||||||
|
|
||||||
|
console.log('Querying suppliers...');
|
||||||
|
console.log(suppliers.suppliers.length + ' suppliers found');
|
||||||
|
|
||||||
|
for (let i = 0; i < suppliers.suppliers.length; i++) {
|
||||||
|
console.log(i , 'Querying supplier: ' + suppliers.suppliers[i].SupplierGLN);
|
||||||
|
vnUtils.getTradeitems(suppliers.suppliers[i].SupplierGLN);
|
||||||
|
await vnUtils.sleep(250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
console.log('Querying the API to check for new data...');
|
console.log('Querying the API to check for new data...');
|
||||||
|
|
||||||
vnUtils.getTradeitems(8714231154815);
|
|
||||||
|
|
||||||
console.log('Current token expiration date: ', tokenExpirationDate);
|
console.log('Current token expiration date: ', tokenExpirationDate);
|
||||||
|
|
||||||
if (moment().isAfter(tokenExpirationDate)) {
|
if (moment().isAfter(tokenExpirationDate)) {
|
||||||
|
@ -21,7 +37,7 @@ try {
|
||||||
tokenExpirationDate = await vnUtils.getClientToken(models);
|
tokenExpirationDate = await vnUtils.getClientToken(models);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, process.env.STATUS == 'development' ? 10000 : 20000);
|
}, process.env.STATUS == 'development' ? 15000 : 30000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Unable to connect to the database:', error);
|
console.error('Unable to connect to the database:', error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const botanicalNames = {
|
const botanicalNames = {
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
|
|
|
@ -2,12 +2,12 @@ import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const characteristics = {
|
const characteristics = {
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
|
||||||
},
|
|
||||||
vnbCode: {
|
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
vnbValueCode: {
|
vbnCode: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
vbnValueCode: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const countryOfOriginIsoCodes = {
|
const countryOfOriginIsoCodes = {
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
isoCode: {
|
isoCode: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
|
|
|
@ -2,11 +2,7 @@ import { Sequelize } from 'sequelize';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
let sequelize = new Sequelize(process.env.DB_SCHEMA, process.env.DB_USER, process.env.DB_PWD, {
|
let sequelize = createConnection();
|
||||||
host: process.env.DB_HOST,
|
|
||||||
dialect: process.env.DB_DIALECT,
|
|
||||||
logging: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
import additionalPricePerPiece from './additionalPricePerPiece.js';
|
import additionalPricePerPiece from './additionalPricePerPiece.js';
|
||||||
import botanicalNames from './botanicalNames.js';
|
import botanicalNames from './botanicalNames.js';
|
||||||
|
@ -32,16 +28,31 @@ let models = {
|
||||||
characteristics: characteristics(sequelize),
|
characteristics: characteristics(sequelize),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.FORCE_SYNC === 'true') {
|
if (process.env.FORCE_SYNC) {
|
||||||
console.log('Syncing the models...');
|
console.log('Syncing the models...');
|
||||||
await sequelize.sync({ force: true });
|
await sequelize.sync({ force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.SECRETS === 'true') {
|
if (process.env.SECRETS) {
|
||||||
await models.clientConfig.create({
|
await models.clientConfig.create({
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: process.env.CLIENT_ID,
|
||||||
clientSecret: process.env.CLIENT_SECRET,
|
clientSecret: process.env.CLIENT_SECRET,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default models;
|
function createConnection() {
|
||||||
|
console.log('Creating the connection...');
|
||||||
|
return new Sequelize(process.env.DB_SCHEMA, process.env.DB_USER, process.env.DB_PWD, {
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
dialect: process.env.DB_DIALECT,
|
||||||
|
logging: false,
|
||||||
|
pool: {
|
||||||
|
max: 20,
|
||||||
|
min: 0,
|
||||||
|
acquire: 60000,
|
||||||
|
idle: 10000,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { models } ;
|
||||||
|
|
|
@ -12,9 +12,6 @@ const PackageModel = {
|
||||||
vbnPackageCode: {
|
vbnPackageCode: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
},
|
},
|
||||||
customPackageId: {
|
|
||||||
type: Sequelize.UUID,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ const packingConfigurations = {
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
piecesPerPackage: {
|
piecesPerPackage: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
|
|
|
@ -2,10 +2,10 @@ import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const photos = {
|
const photos = {
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
photoId: {
|
photoId: {
|
||||||
type: Sequelize.UUID,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
|
|
|
@ -7,7 +7,7 @@ const seasonalPeriod = {
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
tradeItemFk: {
|
tradeItemFk: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
startWeek: {
|
startWeek: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
|
|
|
@ -7,11 +7,11 @@ const tradeItem = {
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
},
|
},
|
||||||
tradeItemId: {
|
tradeItemId: {
|
||||||
type: Sequelize.UUID,
|
type: Sequelize.STRING,
|
||||||
unique: true,
|
unique: true,
|
||||||
},
|
},
|
||||||
supplierOrganizationId: {
|
supplierOrganizationId: {
|
||||||
type: Sequelize.UUID
|
type: Sequelize.STRING
|
||||||
},
|
},
|
||||||
code: {
|
code: {
|
||||||
type: Sequelize.STRING
|
type: Sequelize.STRING
|
||||||
|
|
|
@ -882,6 +882,13 @@
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
"validator": "^13.7.0",
|
"validator": "^13.7.0",
|
||||||
"wkx": "^0.5.0"
|
"wkx": "^0.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sequelize-pool": {
|
"sequelize-pool": {
|
||||||
|
@ -964,9 +971,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "8.3.2",
|
"version": "9.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg=="
|
||||||
},
|
},
|
||||||
"validator": {
|
"validator": {
|
||||||
"version": "13.7.0",
|
"version": "13.7.0",
|
||||||
|
|
10
package.json
10
package.json
|
@ -4,16 +4,18 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev-sync": "FORCE_SYNC=true node index.js",
|
"dev-sync": "FORCE_SYNC=true node --max-old-space-size=4096 index.js",
|
||||||
"dev-secrets": "SECRETS=true node index.js",
|
"dev-secrets": "SECRETS=true node --max-old-space-size=4096 index.js",
|
||||||
"dev-both": "FORCE_SYNC=true SECRETS=true node index.js"
|
"dev-both": "FORCE_SYNC=true SECRETS=true node --max-old-space-size=4096 index.js",
|
||||||
|
"dev-query": "QUERYSUPPLIERS=true FORCE_SYNC=true SECRETS=true node --max-old-space-size=4096 index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"mariadb": "^3.0.2",
|
"mariadb": "^3.0.2",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"node-fetch": "^3.3.0",
|
"node-fetch": "^3.3.0",
|
||||||
"sequelize": "^6.26.0"
|
"sequelize": "^6.26.0",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.31.0"
|
"eslint": "^8.31.0"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
239
utils.js
239
utils.js
|
@ -1,7 +1,8 @@
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import models from './models/index.js';
|
import { models } from './models/index.js';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
/**
|
/**
|
||||||
* The Endpoint where the Access Token is requested
|
* The Endpoint where the Access Token is requested
|
||||||
|
@ -106,6 +107,24 @@ async function getJWT() {
|
||||||
return clientConfigData[0].currentToken;
|
return clientConfigData[0].currentToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pauses the execution of the script for the given amount of milliseconds
|
||||||
|
*
|
||||||
|
* @param {integer} ms
|
||||||
|
* @returns A promise that resolves after ms milliseconds.
|
||||||
|
*/
|
||||||
|
async function sleep(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns every tradeitem from the organization
|
||||||
|
*
|
||||||
|
* @param {*} organizationGln
|
||||||
|
*/
|
||||||
async function getTradeitems(organizationGln) {
|
async function getTradeitems(organizationGln) {
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
@ -115,7 +134,6 @@ async function getTradeitems(organizationGln) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const BASE_CUSTOMER_URL = 'https://api.staging.floriday.io/customers-api/2022v2/';
|
const BASE_CUSTOMER_URL = 'https://api.staging.floriday.io/customers-api/2022v2/';
|
||||||
//const BASE_SUPPLIER_URL = 'https://api.staging.floriday.io/suppliers-api/2022v2/';
|
|
||||||
|
|
||||||
// Get the organization id from the organizationGln
|
// Get the organization id from the organizationGln
|
||||||
|
|
||||||
|
@ -136,103 +154,154 @@ async function getTradeitems(organizationGln) {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers,
|
headers: headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tradeitemsResponse = await tradeitemsRequest.json();
|
const tradeitemsResponse = await tradeitemsRequest.json();
|
||||||
|
|
||||||
tradeitemsResponse.forEach(async item => {
|
// if there is at least one tradeitem, save it in the database
|
||||||
try{
|
|
||||||
models.tradeItem.upsert({
|
|
||||||
tradeItemId: item.tradeItemId,
|
|
||||||
supplierOrganizationId: item.supplierOrganizationId,
|
|
||||||
code: item.code,
|
|
||||||
gtin: item.gtin,
|
|
||||||
vbnProductCode: item.vbnProductCode,
|
|
||||||
name: item.name,
|
|
||||||
isDeleted: item.isDeleted,
|
|
||||||
sequenceNumber: item.sequenceNumber,
|
|
||||||
tradeItemVersion: item.tradeItemVersion,
|
|
||||||
isCustomerSpecific: item.isCustomerSpecific,
|
|
||||||
isHiddenInCatalog: item.isHiddenInCatalog,
|
|
||||||
});
|
|
||||||
|
|
||||||
item.characteristics.forEach((characteristic) => {
|
//console.log(tradeitemsResponse[0]);
|
||||||
models.characteristics.upsert({
|
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
vnbCode: characteristic.vnbCode,
|
|
||||||
vnbValueCode: characteristic.vnbValueCode,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
item.seasonalPeriods.forEach((seasonalPeriod) => {
|
try {
|
||||||
models.seasonalPeriod.upsert({
|
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
startWeek: seasonalPeriod.startWeek,
|
|
||||||
endWeek: seasonalPeriod.endWeek,
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
if (tradeitemsResponse.length > 0 && tradeitemsResponse != null) {
|
||||||
|
|
||||||
item.photos.forEach((photo) => {
|
console.log(`Tradeitems for the organization ${organizationGln} : `, tradeitemsResponse.length);
|
||||||
models.photos.upsert({
|
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
photoId: photo.id,
|
|
||||||
url: photo.url,
|
|
||||||
seasonalPeriodFk: photo.seasonalPeriod,
|
|
||||||
type: photo.type,
|
|
||||||
primary: photo.primary,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
item.packingConfigurations.forEach( async (packagingConfiguration) => {
|
await tradeitemsResponse.forEach(async item => {
|
||||||
let createdPackingConfig = await models.packingConfigurations.upsert({
|
try {
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
piecesPerPackage: packagingConfiguration.piecesPerPackage,
|
|
||||||
bunchesPerPackage: packagingConfiguration.bunchesPerPackage,
|
|
||||||
photoUrl: packagingConfiguration.photoUrl,
|
|
||||||
packagesPerLayer: packagingConfiguration.packagesPerLayer,
|
|
||||||
layersPerLoadCarrier: packagingConfiguration.layersPerLoadCarrier,
|
|
||||||
transportHeightInCm: packagingConfiguration.transportHeightInCm,
|
|
||||||
loadCarrierType: packagingConfiguration.loadCarrierType,
|
|
||||||
isPrimary: packagingConfiguration.isPrimary,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (createdPackingConfig.isNewRecord) {
|
item.tradeItemId = 'Vn-' + item.tradeItemId;
|
||||||
|
|
||||||
models.package.upsert({
|
await models.tradeItem.upsert({
|
||||||
packingConfigurationsFk: createdPackingConfig[0].id,
|
tradeItemId: item.tradeItemId,
|
||||||
vbnPackageCode: packagingConfiguration.package.vbnPackageCode,
|
supplierOrganizationId: organizationGln,
|
||||||
vbnPackageValueCode: packagingConfiguration.package.vbnPackageValueCode,
|
code: item.code,
|
||||||
|
gtin: item.gtin,
|
||||||
|
vbnProductCode: item.vbnProductCode,
|
||||||
|
name: item.name,
|
||||||
|
isDeleted: item.isDeleted,
|
||||||
|
sequenceNumber: item.sequenceNumber,
|
||||||
|
tradeItemVersion: item.tradeItemVersion,
|
||||||
|
isCustomerSpecific: item.isCustomerSpecific,
|
||||||
|
isHiddenInCatalog: item.isHiddenInCatalog,
|
||||||
});
|
});
|
||||||
|
|
||||||
models.additionalPricePerPiece.upsert({
|
try {
|
||||||
packingConfigurationsFk: createdPackingConfig.dataValues.id,
|
await item.characteristics.forEach((characteristic) => {
|
||||||
currency: packagingConfiguration.additionalPricePerPiece.currency,
|
models.characteristics.upsert({
|
||||||
value: packagingConfiguration.additionalPricePerPiece.value,
|
tradeItemFk: item.tradeItemId,
|
||||||
});
|
vbnCode: characteristic.vbnCode,
|
||||||
|
vbnValueCode: characteristic.vbnValueCode,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the characteristics for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await item.seasonalPeriods.forEach((seasonalPeriod) => {
|
||||||
|
models.seasonalPeriod.upsert({
|
||||||
|
tradeItemFk: item.tradeItemId,
|
||||||
|
startWeek: seasonalPeriod.startWeek,
|
||||||
|
endWeek: seasonalPeriod.endWeek,
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the seasonalPeriods for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await item.photos.forEach((photo) => {
|
||||||
|
|
||||||
|
photo.id = 'Vn-' + photo.id;
|
||||||
|
|
||||||
|
models.photos.upsert({
|
||||||
|
tradeItemFk: item.tradeItemId,
|
||||||
|
photoId: photo.id,
|
||||||
|
url: photo.url,
|
||||||
|
seasonalPeriodFk: photo.seasonalPeriod,
|
||||||
|
type: photo.type,
|
||||||
|
primary: photo.primary,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the photos for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await item.packingConfigurations.forEach(async (packagingConfiguration) => {
|
||||||
|
|
||||||
|
let uuid = uuidv4();
|
||||||
|
uuid = 'Vn-' + uuid;
|
||||||
|
|
||||||
|
await models.packingConfigurations.upsert({
|
||||||
|
tradeItemFk: item.tradeItemId,
|
||||||
|
packingConfigurationId: uuid,
|
||||||
|
piecesPerPackage: packagingConfiguration.piecesPerPackage,
|
||||||
|
bunchesPerPackage: packagingConfiguration.bunchesPerPackage,
|
||||||
|
photoUrl: packagingConfiguration.photoUrl,
|
||||||
|
packagesPerLayer: packagingConfiguration.packagesPerLayer,
|
||||||
|
layersPerLoadCarrier: packagingConfiguration.layersPerLoadCarrier,
|
||||||
|
transportHeightInCm: packagingConfiguration.transportHeightInCm,
|
||||||
|
loadCarrierType: packagingConfiguration.loadCarrierType,
|
||||||
|
isPrimary: packagingConfiguration.isPrimary,
|
||||||
|
});
|
||||||
|
|
||||||
|
await models.package.upsert({
|
||||||
|
packingConfigurationsFk: uuid,
|
||||||
|
vbnPackageCode: packagingConfiguration.package.vbnPackageCode,
|
||||||
|
vbnPackageValueCode: packagingConfiguration.package.vbnPackageValueCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
await models.additionalPricePerPiece.upsert({
|
||||||
|
packingConfigurationsFk: uuid,
|
||||||
|
currency: packagingConfiguration.additionalPricePerPiece.currency,
|
||||||
|
value: packagingConfiguration.additionalPricePerPiece.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the packingConfigurations for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
await item.botanicalNames.forEach((botanicalName) => {
|
||||||
|
models.botanicalNames.upsert({
|
||||||
|
tradeItemFk: item.tradeItemId,
|
||||||
|
name: botanicalName,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the botanicalNames for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await item.countryOfOriginIsoCodes.forEach((countryOfOriginIsoCode) => {
|
||||||
|
models.countryOfOriginIsoCodes.upsert({
|
||||||
|
tradeItemFk: item.tradeItemId,
|
||||||
|
isoCode: countryOfOriginIsoCode,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was a error while saving the countryOfOriginIsoCodes for the tradeitem: ', item.tradeItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was an error while saving the data to the database');
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
item.botanicalNames.forEach((botanicalName) => {
|
console.log('There are no tradeitems for the organization: ', organizationGln);
|
||||||
models.botanicalNames.upsert({
|
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
name: botanicalName,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
item.countryOfOriginIsoCodes.forEach((countryOfOriginIsoCode) => {
|
|
||||||
models.countryOfOriginIsoCodes.upsert({
|
|
||||||
tradeItemFk: item.tradeItemId,
|
|
||||||
isoCode: countryOfOriginIsoCode,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.log('There was an error while saving the data to the database');
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log('There was an error while saving the data to the database');
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getClientToken, updateClientConfig, getJWT, getTradeitems };
|
export { getClientToken, updateClientConfig, getJWT, getTradeitems ,sleep };
|
Loading…
Reference in New Issue