@obisey/nest 0.1.32 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -412,11 +412,7 @@ function BaseResolver(modelo) {
|
|
|
412
412
|
{ nombre: modelo, id: item.id },
|
|
413
413
|
{ nombre: planeta },
|
|
414
414
|
],
|
|
415
|
-
}), (cache) =>
|
|
416
|
-
const parsed = JSON.parse(cache);
|
|
417
|
-
const instance = Clase.build(parsed, { raw: false, isNewRecord: false });
|
|
418
|
-
return Promise.resolve(Object.assign(instance, parsed));
|
|
419
|
-
}, //Revisar
|
|
415
|
+
}), (cache) => Promise.resolve(new Clase(JSON.parse(cache))), //Revisar
|
|
420
416
|
(resultado) => Promise.resolve(resultado ? resultado.get({ plain: true }) : null), //transformar
|
|
421
417
|
() => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
|
|
422
418
|
() => new Promise(async (resolve) => {
|
|
@@ -484,8 +480,7 @@ function BaseResolver(modelo) {
|
|
|
484
480
|
],
|
|
485
481
|
}), (cache) => Promise.resolve(cache.map((n) => {
|
|
486
482
|
const parsed = JSON.parse(n);
|
|
487
|
-
|
|
488
|
-
return Object.assign(instance, parsed);
|
|
483
|
+
return Clase.build(parsed, { raw: false, isNewRecord: false });
|
|
489
484
|
})), //Revisar
|
|
490
485
|
(resultado) => Promise.resolve(resultado.map((n) => n.get({ plain: true }))), //transformar
|
|
491
486
|
() => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
|
|
@@ -496,7 +491,7 @@ function BaseResolver(modelo) {
|
|
|
496
491
|
let ids = await this.redis.hGet(nkey, planeta);
|
|
497
492
|
if (ids) {
|
|
498
493
|
Promise.all(JSON.parse(ids).map((id) => this.redis.hExists(pkey(id), 'item'))).then((exists) => {
|
|
499
|
-
if (!exists.includes(
|
|
494
|
+
if (!exists.includes(0)) {
|
|
500
495
|
Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
|
|
501
496
|
}
|
|
502
497
|
else
|
|
@@ -10,7 +10,6 @@ const cifrado_1 = require("./utils/cifrado");
|
|
|
10
10
|
const keyInterface_1 = require("./utils/keyInterface");
|
|
11
11
|
exports.redis_on = true;
|
|
12
12
|
const paginar_1 = require("./utils/paginar");
|
|
13
|
-
const getModelId_1 = require("./utils/getModelId");
|
|
14
13
|
var isDev = false;
|
|
15
14
|
var stringifWhere = (where) => (0, lodash_1.isObject)(where)
|
|
16
15
|
? JSON.stringify(Object.entries(where).reduce((ac, [a, v]) => {
|
|
@@ -153,38 +152,7 @@ function BaseService(modelo) {
|
|
|
153
152
|
() => new Promise((resolve) => {
|
|
154
153
|
repository.findAll(value).then(result => {
|
|
155
154
|
console.log(`[PEDIR-DB] ${modelo}: found ${result.length} items from DB`);
|
|
156
|
-
|
|
157
|
-
console.log(`[PEDIR-FIRST-ITEM] ${modelo}:`, {
|
|
158
|
-
id: result[0].id,
|
|
159
|
-
hasDataValues: !!result[0].dataValues,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
// SAVE ITEMS HERE (before transform)
|
|
163
|
-
console.log(`[PEDIR-SAVING-ITEMS] ${modelo}: saving ${result.length} items to Redis`);
|
|
164
|
-
const savePromises = result.map((item, idx) => {
|
|
165
|
-
const id = (0, getModelId_1.getModelId)(item);
|
|
166
|
-
const plainData = item.get({ plain: true });
|
|
167
|
-
console.log(`[PEDIR-ITEM-${idx}] ${modelo}: id=${id}, saving to pkey=${pkey(id).substring(0, 50)}`);
|
|
168
|
-
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData))
|
|
169
|
-
.then(res => {
|
|
170
|
-
console.log(`[PEDIR-ITEM-${idx}-SAVED] ${modelo}: id=${id}, result=${res}`);
|
|
171
|
-
return res;
|
|
172
|
-
})
|
|
173
|
-
.catch(err => {
|
|
174
|
-
console.log(`[PEDIR-ITEM-${idx}-ERROR] ${modelo}: id=${id}, error=${err.message}`);
|
|
175
|
-
throw err;
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
Promise.all(savePromises)
|
|
179
|
-
.then(() => {
|
|
180
|
-
console.log(`[PEDIR-ITEMS-SAVED] ${modelo}: all ${result.length} items saved successfully`);
|
|
181
|
-
console.log(`[PEDIR-BEFORE-RESOLVE] ${modelo}: about to resolve with ${result.length} items`);
|
|
182
|
-
resolve(result);
|
|
183
|
-
})
|
|
184
|
-
.catch(err => {
|
|
185
|
-
console.log(`[PEDIR-SAVE-ERROR] ${modelo}: error=${err.message}, but resolving anyway with ${result.length} items`);
|
|
186
|
-
resolve(result);
|
|
187
|
-
});
|
|
155
|
+
resolve(result);
|
|
188
156
|
});
|
|
189
157
|
}), //Pedir
|
|
190
158
|
() => new Promise(async (resolve) => {
|
|
@@ -233,22 +201,8 @@ function BaseService(modelo) {
|
|
|
233
201
|
}
|
|
234
202
|
}), //observar
|
|
235
203
|
(__, resultado) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// resultado is already transformed to plain JSON
|
|
239
|
-
return n.id || n;
|
|
240
|
-
});
|
|
241
|
-
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}], count=${idsToSave.length}`);
|
|
242
|
-
console.log(`[ACTUALIZAR-BEFORE-HSET] ${modelo}: about to hSet(${nkey.substring(0, 40)}, ${peticion.substring(0, 20)}, [IDs])`);
|
|
243
|
-
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave))
|
|
244
|
-
.then(res => {
|
|
245
|
-
console.log(`[ACTUALIZAR-HSET-SUCCESS] ${modelo}: result=${res}`);
|
|
246
|
-
return res;
|
|
247
|
-
})
|
|
248
|
-
.catch(err => {
|
|
249
|
-
console.log(`[ACTUALIZAR-HSET-ERROR] ${modelo}: error=${err.message}`);
|
|
250
|
-
throw err;
|
|
251
|
-
});
|
|
204
|
+
// LEGACY PATTERN: Save individual items FIRST, then save IDs
|
|
205
|
+
return Promise.all(resultado.map((n) => this.redis.hSet(pkey(n.id || n), 'item', JSON.stringify(n)))).then(() => this.redis.hSet(nkey, peticion, JSON.stringify(resultado.map((n) => n.id || n))));
|
|
252
206
|
});
|
|
253
207
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
254
208
|
// if (isDev)
|