feat: refs #7882 Improved sendOrders and added more config params
This commit is contained in:
parent
8165830934
commit
b40ecf9e19
|
@ -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`, {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-Saas-Apikey': config.key
|
||||
}
|
||||
});
|
||||
if (tickets.length > config.maxObjects)
|
||||
throw new UserError(`Quadminds does not support more than ${config.maxObjects} tickets`);
|
||||
|
||||
const poiMap = new Map(pois.data.data.map(poi => [poi.code, poi._id]));
|
||||
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(poisData.map(poi => [poi.code, poi._id]));
|
||||
|
||||
let orders = await Self.rawSql(`
|
||||
SELECT a.id poiCode,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
},
|
||||
"key": {
|
||||
"type": "string"
|
||||
},
|
||||
"maxObjects": {
|
||||
"type": "number"
|
||||
},
|
||||
"limit": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue