@obisey/nest 0.1.23 → 0.1.24

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obisey/nest",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "NestJS utilities and base classes by Obisey",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -145,26 +145,42 @@ function BaseService(modelo) {
145
145
  () => new Promise((resolve) => {
146
146
  resolve(repository.findAll(value)); //Pedir
147
147
  }), () => new Promise(async (resolve) => {
148
+ console.log(`[OBSERVAR-START] ${modelo}: checking Redis for nkey=${nkey.substring(0, 50)}`);
148
149
  let e = await this.redis.hExists(nkey, peticion);
150
+ console.log(`[OBSERVAR-EXISTS] ${modelo}: exists=${e}`);
149
151
  if (e) {
150
152
  let ids = await this.redis.hGet(nkey, peticion);
153
+ console.log(`[OBSERVAR-IDS] ${modelo}: ids from Redis = ${ids ? ids.substring(0, 60) : 'undefined'}`);
151
154
  if (ids) {
152
155
  Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hExists(pkey(id), 'item'))).then((exists) => {
153
156
  if (!exists.includes(0)) {
154
- Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
157
+ console.log(`[OBSERVAR-ALL-EXIST] ${modelo}: all items exist, fetching from Redis`);
158
+ Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(items => {
159
+ console.log(`[OBSERVAR-RESOLVE-ITEMS] ${modelo}: resolving ${items.length} items from Redis`);
160
+ resolve(items);
161
+ });
155
162
  }
156
- else
163
+ else {
164
+ console.log(`[OBSERVAR-INCOMPLETE] ${modelo}: some items missing in Redis, fallback to DB`);
157
165
  resolve(undefined);
166
+ }
158
167
  });
159
168
  }
160
- else
169
+ else {
170
+ console.log(`[OBSERVAR-NO-IDS] ${modelo}: no IDs in Redis, fallback to DB`);
161
171
  resolve(undefined);
172
+ }
162
173
  }
163
- else
174
+ else {
175
+ console.log(`[OBSERVAR-NOT-EXISTS] ${modelo}: nkey not in Redis, fallback to DB`);
164
176
  resolve(undefined);
177
+ }
165
178
  }), //observar
166
179
  (__, resultado) => {
167
- return this.redis.hSet(nkey, peticion, JSON.stringify(resultado.map((n) => (0, getModelId_1.getModelId)(n))));
180
+ console.log(`[ACTUALIZAR-START] ${modelo}: saving ${resultado.length} items to Redis`);
181
+ const idsToSave = resultado.map((n) => (0, getModelId_1.getModelId)(n));
182
+ console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
183
+ return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
168
184
  });
169
185
  await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
170
186
  // if (isDev)