refs #4823 Refactor and change in table names
This commit is contained in:
parent
52d2e783c8
commit
9aaf5a9485
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const clientConfig = {
|
const config = {
|
||||||
id: {
|
id: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -21,13 +21,12 @@ const clientConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const ClientConfig = sequelize.define(
|
return sequelize.define(
|
||||||
'clientConfig',
|
'config',
|
||||||
clientConfig,
|
config,
|
||||||
{
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return ClientConfig;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const organizations = {
|
const organization = {
|
||||||
organizationId: {
|
organizationId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
@ -60,12 +60,11 @@ const organizations = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const Organizations = sequelize.define(
|
return sequelize.define(
|
||||||
'organization',
|
'organization',
|
||||||
organizations, {
|
organization, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Organizations;
|
|
||||||
};
|
};
|
|
@ -30,27 +30,29 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conf Models
|
// Conf Models
|
||||||
import clientConfig from './config/clientConfig.js';
|
import config from './config/config.js';
|
||||||
import sequenceNumber from './config/sequenceNumber.js';
|
import sequenceNumber from './config/sequenceNumber.js';
|
||||||
|
|
||||||
// Supply Line Models
|
|
||||||
import supplyLine from './supplyLine/supplyLine.js';
|
|
||||||
import volumePrices from './supplyLine/volumePrices.js';
|
|
||||||
import clockPresalesSupply from './supplyLine/clockPresalesSupply.js';
|
|
||||||
|
|
||||||
// Organization Models
|
// Organization Models
|
||||||
import organization from './organization/organization.js';
|
import organization from './organization/organization.js';
|
||||||
import warehouses from './organization/warehouses.js';
|
|
||||||
|
// Warehouse Models
|
||||||
|
import warehouse from './warehouse/warehouse.js';
|
||||||
|
|
||||||
|
// Supply Line Models
|
||||||
|
import supplyLine from './supplyLine/supplyLine.js';
|
||||||
|
import volumePric from './supplyLine/volumePrice.js';
|
||||||
|
import clockPresaleSupply from './supplyLine/clockPresaleSupply.js';
|
||||||
|
|
||||||
// TradeItem Models
|
// TradeItem Models
|
||||||
import tradeItem from './tradeItem/tradeItem.js';
|
import tradeItem from './tradeItem/tradeItem.js';
|
||||||
import botanicalNames from './tradeItem/botanicalNames.js';
|
import botanicalName from './tradeItem/botanicalName.js';
|
||||||
import countryOfOriginIsoCodes from './tradeItem/countryOfOriginIsoCodes.js';
|
import countryOfOriginIsoCode from './tradeItem/countryOfOriginIsoCode.js';
|
||||||
import packageModel from './tradeItem/package.js';
|
import packageModel from './tradeItem/package.js';
|
||||||
import packingConfigurations from './tradeItem/packingConfigurations.js';
|
import packingConfiguration from './tradeItem/packingConfiguration.js';
|
||||||
import photos from './tradeItem/photos.js';
|
import photo from './tradeItem/photo.js';
|
||||||
import seasonalPeriod from './tradeItem/seasonalPeriod.js';
|
import seasonalPeriod from './tradeItem/seasonalPeriod.js';
|
||||||
import characteristics from './tradeItem/characteristics.js';
|
import characteristic from './tradeItem/characteristic.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all the models that are related to the application.
|
* Contains all the models that are related to the application.
|
||||||
|
@ -58,24 +60,28 @@ import characteristics from './tradeItem/characteristics.js';
|
||||||
let models = {
|
let models = {
|
||||||
sequelize: sequelize,
|
sequelize: sequelize,
|
||||||
sequenceNumber: sequenceNumber(sequelize),
|
sequenceNumber: sequenceNumber(sequelize),
|
||||||
clientConfig: clientConfig(sequelize),
|
config: config(sequelize),
|
||||||
organization: organization(sequelize),
|
organization: organization(sequelize),
|
||||||
warehouses: warehouses(sequelize),
|
warehouse: warehouse(sequelize),
|
||||||
tradeItem: tradeItem(sequelize),
|
tradeItem: tradeItem(sequelize),
|
||||||
botanicalName: botanicalNames(sequelize),
|
botanicalName: botanicalName(sequelize),
|
||||||
characteristic: characteristics(sequelize),
|
characteristic: characteristic(sequelize),
|
||||||
countryOfOriginIsoCode: countryOfOriginIsoCodes(sequelize),
|
countryOfOriginIsoCode: countryOfOriginIsoCode(sequelize),
|
||||||
packingConfiguration: packingConfigurations(sequelize),
|
packingConfiguration: packingConfiguration(sequelize),
|
||||||
photo: photos(sequelize),
|
photo: photo(sequelize),
|
||||||
seasonalPeriod: seasonalPeriod(sequelize),
|
seasonalPeriod: seasonalPeriod(sequelize),
|
||||||
supplyLine: supplyLine(sequelize),
|
supplyLine: supplyLine(sequelize),
|
||||||
volumePrices: volumePrices(sequelize),
|
volumePrice: volumePric(sequelize),
|
||||||
clockPresalesSupply: clockPresalesSupply(sequelize),
|
clockPresaleSupply: clockPresaleSupply(sequelize),
|
||||||
package: packageModel(sequelize),
|
package: packageModel(sequelize),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Foreign Keys
|
// Foreign Keys
|
||||||
try {
|
try {
|
||||||
|
/* TODO: Aplicar dependiendo de cada caso
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
*/
|
||||||
models.characteristic.belongsTo(models.tradeItem, {
|
models.characteristic.belongsTo(models.tradeItem, {
|
||||||
foreignKey: 'tradeItemId',
|
foreignKey: 'tradeItemId',
|
||||||
targetKey: 'tradeItemId',
|
targetKey: 'tradeItemId',
|
||||||
|
@ -99,31 +105,24 @@ try {
|
||||||
models.package.belongsTo(models.packingConfiguration, {
|
models.package.belongsTo(models.packingConfiguration, {
|
||||||
foreignKey: 'packingConfigurationId',
|
foreignKey: 'packingConfigurationId',
|
||||||
targetKey: 'packingConfigurationId',
|
targetKey: 'packingConfigurationId',
|
||||||
|
|
||||||
});
|
});
|
||||||
models.botanicalName.belongsTo(models.tradeItem, {
|
models.botanicalName.belongsTo(models.tradeItem, {
|
||||||
foreignKey: 'tradeItemId',
|
foreignKey: 'tradeItemId',
|
||||||
targetKey: 'tradeItemId',
|
targetKey: 'tradeItemId',
|
||||||
onDelete: 'CASCADE',
|
|
||||||
onUpdate: 'CASCADE',
|
|
||||||
});
|
});
|
||||||
models.countryOfOriginIsoCode.belongsTo(models.tradeItem, {
|
models.countryOfOriginIsoCode.belongsTo(models.tradeItem, {
|
||||||
foreignKey: 'tradeItemId',
|
foreignKey: 'tradeItemId',
|
||||||
targetKey: 'tradeItemId',
|
targetKey: 'tradeItemId',
|
||||||
onDelete: 'CASCADE',
|
|
||||||
onUpdate: 'CASCADE',
|
|
||||||
});
|
});
|
||||||
models.volumePrices.belongsTo(models.supplyLine, {
|
models.volumePrice.belongsTo(models.supplyLine, {
|
||||||
foreignKey: 'supplyLineId',
|
foreignKey: 'supplyLineId',
|
||||||
targetKey: 'supplyLineId',
|
targetKey: 'supplyLineId',
|
||||||
});
|
});
|
||||||
models.supplyLine.belongsTo(models.tradeItem, {
|
models.supplyLine.belongsTo(models.tradeItem, {
|
||||||
foreignKey: 'tradeItemId',
|
foreignKey: 'tradeItemId',
|
||||||
targetKey: 'tradeItemId',
|
targetKey: 'tradeItemId',
|
||||||
onDelete: 'CASCADE',
|
|
||||||
onUpdate: 'CASCADE',
|
|
||||||
});
|
});
|
||||||
models.supplyLine.belongsTo(models.warehouses, {
|
models.supplyLine.belongsTo(models.warehouse, {
|
||||||
foreignKey: 'warehouseId',
|
foreignKey: 'warehouseId',
|
||||||
targetKey: 'warehouseId',
|
targetKey: 'warehouseId',
|
||||||
});
|
});
|
||||||
|
@ -135,19 +134,19 @@ try {
|
||||||
foreignKey: 'organizationId',
|
foreignKey: 'organizationId',
|
||||||
targetKey: 'organizationId',
|
targetKey: 'organizationId',
|
||||||
});
|
});
|
||||||
models.warehouses.belongsTo(models.organization, {
|
models.warehouse.belongsTo(models.organization, {
|
||||||
foreignKey: 'organizationId',
|
foreignKey: 'organizationId',
|
||||||
targetKey: 'organizationId',
|
targetKey: 'organizationId',
|
||||||
});
|
});
|
||||||
models.clockPresalesSupply.belongsTo(models.supplyLine, {
|
models.clockPresaleSupply.belongsTo(models.supplyLine, {
|
||||||
foreignKey: 'supplyLineId',
|
foreignKey: 'supplyLineId',
|
||||||
targetKey: 'supplyLineId',
|
targetKey: 'supplyLineId',
|
||||||
});
|
});
|
||||||
models.clockPresalesSupply.belongsTo(models.tradeItem, {
|
models.clockPresaleSupply.belongsTo(models.tradeItem, {
|
||||||
foreignKey: 'tradeItemId',
|
foreignKey: 'tradeItemId',
|
||||||
targetKey: 'tradeItemId',
|
targetKey: 'tradeItemId',
|
||||||
});
|
});
|
||||||
models.clockPresalesSupply.belongsTo(models.organization, {
|
models.clockPresaleSupply.belongsTo(models.organization, {
|
||||||
foreignKey: 'organizationId',
|
foreignKey: 'organizationId',
|
||||||
targetKey: 'organizationId',
|
targetKey: 'organizationId',
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const clockPresalesSupply = {
|
const clockPresaleSupply = {
|
||||||
supplyLineId: {
|
supplyLineId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -54,8 +54,8 @@ const clockPresalesSupply = {
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
return sequelize.define(
|
return sequelize.define(
|
||||||
'supplyLine_clockPresalesSupply',
|
'supplyLineClockPresaleSupply',
|
||||||
clockPresalesSupply, {
|
clockPresaleSupply, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
|
@ -75,12 +75,11 @@ const supplyLine = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const SupplyLine = sequelize.define(
|
return sequelize.define(
|
||||||
'supplyLine',
|
'supplyLine',
|
||||||
supplyLine, {
|
supplyLine, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return SupplyLine;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const volumePrices = {
|
const volumePrice = {
|
||||||
supplyLineId: {
|
supplyLineId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -16,12 +16,11 @@ const volumePrices = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const VolumePrices = sequelize.define(
|
return sequelize.define(
|
||||||
'supplyLine_volumePrices',
|
'supplyLineVolumePrice',
|
||||||
volumePrices, {
|
volumePrice, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return VolumePrices;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const botanicalNames = {
|
const botanicalName = {
|
||||||
botanicalNameId: {
|
botanicalNameId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -14,12 +14,11 @@ const botanicalNames = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const BotanicalNames = sequelize.define(
|
return sequelize.define(
|
||||||
'tradeItem_botanicalNames',
|
'tradeItemBotanicalName',
|
||||||
botanicalNames, {
|
botanicalName, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return BotanicalNames;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const characteristics = {
|
const characteristic = {
|
||||||
tradeItemId: {
|
tradeItemId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -15,13 +15,12 @@ const characteristics = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const Characteristics = sequelize.define(
|
return sequelize.define(
|
||||||
'tradeItem_characteristics',
|
'tradeItemCharacteristic',
|
||||||
characteristics,
|
characteristic,
|
||||||
{
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Characteristics;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const countryOfOriginIsoCodes = {
|
const countryOfOriginIsoCode = {
|
||||||
tradeItemId: {
|
tradeItemId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -12,13 +12,12 @@ const countryOfOriginIsoCodes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const CountryOfOriginIsoCodes = sequelize.define(
|
return sequelize.define(
|
||||||
'tradeItem_countryOfOriginIsoCodes',
|
'tradeItemCountryOfOriginIsoCodes',
|
||||||
countryOfOriginIsoCodes,
|
countryOfOriginIsoCode,
|
||||||
{
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return CountryOfOriginIsoCodes;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const PackageModel = {
|
const packageModel = {
|
||||||
packingConfigurationId: {
|
packingConfigurationId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -15,9 +15,12 @@ const PackageModel = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const Package = sequelize.define('tradeItem_packingConfigurations_package', PackageModel, {
|
return sequelize.define(
|
||||||
|
'tradeItemPackingConfigurationPackage',
|
||||||
|
packageModel,
|
||||||
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
});
|
}
|
||||||
return Package;
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const packingConfigurations = {
|
const packingConfiguration = {
|
||||||
packingConfigurationId: {
|
packingConfigurationId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -38,13 +38,12 @@ const packingConfigurations = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const PackingConfigurations = sequelize.define(
|
return sequelize.define(
|
||||||
'tradeItem_packingConfigurations',
|
'tradeItemPackingConfiguration',
|
||||||
packingConfigurations,
|
packingConfiguration,
|
||||||
{
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return PackingConfigurations;
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const photos = {
|
const photo = {
|
||||||
tradeItemId: {
|
tradeItemId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -18,9 +18,12 @@ const photos = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const Photos = sequelize.define('tradeItem_photos', photos, {
|
return sequelize.define(
|
||||||
|
'tradeItemPhoto',
|
||||||
|
photo,
|
||||||
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
});
|
}
|
||||||
return Photos;
|
);
|
||||||
};
|
};
|
|
@ -16,9 +16,12 @@ const seasonalPeriod = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const SeasonalPeriod = sequelize.define('tradeItem_seasonalPeriod', seasonalPeriod, {
|
return sequelize.define(
|
||||||
|
'tradeItemSeasonalPeriod',
|
||||||
|
seasonalPeriod,
|
||||||
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
});
|
}
|
||||||
return SeasonalPeriod;
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,9 +48,12 @@ const tradeItem = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const TradeItem = sequelize.define('tradeItem', tradeItem, {
|
return sequelize.define(
|
||||||
|
'tradeItem',
|
||||||
|
tradeItem,
|
||||||
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
});
|
}
|
||||||
return TradeItem;
|
);
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
const warehouses = {
|
const warehouse = {
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
|
@ -48,12 +48,11 @@ const warehouses = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (sequelize) => {
|
export default (sequelize) => {
|
||||||
const Warehouses = sequelize.define(
|
return sequelize.define(
|
||||||
'organization_warehouses',
|
'warehouse',
|
||||||
warehouses, {
|
warehouse, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Warehouses;
|
|
||||||
};
|
};
|
30
utils.js
30
utils.js
|
@ -16,7 +16,7 @@ const env = process.env;
|
||||||
export async function requestToken(isForce = false) {
|
export async function requestToken(isForce = false) {
|
||||||
let spinner = ora(`Requesting new token...`).start();
|
let spinner = ora(`Requesting new token...`).start();
|
||||||
try {
|
try {
|
||||||
const clientConfigData = await models.clientConfig.findOne();
|
const clientConfigData = await models.config.findOne();
|
||||||
|
|
||||||
let tokenExpiration, token;
|
let tokenExpiration, token;
|
||||||
if (clientConfigData) {
|
if (clientConfigData) {
|
||||||
|
@ -62,7 +62,7 @@ export async function requestToken(isForce = false) {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export async function getCurrentToken() {
|
export async function getCurrentToken() {
|
||||||
return (await models.clientConfig.findOne()).currentToken;
|
return (await models.config.findOne()).currentToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ export async function checkConfig() {
|
||||||
throw new Error(`You haven't provided the ${reqEnvVar} environment variable`);
|
throw new Error(`You haven't provided the ${reqEnvVar} environment variable`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const clientConfigData = await models.clientConfig.findOne();
|
const clientConfigData = await models.config.findOne();
|
||||||
if (!clientConfigData)
|
if (!clientConfigData)
|
||||||
await updateClientConfig(env.CLIENT_ID, env.CLIENT_SECRET);
|
await updateClientConfig(env.CLIENT_ID, env.CLIENT_SECRET);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ export async function checkConfig() {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export async function getCurrentTokenExpiration() {
|
export async function getCurrentTokenExpiration() {
|
||||||
return (await models.clientConfig.findOne()).tokenExpiration;
|
return (await models.config.findOne()).tokenExpiration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,7 +105,7 @@ export async function getCurrentTokenExpiration() {
|
||||||
export async function updateClientConfig(clientConfig) {
|
export async function updateClientConfig(clientConfig) {
|
||||||
try {
|
try {
|
||||||
if (!JSON.parse(process.env.USE_SECRETS_DB)) clientId = clientSecret = null
|
if (!JSON.parse(process.env.USE_SECRETS_DB)) clientId = clientSecret = null
|
||||||
await models.clientConfig.upsert({
|
await models.config.upsert({
|
||||||
id: 1,
|
id: 1,
|
||||||
...clientConfig,
|
...clientConfig,
|
||||||
});
|
});
|
||||||
|
@ -267,7 +267,7 @@ export async function syncSupplyLines() {
|
||||||
|
|
||||||
for (let supplyLine of supplyLines) {
|
for (let supplyLine of supplyLines) {
|
||||||
// Check if the warehouse exists, and if it doesn't, create it
|
// Check if the warehouse exists, and if it doesn't, create it
|
||||||
let warehouse = await models.warehouses.findOne({
|
let warehouse = await models.warehouse.findOne({
|
||||||
where: { warehouseId: supplyLine.warehouseId }
|
where: { warehouseId: supplyLine.warehouseId }
|
||||||
});
|
});
|
||||||
if (!warehouse) {
|
if (!warehouse) {
|
||||||
|
@ -310,7 +310,7 @@ export async function syncSupplyLines() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let volumePrice of supplyLine.volumePrices)
|
for (let volumePrice of supplyLine.volumePrices)
|
||||||
await models.volumePrices.upsert({
|
await models.volumePrice.upsert({
|
||||||
supplyLineId: supplyLine.supplyLineId,
|
supplyLineId: supplyLine.supplyLineId,
|
||||||
...volumePrice,
|
...volumePrice,
|
||||||
});
|
});
|
||||||
|
@ -471,16 +471,16 @@ export async function insertItem(tradeItem) {
|
||||||
/**
|
/**
|
||||||
* Insert clock presales supply in the database.
|
* Insert clock presales supply in the database.
|
||||||
*
|
*
|
||||||
* @param {Array} clockPresalesSupply
|
* @param {Array} clockPresaleSupply
|
||||||
*/
|
*/
|
||||||
export async function insertClockPresalesSupply(clockPresalesSupply) {
|
export async function insertClockPresalesSupply(clockPresaleSupply) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
await models.clockPresalesSupply.upsert({
|
await models.clockPresaleSupply.upsert({
|
||||||
...clockPresalesSupply,
|
...clockPresaleSupply,
|
||||||
pricePerPiece_currency: clockPresalesSupply.pricePerPiece.currency,
|
pricePerPiece_currency: clockPresaleSupply.pricePerPiece.currency,
|
||||||
pricePerPiece_value: clockPresalesSupply.pricePerPiece.value,
|
pricePerPiece_value: clockPresaleSupply.pricePerPiece.value,
|
||||||
organizationId: clockPresalesSupply.supplierOrganizationId,
|
organizationId: clockPresaleSupply.supplierOrganizationId,
|
||||||
});
|
});
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -497,7 +497,7 @@ export async function insertClockPresalesSupply(clockPresalesSupply) {
|
||||||
export async function insertWarehouse(warehouse) {
|
export async function insertWarehouse(warehouse) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
await models.warehouses.upsert({
|
await models.warehouse.upsert({
|
||||||
...warehouse,
|
...warehouse,
|
||||||
location_gln: warehouse.location.gln,
|
location_gln: warehouse.location.gln,
|
||||||
location_address_addressLine: warehouse.location.address.addressLine,
|
location_address_addressLine: warehouse.location.address.addressLine,
|
||||||
|
|
Loading…
Reference in New Issue