refs #4823 Minor changes

This commit is contained in:
Guillermo Bonet 2023-06-21 11:16:47 +02:00
parent fe0489bccd
commit aab13f1294
5 changed files with 23 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import { Sequelize } from 'sequelize'; import { Sequelize } from 'sequelize';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import chalk from 'chalk'; import chalk from 'chalk';
import fs from 'fs';
import * as utils from '../utils.js'; import * as utils from '../utils.js';
dotenv.config(); dotenv.config();
@ -170,13 +171,12 @@ try {
await utils.startSpin(`${actionMsg} models...`); await utils.startSpin(`${actionMsg} models...`);
await sequelize.sync(action); await sequelize.sync(action);
/*
// Create views // Create views
sequelize.query(fs.readFileSync('routines/views/supplyOffer.sql', 'utf-8')); sequelize.query(fs.readFileSync('routines/views/supplyOffer.sql', 'utf-8'));
// Create procedures // Create procedures
sequelize.query(fs.readFileSync('routines/procedures/offerRefresh.sql', 'utf-8')); sequelize.query(fs.readFileSync('routines/procedures/offerRefresh.sql', 'utf-8'));
*/
await utils.okSpin(); await utils.okSpin();
} }
catch (err) { catch (err) {

View File

@ -41,6 +41,9 @@ const packingConfiguration = {
isPrimary: { isPrimary: {
type: Sequelize.BOOLEAN, type: Sequelize.BOOLEAN,
}, },
supplyLineId: {
type: Sequelize.STRING,
},
}; };
export default (sequelize) => { export default (sequelize) => {

View File

@ -1,4 +1,5 @@
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `floriday`.`offerRefresh`() CREATE OR REPLACE DEFINER=`root`@`localhost`
PROCEDURE `floriday`.`offerRefresh`()
BEGIN BEGIN
DECLARE vLanded DATETIME; DECLARE vLanded DATETIME;
DECLARE vLastInserted DATETIME; DECLARE vLastInserted DATETIME;

View File

@ -1,5 +1,7 @@
CREATE OR REPLACE VIEW supplyOffer AS CREATE OR REPLACE DEFINER=`root`@`localhost`
SELECT sl.supplyLineId, SQL SECURITY DEFINER
VIEW supplyOffer
AS SELECT sl.supplyLineId,
ti.name tradeItemName, ti.name tradeItemName,
i.product_name vbnProductName, i.product_name vbnProductName,
o.commercialName organizationName, o.commercialName organizationName,

View File

@ -157,7 +157,7 @@ export async function syncModel(model) {
const res = (await vnRequest('GET', `${env.API_URL}${methods[model].sync.url}${curSeqNum}${params ? `?${params}` : ''}`)); const res = (await vnRequest('GET', `${env.API_URL}${methods[model].sync.url}${curSeqNum}${params ? `?${params}` : ''}`));
if (res?.response?.status == 403 && res?.response?.data?.title === 'There are no connected suppliers.') { // Forbidden if (res?.response?.status == 403 && res?.response?.data?.title === 'There are no connected suppliers.') { // Forbidden
await await warnSpin(`Syncing ${model}...`, new Error(res.response.data.title), true); await await warnSpin(`Syncing ${model}...`, new Error(res.response.data.title));
return; return;
} }
@ -741,8 +741,11 @@ export async function vnRequest(method, url, data, headers) {
} catch (err) { } catch (err) {
switch (err.code) { switch (err.code) {
case 'ECONNRESET': // Client network socket TLS case 'ECONNRESET': // Client network socket TLS
await warnSpin(null, err);
await sleep(1000);
break;
case 'EAI_AGAIN': // getaddrinfo || Lost connection case 'EAI_AGAIN': // getaddrinfo || Lost connection
await warnSpin(null, err, false); await warnSpin(null, err);
await sleep(env.MS_RETRY_LOST_CONNECTION); await sleep(env.MS_RETRY_LOST_CONNECTION);
break; break;
case 'ECONNABORTED': case 'ECONNABORTED':
@ -753,28 +756,28 @@ export async function vnRequest(method, url, data, headers) {
return err; return err;
case 504: case 504:
case 502: case 502:
await warnSpin(null, err, false); await warnSpin(null, err,);
await sleep(1000); await sleep(1000);
break; break;
case 429: // Too Many Requests case 429: // Too Many Requests
await warnSpin(null, err, false); await warnSpin(null, err);
await sleep(60000); await sleep(60000);
break; break;
case 401: // Unauthorized case 401: // Unauthorized
await warnSpin(null, err, false); await warnSpin(null, err);
await checkToken(true); await checkToken(true);
headers.Authorization headers.Authorization
? headers.Authorization = `Bearer ${await getCurrentToken()}` ? headers.Authorization = `Bearer ${await getCurrentToken()}`
: handler('critical', err); : handler('critical', err);
break; break;
default: default:
await warnSpin(null, err, false); await warnSpin(null, err);
await sleep(env.MS_RETRY_UNHANDLED_ERROR); await sleep(env.MS_RETRY_UNHANDLED_ERROR);
break; break;
} }
break; break;
default: default:
await warnSpin(null, err, false); await warnSpin(null, err);
await sleep(env.MS_RETRY_UNHANDLED_ERROR); await sleep(env.MS_RETRY_UNHANDLED_ERROR);
break; break;
} }
@ -840,15 +843,14 @@ export async function okSpin(msg) {
* *
* @param {String} msg Text of spinner * @param {String} msg Text of spinner
* @param {Error} err Error object * @param {Error} err Error object
* @param {Boolean} clear Clean the instance
**/ **/
export async function warnSpin(msg, err, clear) { export async function warnSpin(msg, err) {
if (JSON.parse(env.TIME_STAMPS) && msg) if (JSON.parse(env.TIME_STAMPS) && msg)
msg = `${chalk.gray(`[${new moment().format('YYYY-MM-DD hh:mm:ss A')}]`)} ${msg}`; msg = `${chalk.gray(`[${new moment().format('YYYY-MM-DD hh:mm:ss A')}]`)} ${msg}`;
if (spinner) { if (spinner) {
spinner.warn(msg); spinner.warn(msg);
if (clear) spinner = null; spinner = null;
} }
if (err) await handler('warning', err); if (err) await handler('warning', err);
}; };