@obisey/nest 0.1.26 → 0.1.28
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 +21 -22
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@ function BaseService(modelo) {
|
|
|
53
53
|
// }
|
|
54
54
|
let nkey = `${key.universo ? key.universo : 'pro'}:${key.IdEmpresa}:${key.fragmentos[0].nombre}:${id}`;
|
|
55
55
|
const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({ ...key }), (cache) => {
|
|
56
|
-
return Promise.resolve(
|
|
56
|
+
return Promise.resolve(repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](JSON.parse(cache)));
|
|
57
57
|
}, //Revisar
|
|
58
58
|
(resultado) => {
|
|
59
59
|
return Promise.resolve(resultado
|
|
@@ -134,7 +134,8 @@ function BaseService(modelo) {
|
|
|
134
134
|
cached: parsed,
|
|
135
135
|
modelName: (0, lodash_1.capitalize)(modelo),
|
|
136
136
|
});
|
|
137
|
-
const
|
|
137
|
+
const ModelClass = repository.sequelize.models[(0, lodash_1.capitalize)(modelo)];
|
|
138
|
+
const instance = ModelClass.build(parsed, { raw: false, isNewRecord: false });
|
|
138
139
|
console.log(`[OBISEY-NEST DESERIALIZED] ${modelo}:`, {
|
|
139
140
|
id: instance.id,
|
|
140
141
|
hasId: 'id' in instance,
|
|
@@ -158,6 +159,18 @@ function BaseService(modelo) {
|
|
|
158
159
|
hasDataValues: !!result[0].dataValues,
|
|
159
160
|
});
|
|
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) => {
|
|
165
|
+
const id = (0, getModelId_1.getModelId)(item);
|
|
166
|
+
const plainData = item.get({ plain: true });
|
|
167
|
+
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData));
|
|
168
|
+
});
|
|
169
|
+
Promise.all(savePromises).then(() => {
|
|
170
|
+
console.log(`[PEDIR-ITEMS-SAVED] ${modelo}: all items saved`);
|
|
171
|
+
}).catch(err => {
|
|
172
|
+
console.log(`[PEDIR-SAVE-ERROR] ${modelo}:`, err);
|
|
173
|
+
});
|
|
161
174
|
resolve(result);
|
|
162
175
|
});
|
|
163
176
|
}), //Pedir
|
|
@@ -195,27 +208,13 @@ function BaseService(modelo) {
|
|
|
195
208
|
}
|
|
196
209
|
}), //observar
|
|
197
210
|
(__, 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));
|
|
211
|
+
console.log(`[ACTUALIZAR-START] ${modelo}: saving IDs to Redis`);
|
|
212
|
+
const idsToSave = resultado.map((n) => {
|
|
213
|
+
// resultado is already transformed to plain JSON
|
|
214
|
+
return n.id || n;
|
|
218
215
|
});
|
|
216
|
+
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
217
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
|
|
219
218
|
});
|
|
220
219
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
221
220
|
// if (isDev)
|