change models

This commit is contained in:
Pau 2023-02-01 13:23:06 +01:00
parent c0f1575a85
commit 53b11dfca0
14 changed files with 35 additions and 17 deletions

View File

@ -12,6 +12,9 @@ const clientConfig = {
clientSecret: {
type: Sequelize.STRING,
},
requestLimit: {
type: Sequelize.INTEGER,
},
currentToken: {
type: Sequelize.STRING(2000),
},

View File

@ -4,18 +4,18 @@ dotenv.config();
let sequelize = createConnection();
import botanicalNames from './botanicalNames.js';
import countryOfOriginIsoCodes from './countryOfOriginIsoCodes.js';
import packageModel from './package.js';
import packingConfigurations from './packingConfigurations.js';
import photos from './photos.js';
import seasonalPeriod from './seasonalPeriod.js';
import tradeItem from './tradeItem.js';
import clientConfig from './clientConfig.js';
import characteristics from './characteristics.js';
import supplyLine from './supplyLine.js';
import volumePrices from './volumePrices.js';
import suppliers from './suppliers.js';
import botanicalNames from './tradeItem/botanicalNames.js';
import countryOfOriginIsoCodes from './tradeItem/countryOfOriginIsoCodes.js';
import packageModel from './tradeItem/package.js';
import packingConfigurations from './tradeItem/packingConfigurations.js';
import photos from './tradeItem/photos.js';
import seasonalPeriod from './tradeItem/seasonalPeriod.js';
import tradeItem from './tradeItem/tradeItem.js';
import clientConfig from './conf/clientConfig.js';
import characteristics from './tradeItem/characteristics.js';
import supplyLine from './supplyLine/supplyLine.js';
import volumePrices from './supplyLine/volumePrices.js';
import suppliers from './supplier/suppliers.js';
/**
* Contains all the models that are related to the application.

View File

@ -34,7 +34,7 @@ async function getClientToken() {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}&scope=role:app catalog:read supply:read organization:read network:read`,
body: `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}&scope=role:app catalog:read supply:read organization:read network:write network:read`,
});
const tokenResponse = await tokenRequest.json();
@ -205,6 +205,7 @@ async function getTradeitems(organizationGln) {
const organizationsResponse = await organizationsRequest.json();
const organizationId = organizationsResponse.organizationId;
console.log('Organization ID: ', organizationId);
// Get the tradeitems from the organization
@ -471,6 +472,11 @@ async function getTradeItem(tradeItemId) {
}
/**
* Gets the stock for all suppliers
*
* Does this by getting all suppliers and then calling the getStockBySupplier function for each supplier
*/
async function getStock() {
const suppliers = await models.suppliers.findAll();
@ -485,6 +491,12 @@ async function getStock() {
}
/**
* Returns the stock for a given supplier
*
* @param {*} supplierId
* @returns void - inserts the stock into the database
*/
async function getStockBySupplier(supplierId) {
supplierId = await removeVnPrefix(supplierId);
@ -558,11 +570,14 @@ async function getStockBySupplier(supplierId) {
tradeItemFk: await vnUuid(supplyLine.tradeItemId),
});
await models.volumePrices.upsert({
unit: supplyLine.volumePrices.unit,
price: supplyLine.volumePrices.price,
supplyLineFk: await vnUuid(supplyLine.supplyLineId),
supplyLine.volumePrices.forEach(async (volumePrice) => {
await models.volumePrices.upsert({
supplyLineFk: supplyLine.supplyLineId,
unit: volumePrice.unit,
pricePerPiece: volumePrice.pricePerPiece,
});
});
} catch (error) {
if (error.name == 'SequelizeForeignKeyConstraintError') {