feat: refs #7882 Improved sendOrders and added more config params
gitea/salix/pipeline/pr-dev This commit looks good Details
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-09-02 11:48:32 +02:00
parent 8165830934
commit b40ecf9e19
4 changed files with 28 additions and 7 deletions

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';