@obisey/nest 0.1.25 → 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 -17
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,24 +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
|
-
const promises = resultado.map((item) => {
|
|
209
|
-
const id = (0, getModelId_1.getModelId)(item);
|
|
210
|
-
const plainData = item.get({ plain: true });
|
|
211
|
-
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData));
|
|
212
|
-
});
|
|
213
|
-
return Promise.all(promises).then(() => {
|
|
214
|
-
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;
|
|
215
214
|
});
|
|
215
|
+
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
216
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
|
|
216
217
|
});
|
|
217
218
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
218
219
|
// if (isDev)
|