@obisey/nest 0.1.26 → 0.1.27
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 +18 -20
package/package.json
CHANGED
|
@@ -158,6 +158,18 @@ function BaseService(modelo) {
|
|
|
158
158
|
hasDataValues: !!result[0].dataValues,
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
+
// SAVE ITEMS HERE (before transform)
|
|
162
|
+
console.log(`[PEDIR-SAVING-ITEMS] ${modelo}: saving ${result.length} items to Redis`);
|
|
163
|
+
const savePromises = result.map((item) => {
|
|
164
|
+
const id = (0, getModelId_1.getModelId)(item);
|
|
165
|
+
const plainData = item.get({ plain: true });
|
|
166
|
+
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData));
|
|
167
|
+
});
|
|
168
|
+
Promise.all(savePromises).then(() => {
|
|
169
|
+
console.log(`[PEDIR-ITEMS-SAVED] ${modelo}: all items saved`);
|
|
170
|
+
}).catch(err => {
|
|
171
|
+
console.log(`[PEDIR-SAVE-ERROR] ${modelo}:`, err);
|
|
172
|
+
});
|
|
161
173
|
resolve(result);
|
|
162
174
|
});
|
|
163
175
|
}), //Pedir
|
|
@@ -195,27 +207,13 @@ function BaseService(modelo) {
|
|
|
195
207
|
}
|
|
196
208
|
}), //observar
|
|
197
209
|
(__, resultado) => {
|
|
198
|
-
console.log(`[ACTUALIZAR-START] ${modelo}: saving
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
plainObj: resultado[0].get({ plain: true }),
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
const idsToSave = resultado.map((n) => (0, getModelId_1.getModelId)(n));
|
|
206
|
-
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
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));
|
|
210
|
+
console.log(`[ACTUALIZAR-START] ${modelo}: saving IDs to Redis`);
|
|
211
|
+
const idsToSave = resultado.map((n) => {
|
|
212
|
+
// resultado is already transformed to plain JSON
|
|
213
|
+
return n.id || n;
|
|
218
214
|
});
|
|
215
|
+
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
216
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
|
|
219
217
|
});
|
|
220
218
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
221
219
|
// if (isDev)
|