feat: refs #7882 Added model and method #2879

Merged
guillermo merged 9 commits from 7882-quadMinds into master 2024-09-18 05:16:46 +00:00
4 changed files with 28 additions and 7 deletions
Showing only changes of commit b40ecf9e19 - Show all commits

View File

@ -25,14 +25,22 @@ module.exports = Self => {
const config = await Self.app.models.QuadmindsApiConfig.findOne();
if (!config) throw new UserError('Config params not set');
const pois = await axios.get(`${config.url}pois/search?limit=10000&offset=0`, {
if (tickets.length > config.maxObjects)
throw new UserError(`Quadminds does not support more than ${config.maxObjects} tickets`);
let poisData = [];
let isOk;
for (let offset = 0; !isOk; offset = offset + config.limit) {
const pois = await axios.get(`${config.url}pois/search?limit=${config.limit}&offset=${offset}`, {
headers: {
'Accept': 'application/json',
'X-Saas-Apikey': config.key
}
});
pois.data.data.length ? poisData.push(...pois.data.data) : isOk = true;
}
const poiMap = new Map(pois.data.data.map(poi => [poi.code, poi._id]));
const poiMap = new Map(poisData.map(poi => [poi.code, poi._id]));
let orders = await Self.rawSql(`
SELECT a.id poiCode,

View File

@ -24,6 +24,9 @@ module.exports = Self => {
const config = await Self.app.models.QuadmindsApiConfig.findOne();
if (!config) throw new UserError('Config params not set');
if (tickets.length > config.maxObjects)
throw new UserError(`Quadminds does not support more than ${config.maxObjects} tickets`);
let pois = await Self.rawSql(`
WITH deliveryNotes AS (
SELECT t.id, t.routeFk, tn.description

View File

@ -17,6 +17,12 @@
},
"key": {
"type": "string"
},
"maxObjects": {
"type": "number"
},
"limit": {
"type": "number"
}
}
}

View File

@ -1 +1,5 @@
RENAME TABLE vn.quadMindsApiConfig TO vn.quadmindsApiConfig;
ALTER TABLE vn.quadmindsApiConfig
ADD maxObjects INT NULL COMMENT 'Número máximo de objetos en el array por petición',
ADD `limit` INT NULL COMMENT 'Limite de objetos solicitados por petición';