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: { clientSecret: {
type: Sequelize.STRING, type: Sequelize.STRING,
}, },
requestLimit: {
type: Sequelize.INTEGER,
},
currentToken: { currentToken: {
type: Sequelize.STRING(2000), type: Sequelize.STRING(2000),
}, },

View File

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

View File

@ -34,7 +34,7 @@ async function getClientToken() {
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', '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(); const tokenResponse = await tokenRequest.json();
@ -205,6 +205,7 @@ async function getTradeitems(organizationGln) {
const organizationsResponse = await organizationsRequest.json(); const organizationsResponse = await organizationsRequest.json();
const organizationId = organizationsResponse.organizationId; const organizationId = organizationsResponse.organizationId;
console.log('Organization ID: ', organizationId);
// Get the tradeitems from the organization // 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() { async function getStock() {
const suppliers = await models.suppliers.findAll(); 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) { async function getStockBySupplier(supplierId) {
supplierId = await removeVnPrefix(supplierId); supplierId = await removeVnPrefix(supplierId);
@ -558,11 +570,14 @@ async function getStockBySupplier(supplierId) {
tradeItemFk: await vnUuid(supplyLine.tradeItemId), tradeItemFk: await vnUuid(supplyLine.tradeItemId),
}); });
await models.volumePrices.upsert({ supplyLine.volumePrices.forEach(async (volumePrice) => {
unit: supplyLine.volumePrices.unit, await models.volumePrices.upsert({
price: supplyLine.volumePrices.price, supplyLineFk: supplyLine.supplyLineId,
supplyLineFk: await vnUuid(supplyLine.supplyLineId), unit: volumePrice.unit,
pricePerPiece: volumePrice.pricePerPiece,
});
}); });
} catch (error) { } catch (error) {
if (error.name == 'SequelizeForeignKeyConstraintError') { if (error.name == 'SequelizeForeignKeyConstraintError') {