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

View File

@ -41,6 +41,9 @@ const packingConfiguration = {
isPrimary: {
type: Sequelize.BOOLEAN,
},
supplyLineId: {
type: Sequelize.STRING,
},
};
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
DECLARE vLanded DATETIME;
DECLARE vLastInserted DATETIME;

View File

@ -1,5 +1,7 @@
CREATE OR REPLACE VIEW supplyOffer AS
SELECT sl.supplyLineId,
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW supplyOffer
AS SELECT sl.supplyLineId,
ti.name tradeItemName,
i.product_name vbnProductName,
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}` : ''}`));
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;
}
@ -741,8 +741,11 @@ export async function vnRequest(method, url, data, headers) {
} catch (err) {
switch (err.code) {
case 'ECONNRESET': // Client network socket TLS
await warnSpin(null, err);
await sleep(1000);
break;
case 'EAI_AGAIN': // getaddrinfo || Lost connection
await warnSpin(null, err, false);
await warnSpin(null, err);
await sleep(env.MS_RETRY_LOST_CONNECTION);
break;
case 'ECONNABORTED':
@ -753,28 +756,28 @@ export async function vnRequest(method, url, data, headers) {
return err;
case 504:
case 502:
await warnSpin(null, err, false);
await warnSpin(null, err,);
await sleep(1000);
break;
case 429: // Too Many Requests
await warnSpin(null, err, false);
await warnSpin(null, err);
await sleep(60000);
break;
case 401: // Unauthorized
await warnSpin(null, err, false);
await warnSpin(null, err);
await checkToken(true);
headers.Authorization
? headers.Authorization = `Bearer ${await getCurrentToken()}`
: handler('critical', err);
break;
default:
await warnSpin(null, err, false);
await warnSpin(null, err);
await sleep(env.MS_RETRY_UNHANDLED_ERROR);
break;
}
break;
default:
await warnSpin(null, err, false);
await warnSpin(null, err);
await sleep(env.MS_RETRY_UNHANDLED_ERROR);
break;
}
@ -840,15 +843,14 @@ export async function okSpin(msg) {
*
* @param {String} msg Text of spinner
* @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)
msg = `${chalk.gray(`[${new moment().format('YYYY-MM-DD hh:mm:ss A')}]`)} ${msg}`;
if (spinner) {
spinner.warn(msg);
if (clear) spinner = null;
spinner = null;
}
if (err) await handler('warning', err);
};