@obisey/nest 0.1.0

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.
@@ -0,0 +1,597 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.BaseResolver = BaseResolver;
37
+ const lodash_1 = require("lodash");
38
+ const keyInterface_1 = require("./utils/keyInterface");
39
+ const formarwhere_1 = require("./utils/formarwhere");
40
+ const chalk = require('chalk');
41
+ const log = console.log;
42
+ var imprimir = (texto) => {
43
+ log(chalk.green(texto));
44
+ };
45
+ var tiempo = 86400000;
46
+ var isDev = false;
47
+ const redisStore_1 = require("../redisStore");
48
+ const cachear_1 = require("./utils/cachear");
49
+ const paginar_1 = require("./utils/paginar");
50
+ const _ = __importStar(require("lodash"));
51
+ function BaseResolver(modelo) {
52
+ return class BaseResolver {
53
+ constructor(cacheManager, receptor = null) {
54
+ this.cacheManager = cacheManager;
55
+ this.receptor = receptor;
56
+ }
57
+ belongsTo(universo, planeta, IdEmpresa, pagina = null) {
58
+ // 1
59
+ return {
60
+ resolvefield: async (item, where, cacheable, Clase) => this.uno({
61
+ universo,
62
+ IdEmpresa,
63
+ planeta,
64
+ item,
65
+ cacheable,
66
+ where,
67
+ Clase,
68
+ tipo: 'resolverfield',
69
+ relacion: 'belongsTo',
70
+ }, pagina),
71
+ query: async (servicio, IdModelo, Clase) => {
72
+ imprimir(`${modelo} ${IdModelo} belongsTo query ${planeta}`);
73
+ return servicio
74
+ .findByPk(IdModelo, pagina)
75
+ .then((item) => item.$get(planeta));
76
+ },
77
+ ligar: async (servicio, alias, objeto, peticion, borrarSSR = false) => {
78
+ console.log({ alias, modelo, planeta, peticion });
79
+ return this.eliminarCache([
80
+ `${modelo}:${peticion.where.id}`,
81
+ `${alias}:${objeto[`Id${(0, lodash_1.capitalize)(alias)}`]}`,
82
+ ], borrarSSR) // El único diferente
83
+ .then(() => servicio.update({ id: peticion.where.id, ...objeto }, peticion))
84
+ .then(() => true);
85
+ },
86
+ desligar: async (servicio, alias, IdModelo, IdPlaneta, borrarSSR = false) => this.desligar({
87
+ universo,
88
+ servicio,
89
+ alias,
90
+ IdModelo,
91
+ IdPlaneta,
92
+ tipo: 'belongsTo',
93
+ planeta,
94
+ borrarSSR,
95
+ }),
96
+ };
97
+ }
98
+ hasOne(universo, planeta, IdEmpresa, pagina = null) {
99
+ // 3
100
+ return {
101
+ resolvefield: async (item, where, cacheable, Clase) => {
102
+ console.log('hasOne');
103
+ return this.uno({
104
+ universo,
105
+ IdEmpresa,
106
+ planeta,
107
+ item,
108
+ cacheable,
109
+ where,
110
+ Clase,
111
+ tipo: 'resolverfield',
112
+ relacion: 'hasOne',
113
+ }, pagina);
114
+ },
115
+ query: async (servicio, IdModelo, Clase) => {
116
+ imprimir(`${modelo} ${IdModelo} hasOne query ${planeta}`);
117
+ return servicio
118
+ .findByPk(IdModelo, pagina)
119
+ .then((item) => item.$get(planeta));
120
+ },
121
+ ligar: async (servicio, alias, IdModelo, IdPlaneta, through = null, borrarSSR = false) => this.ligar({
122
+ universo,
123
+ servicio,
124
+ alias,
125
+ IdModelo,
126
+ IdPlaneta,
127
+ tipo: 'hasOne',
128
+ planeta,
129
+ through,
130
+ borrarSSR,
131
+ }),
132
+ desligar: async (servicio, alias, IdModelo, IdPlaneta, borrarSSR = false) => this.desligar({
133
+ universo,
134
+ servicio,
135
+ alias,
136
+ IdModelo,
137
+ IdPlaneta,
138
+ tipo: 'hasOne',
139
+ planeta,
140
+ borrarSSR,
141
+ }),
142
+ };
143
+ }
144
+ hasManyBelongsToMany(universo, planeta, IdEmpresa, pagina = null) {
145
+ // 2 y 4
146
+ return {
147
+ resolvefield: async (item, where, cacheable, Clase) => this.muchos({
148
+ universo,
149
+ IdEmpresa,
150
+ planeta,
151
+ item,
152
+ cacheable,
153
+ where,
154
+ Clase,
155
+ tipo: 'resolverfield',
156
+ relacion: 'hasManyBelongsToMany',
157
+ }, pagina),
158
+ query: async (servicio, IdModelo, Clase) => {
159
+ imprimir(`${modelo} ${IdModelo} hasManyBelongsToMany query ${planeta}`);
160
+ return servicio
161
+ .findByPk(IdModelo, pagina)
162
+ .then((item) => item.$get(planeta));
163
+ },
164
+ ligar: async (servicio, alias, IdModelo, IdPlaneta, through = null, borrarSSR = false) => this.ligar({
165
+ universo,
166
+ servicio,
167
+ alias,
168
+ IdModelo,
169
+ IdPlaneta,
170
+ tipo: 'hasManyBelongsToMany',
171
+ planeta,
172
+ through,
173
+ borrarSSR,
174
+ }),
175
+ desligar: async (servicio, alias, IdModelo, IdPlaneta, borrarSSR = false) => this.desligar({
176
+ universo,
177
+ servicio,
178
+ alias,
179
+ IdModelo,
180
+ IdPlaneta,
181
+ tipo: 'hasManyBelongsToMany',
182
+ planeta,
183
+ borrarSSR,
184
+ }),
185
+ };
186
+ }
187
+ nodo(universo, planeta, IdEmpresa, pagina = null) {
188
+ // 7
189
+ return {
190
+ resolvefield: async (item, where, cacheable, Clase) => this.muchos({
191
+ universo,
192
+ IdEmpresa,
193
+ planeta,
194
+ item,
195
+ cacheable,
196
+ where,
197
+ Clase,
198
+ tipo: 'resolverfield',
199
+ relacion: 'nodo',
200
+ }, pagina),
201
+ query: async (servicio, IdModelo, Clase) => {
202
+ imprimir(`${modelo} ${IdModelo} nodo query ${planeta}`);
203
+ return servicio
204
+ .findByPk(IdModelo, pagina)
205
+ .then((item) => item.$get(planeta));
206
+ },
207
+ ligar: async (servicio, alias, IdModelo, IdPlaneta, through, borrarSSR = false) => this.ligar({
208
+ universo,
209
+ servicio,
210
+ alias,
211
+ IdModelo,
212
+ IdPlaneta,
213
+ tipo: 'nodo',
214
+ planeta,
215
+ through,
216
+ borrarSSR,
217
+ }),
218
+ desligar: async (servicio, alias, IdModelo, IdPlaneta, borrarSSR = false) => this.desligar({
219
+ universo,
220
+ servicio,
221
+ alias,
222
+ IdModelo,
223
+ IdPlaneta,
224
+ tipo: 'nodo',
225
+ planeta,
226
+ borrarSSR,
227
+ }),
228
+ };
229
+ }
230
+ especial(universo, planeta, IdEmpresa, pagina = null) {
231
+ // 5
232
+ return {
233
+ resolvefield: async (item, where, cacheable, Clase) => this.uno({
234
+ universo,
235
+ IdEmpresa,
236
+ planeta,
237
+ item,
238
+ cacheable,
239
+ where,
240
+ Clase,
241
+ tipo: 'resolverfield',
242
+ relacion: 'especial',
243
+ }, pagina),
244
+ query: async (servicio, IdModelo, Clase) => {
245
+ imprimir(`${modelo} ${IdModelo} especial query ${planeta}`);
246
+ return servicio
247
+ .findByPk(IdModelo, pagina)
248
+ .then((item) => item.$get(planeta));
249
+ },
250
+ ligar: async (servicio, alias, IdModelo, IdPlaneta, through = null, borrarSSR) => this.ligar({
251
+ universo,
252
+ servicio,
253
+ alias,
254
+ IdModelo,
255
+ IdPlaneta,
256
+ tipo: 'especial',
257
+ planeta,
258
+ through,
259
+ borrarSSR,
260
+ }),
261
+ desligar: async (servicio, alias, IdModelo, IdPlaneta, borrarSSR) => this.desligar({
262
+ universo,
263
+ servicio,
264
+ alias,
265
+ IdModelo,
266
+ IdPlaneta,
267
+ tipo: 'especial',
268
+ planeta,
269
+ borrarSSR,
270
+ }),
271
+ };
272
+ }
273
+ recursiva(universo, planeta, IdEmpresa, pagina = null) {
274
+ // 6
275
+ return {
276
+ sucesores: async (servicio, item, singular, plural, clase) => this.basesucesores(universo, IdEmpresa, servicio, item, singular, plural, clase),
277
+ predecesores: async (servicio, item, singular, plural, clase) => this.basepredecesores(universo, IdEmpresa, servicio, item, singular, plural, clase),
278
+ arbol: async (item, where, cacheable, Clase) => { },
279
+ preResolvefield: async (item, where, cacheable, Clase) => this.uno({
280
+ universo,
281
+ IdEmpresa,
282
+ planeta,
283
+ item,
284
+ cacheable,
285
+ where,
286
+ Clase,
287
+ tipo: 'resolverfield',
288
+ relacion: 'recursiva',
289
+ }, pagina),
290
+ preQuery: async (servicio, IdModelo, Clase) => {
291
+ imprimir(`${modelo} ${IdModelo} recursiva query ${planeta}`);
292
+ return servicio
293
+ .findByPk(IdModelo, pagina)
294
+ .then((item) => item.$get(planeta));
295
+ },
296
+ subResolvefield: async (item, where, cacheable, Clase) => this.muchos({
297
+ universo,
298
+ IdEmpresa,
299
+ planeta,
300
+ item,
301
+ cacheable,
302
+ where,
303
+ Clase,
304
+ tipo: 'resolverfield',
305
+ relacion: 'recursiva',
306
+ }, pagina),
307
+ subQuery: async (servicio, IdModelo, Clase) => {
308
+ imprimir(`${modelo} ${IdModelo} recursiva query ${planeta}`);
309
+ return servicio
310
+ .findByPk(IdModelo, pagina)
311
+ .then((item) => item.$get(planeta));
312
+ },
313
+ ligar: async (IdModelo, IdPlaneta, borrarSSR) => {
314
+ imprimir(`${modelo} ${IdModelo} ligar ligar ${planeta} ${IdPlaneta}`);
315
+ },
316
+ desligar: async (IdModelo, IdPlaneta, borrarSSR) => {
317
+ imprimir(`${modelo} ${IdModelo} desligar desligar ${planeta} ${IdPlaneta}`);
318
+ },
319
+ };
320
+ }
321
+ async basesucesores(universo, IdEmpresa, servicio, item, singular, plural, clase) {
322
+ // console.log('me estoy ejecutando')
323
+ async function detective(item) {
324
+ console.log('item', item.nombre);
325
+ return await item
326
+ .$get(`sub${plural}`)
327
+ .then(async (items) => Promise.all(items.map(async (item) => await detective(item))))
328
+ .then((items) => [...items, item.id]);
329
+ }
330
+ try {
331
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
332
+ !IdEmpresa) {
333
+ IdEmpresa = await this.receptor.buscarEmpresa();
334
+ }
335
+ const key = `${universo ? universo : 'pro'}:${IdEmpresa}:${singular}:${item}`;
336
+ const exist = await this.cacheManager.store.hexists(key, 'item');
337
+ console.log('key:', key);
338
+ if (exist) {
339
+ const item = await this.cacheManager.store.hget(key, 'sucesores');
340
+ if (item) {
341
+ return JSON.parse(item);
342
+ }
343
+ }
344
+ console.log('exist:', exist);
345
+ const resultado = await servicio
346
+ .findByPk(item)
347
+ .then((response) => detective(response))
348
+ .then((response) => (0, lodash_1.flattenDeep)(response));
349
+ this.cacheManager.store.hset(key, 'sucesores', JSON.stringify(resultado));
350
+ return resultado;
351
+ }
352
+ catch (err) {
353
+ // console.log({ err });
354
+ }
355
+ }
356
+ async basepredecesores(universo, IdEmpresa, servicio, item, singular, plural, clase) {
357
+ async function detective(item, array) {
358
+ item && array.push(item.id);
359
+ return !_.isNull(item)
360
+ ? await item
361
+ .$get(`pre${modelo}`)
362
+ .then((response) => detective(response, array))
363
+ : array;
364
+ }
365
+ try {
366
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
367
+ !IdEmpresa) {
368
+ IdEmpresa = await this.receptor.buscarEmpresa();
369
+ }
370
+ const key = `${universo ? universo : 'pro'}:${IdEmpresa}:${singular}:${item}`;
371
+ const exist = await this.cacheManager.store.hexists(key, 'item');
372
+ if (exist) {
373
+ const item = await this.cacheManager.store.hget(key, 'predecesores');
374
+ if (item) {
375
+ return JSON.parse(item);
376
+ }
377
+ }
378
+ const resultado = await servicio
379
+ .findByPk(item)
380
+ .then((response) => detective(response, []))
381
+ .then((response) => (0, lodash_1.flattenDeep)(response));
382
+ this.cacheManager.store.hset(key, 'predecesores', JSON.stringify(resultado));
383
+ return resultado;
384
+ }
385
+ catch (err) {
386
+ console.log({ err });
387
+ }
388
+ }
389
+ async uno({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }, pagina = null) {
390
+ let tiempo;
391
+ // if (isDev) tiempo = moment();
392
+ try {
393
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
394
+ !IdEmpresa) {
395
+ IdEmpresa = await this.receptor.buscarEmpresa();
396
+ }
397
+ let nkey = `${universo ? universo : 'pro'}:${IdEmpresa}:${modelo}:${item.id}`;
398
+ const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({
399
+ universo,
400
+ IdEmpresa,
401
+ tipo,
402
+ fragmentos: [
403
+ { nombre: modelo, id: item.id },
404
+ { nombre: planeta },
405
+ ],
406
+ }), (cache) => Promise.resolve(new Clase(JSON.parse(cache))), //Revisar
407
+ (resultado) => Promise.resolve(resultado ? resultado.get({ plain: true }) : null), //transformar
408
+ () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
409
+ () => new Promise(async (resolve) => {
410
+ try {
411
+ let e = await this.cacheManager.store.hexists(nkey, planeta);
412
+ if (e) {
413
+ let id = await this.cacheManager.store.hget(nkey, planeta);
414
+ let key = `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`;
415
+ const exist = await this.cacheManager.store.hexists(key, 'item');
416
+ if (exist) {
417
+ let item = await this.cacheManager.store.hget(key, 'item');
418
+ resolve(item);
419
+ }
420
+ else {
421
+ resolve(undefined);
422
+ }
423
+ }
424
+ else {
425
+ return resolve(undefined);
426
+ }
427
+ }
428
+ catch (err) {
429
+ console.log(this.cacheManager);
430
+ }
431
+ }), //observar
432
+ (__, resultado) => {
433
+ if (resultado)
434
+ this.cacheManager.store.hset(`${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${resultado.id}`, 'item', JSON.stringify(resultado));
435
+ return this.cacheManager.store.hset(nkey, planeta, resultado ? JSON.stringify(resultado.id) : null);
436
+ });
437
+ if (resultado)
438
+ await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.get({ plain: true }));
439
+ if (isDev)
440
+ console.log(
441
+ // moment().diff(moment(tiempo), 'milliseconds', true),
442
+ 'uno', cache);
443
+ return resultado;
444
+ }
445
+ catch (err) {
446
+ console.log(err);
447
+ log(chalk.red('uno', { modelo, err }, '***********'));
448
+ }
449
+ }
450
+ async muchos({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }, pagina = null) {
451
+ let tiempo;
452
+ // if (isDev) tiempo = moment();
453
+ try {
454
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
455
+ !IdEmpresa) {
456
+ IdEmpresa = await this.receptor.buscarEmpresa();
457
+ }
458
+ let nkey = `${universo ? universo : 'pro'}:${IdEmpresa}:${modelo}:${item.id}`;
459
+ let pkey = (id) => `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`;
460
+ const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({
461
+ universo,
462
+ IdEmpresa,
463
+ tipo,
464
+ fragmentos: [
465
+ { nombre: modelo, id: item.id },
466
+ { nombre: planeta },
467
+ ],
468
+ }), (cache) => Promise.resolve(cache.map((n) => new Clase(JSON.parse(n)))), //Revisar
469
+ (resultado) => Promise.resolve(resultado.map((n) => n.get({ plain: true }))), //transformar
470
+ () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
471
+ () => new Promise(async (resolve) => {
472
+ try {
473
+ let e = await this.cacheManager.store.hexists(nkey, planeta);
474
+ if (e) {
475
+ let ids = await this.cacheManager.store.hget(nkey, planeta);
476
+ if (ids) {
477
+ Promise.all(JSON.parse(ids).map((id) => this.cacheManager.store.hexists(pkey(id), 'item'))).then((exists) => {
478
+ if (!exists.includes(0)) {
479
+ Promise.all(JSON.parse(ids).map(async (id) => await this.cacheManager.store.hget(pkey(id), 'item'))).then(resolve);
480
+ }
481
+ else
482
+ resolve(undefined);
483
+ });
484
+ }
485
+ else
486
+ resolve(undefined);
487
+ }
488
+ else
489
+ resolve(undefined);
490
+ }
491
+ catch (err) {
492
+ console.log({ err });
493
+ }
494
+ }), //observar
495
+ (__, resultado) => {
496
+ return Promise.all(resultado.map((n) => this.cacheManager.store.hset(pkey(n.id), 'item', JSON.stringify(n)))).then(() => this.cacheManager.store.hset(nkey, planeta, JSON.stringify(resultado.map((n) => n.id))));
497
+ });
498
+ await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.map((n) => n.get({ plain: true })));
499
+ if (isDev)
500
+ console.log(
501
+ // moment().diff(moment(tiempo), 'milliseconds', true),
502
+ 'muchos', cache);
503
+ return resultado ? resultado : [];
504
+ }
505
+ catch (err) {
506
+ console.log(err);
507
+ log(chalk.red('muchos', { modelo, err }, '***********'));
508
+ }
509
+ }
510
+ async ligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, through, borrarSSR, }) {
511
+ let IdEmpresa = null;
512
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
513
+ !IdEmpresa) {
514
+ IdEmpresa = await this.receptor.buscarEmpresa();
515
+ }
516
+ let crearKey = (planeta, id) => [
517
+ `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`,
518
+ `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:paginacion`,
519
+ ];
520
+ // debugger
521
+ return this.eliminarCache([
522
+ ...crearKey(modelo, IdModelo),
523
+ ...crearKey(planeta, IdPlaneta),
524
+ ], borrarSSR)
525
+ .then(() => servicio.findByPk(IdModelo))
526
+ .then((item) => {
527
+ return item.$add(alias, IdPlaneta, through ? { through } : null);
528
+ })
529
+ .then((response) => true)
530
+ .catch((err) => {
531
+ log(chalk.red('ligar', alias, err, '***********'));
532
+ return false;
533
+ });
534
+ }
535
+ async desligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, borrarSSR, }) {
536
+ let IdEmpresa = null;
537
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
538
+ !IdEmpresa) {
539
+ IdEmpresa = await this.receptor.buscarEmpresa();
540
+ }
541
+ let crearKey = (planeta, id) => [
542
+ `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`,
543
+ `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:paginacion`,
544
+ ];
545
+ console.log('simoooon');
546
+ imprimir(`${modelo} ${IdModelo} ${tipo} desligar ${planeta} ${IdPlaneta}`);
547
+ return this.eliminarCache([
548
+ ...crearKey(modelo, IdModelo),
549
+ ...crearKey(planeta, IdPlaneta),
550
+ ], borrarSSR)
551
+ .then(() => servicio.findByPk(IdModelo))
552
+ .then((item) => item.$remove(alias, IdPlaneta))
553
+ .then(() => true)
554
+ .catch((err) => {
555
+ log(chalk.red('desligar', alias, err, '***********'));
556
+ return false;
557
+ });
558
+ }
559
+ async eliminarCache(items, borrarSSR = false) {
560
+ if (borrarSSR)
561
+ redisStore_1.clientSsr.flushdb();
562
+ log(chalk.red('SE ELIMINOOOO ALGOOO!!!!!!!!!!!!!!', items, borrarSSR));
563
+ return Promise.all(items.map(async (item) => this.cacheManager
564
+ .keys(`*${item}*`)
565
+ .then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))))));
566
+ }
567
+ async arbol(universo, IdEmpresa, planeta, servicio, Clase, subnombre, IdPlaneta) {
568
+ if (['general', 'ecommerce', 'ecreator'].includes(universo) &&
569
+ !IdEmpresa) {
570
+ IdEmpresa = await this.receptor.buscarEmpresa();
571
+ }
572
+ const KEY = `${universo ?? 'pro'}:${IdEmpresa}:arbol:${subnombre.replace('sub', '')}`;
573
+ const cache = await this.cacheManager.get(KEY);
574
+ if (cache) {
575
+ const data = JSON.parse(cache);
576
+ if (Array.isArray(data)) {
577
+ return data.map((item) => new Clase(item));
578
+ }
579
+ }
580
+ // let resultado;
581
+ const resultado = await servicio.findAll({
582
+ where: {
583
+ [IdPlaneta]: null,
584
+ },
585
+ // include: [
586
+ // {
587
+ // model: Clase,
588
+ // as: subnombre,
589
+ // nested: true,
590
+ // },
591
+ // ],
592
+ });
593
+ await this.cacheManager.set(KEY, JSON.stringify(resultado));
594
+ return resultado;
595
+ }
596
+ };
597
+ }
@@ -0,0 +1,93 @@
1
+ import { Key } from './utils/keyInterface';
2
+ export declare const redis_on = true;
3
+ type Ctor = new (...a: any[]) => any;
4
+ interface Peticion {
5
+ value: any;
6
+ key: Key;
7
+ Clase: Ctor;
8
+ repository: any;
9
+ options?: any;
10
+ pagina?: any;
11
+ cacheable?: boolean;
12
+ borrarSSR?: boolean;
13
+ }
14
+ export declare function BaseService(modelo: string): {
15
+ new <T extends {
16
+ cacheManager: any;
17
+ receptor: any;
18
+ buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
19
+ buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
20
+ crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
21
+ contar({ value, repository, key }: {
22
+ value: any;
23
+ repository: any;
24
+ key: any;
25
+ }): Promise<unknown>;
26
+ actualizar({ value, options, key, Clase, repository, borrarSSR, }: {
27
+ value: any;
28
+ options: any;
29
+ key: any;
30
+ Clase: any;
31
+ repository: any;
32
+ borrarSSR?: any;
33
+ }): Promise<unknown>;
34
+ reescribir({ value, options, repository }: {
35
+ value: any;
36
+ options: any;
37
+ repository: any;
38
+ }): Promise<unknown>;
39
+ destruir({ value, repository, borrarSSR, }: {
40
+ value: any;
41
+ repository: any;
42
+ borrarSSR?: any;
43
+ }): Promise<unknown>;
44
+ buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: Peticion): Promise<{
45
+ count: number;
46
+ rows: Ctor[];
47
+ }>;
48
+ buscarOcrear<Ctor>({ value, repository }: {
49
+ value: any;
50
+ repository: any;
51
+ }): Promise<Ctor>;
52
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
53
+ }>(cacheManager: any, receptor?: any): {
54
+ cacheManager: any;
55
+ receptor: any;
56
+ buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
57
+ buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
58
+ crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
59
+ contar({ value, repository, key }: {
60
+ value: any;
61
+ repository: any;
62
+ key: any;
63
+ }): Promise<unknown>;
64
+ actualizar({ value, options, key, Clase, repository, borrarSSR, }: {
65
+ value: any;
66
+ options: any;
67
+ key: any;
68
+ Clase: any;
69
+ repository: any;
70
+ borrarSSR?: any;
71
+ }): Promise<unknown>;
72
+ reescribir({ value, options, repository }: {
73
+ value: any;
74
+ options: any;
75
+ repository: any;
76
+ }): Promise<unknown>;
77
+ destruir({ value, repository, borrarSSR, }: {
78
+ value: any;
79
+ repository: any;
80
+ borrarSSR?: any;
81
+ }): Promise<unknown>;
82
+ buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: Peticion): Promise<{
83
+ count: number;
84
+ rows: Ctor[];
85
+ }>;
86
+ buscarOcrear<Ctor>({ value, repository }: {
87
+ value: any;
88
+ repository: any;
89
+ }): Promise<Ctor>;
90
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
91
+ };
92
+ };
93
+ export {};