@obisey/nest 0.1.24 → 0.1.26
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 +1 -1
- package/prototipos/baseService.js +39 -4
package/package.json
CHANGED
|
@@ -141,10 +141,27 @@ function BaseService(modelo) {
|
|
|
141
141
|
});
|
|
142
142
|
return instance;
|
|
143
143
|
})), //Revisar
|
|
144
|
-
(resultado) =>
|
|
144
|
+
(resultado) => {
|
|
145
|
+
console.log(`[TRANSFORMAR] ${modelo}: transforming ${resultado.length} items`);
|
|
146
|
+
const plain = resultado.map((n) => n.get({ plain: true }));
|
|
147
|
+
if (plain.length > 0) {
|
|
148
|
+
console.log(`[TRANSFORMAR-FIRST] ${modelo}:`, plain[0]);
|
|
149
|
+
}
|
|
150
|
+
return Promise.resolve(plain);
|
|
151
|
+
}, //transformar
|
|
145
152
|
() => new Promise((resolve) => {
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
repository.findAll(value).then(result => {
|
|
154
|
+
console.log(`[PEDIR-DB] ${modelo}: found ${result.length} items from DB`);
|
|
155
|
+
if (result.length > 0) {
|
|
156
|
+
console.log(`[PEDIR-FIRST-ITEM] ${modelo}:`, {
|
|
157
|
+
id: result[0].id,
|
|
158
|
+
hasDataValues: !!result[0].dataValues,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
resolve(result);
|
|
162
|
+
});
|
|
163
|
+
}), //Pedir
|
|
164
|
+
() => new Promise(async (resolve) => {
|
|
148
165
|
console.log(`[OBSERVAR-START] ${modelo}: checking Redis for nkey=${nkey.substring(0, 50)}`);
|
|
149
166
|
let e = await this.redis.hExists(nkey, peticion);
|
|
150
167
|
console.log(`[OBSERVAR-EXISTS] ${modelo}: exists=${e}`);
|
|
@@ -157,6 +174,7 @@ function BaseService(modelo) {
|
|
|
157
174
|
console.log(`[OBSERVAR-ALL-EXIST] ${modelo}: all items exist, fetching from Redis`);
|
|
158
175
|
Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(items => {
|
|
159
176
|
console.log(`[OBSERVAR-RESOLVE-ITEMS] ${modelo}: resolving ${items.length} items from Redis`);
|
|
177
|
+
console.log(`[OBSERVAR-ITEMS-CONTENT] ${modelo}: [0]=${items[0] ? items[0].substring(0, 80) : 'NULL'}`);
|
|
160
178
|
resolve(items);
|
|
161
179
|
});
|
|
162
180
|
}
|
|
@@ -178,9 +196,26 @@ function BaseService(modelo) {
|
|
|
178
196
|
}), //observar
|
|
179
197
|
(__, resultado) => {
|
|
180
198
|
console.log(`[ACTUALIZAR-START] ${modelo}: saving ${resultado.length} items to Redis`);
|
|
199
|
+
if (resultado.length > 0) {
|
|
200
|
+
console.log(`[ACTUALIZAR-FIRST-ITEM] ${modelo}: resultado[0]=`, {
|
|
201
|
+
id: resultado[0].id,
|
|
202
|
+
plainObj: resultado[0].get({ plain: true }),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
181
205
|
const idsToSave = resultado.map((n) => (0, getModelId_1.getModelId)(n));
|
|
182
206
|
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
183
|
-
|
|
207
|
+
// SAVE INDIVIDUAL ITEMS
|
|
208
|
+
console.log(`[ACTUALIZAR-SAVING-ITEMS] ${modelo}: about to save ${resultado.length} items`);
|
|
209
|
+
const promises = resultado.map((item, idx) => {
|
|
210
|
+
const id = (0, getModelId_1.getModelId)(item);
|
|
211
|
+
const plainData = item.get({ plain: true });
|
|
212
|
+
console.log(`[ACTUALIZAR-ITEM-${id}] ${modelo}: saving to pkey=${pkey(id).substring(0, 40)}`);
|
|
213
|
+
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData));
|
|
214
|
+
});
|
|
215
|
+
return Promise.all(promises).then(() => {
|
|
216
|
+
console.log(`[ACTUALIZAR-ALL-SAVED] ${modelo}: items saved, saving IDs`);
|
|
217
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
|
|
218
|
+
});
|
|
184
219
|
});
|
|
185
220
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
186
221
|
// if (isDev)
|