@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,216 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FilterBoolean = exports.FilterDate = exports.FilterFloat = exports.FilterNumber = exports.FilterString = exports.formarInclude = void 0;
13
+ const lodash_1 = require("lodash");
14
+ const graphql_1 = require("@nestjs/graphql");
15
+ const formarwhere_1 = require("./formarwhere");
16
+ const formarInclude = async (include, mapa, tipo, conexion, required = true) => {
17
+ if (!include)
18
+ return [];
19
+ let response = await (0, lodash_1.chain)(include)
20
+ .entries()
21
+ .value()
22
+ .reduce(async (ac, [as, { where, include }]) => {
23
+ return ac.then(async (ac) => {
24
+ return ac.concat({
25
+ as,
26
+ ...(where
27
+ ? {
28
+ where: (0, formarwhere_1.formarWhere)(where),
29
+ }
30
+ : {}),
31
+ ...(include
32
+ ? {
33
+ include: await (0, exports.formarInclude)(include, await mapa.include[(0, lodash_1.lowerCase)(as)].mapa, tipo, conexion, required),
34
+ }
35
+ : {}),
36
+ required: include ? true : required,
37
+ model: tipo == 'ESTATICO'
38
+ ? mapa.include[(0, lodash_1.lowerCase)(as)].modelo
39
+ : conexion.getRepository(mapa.include[(0, lodash_1.lowerCase)(as)].modelo),
40
+ });
41
+ });
42
+ }, Promise.resolve([]));
43
+ return response;
44
+ };
45
+ exports.formarInclude = formarInclude;
46
+ let FilterBasic = class FilterBasic {
47
+ };
48
+ __decorate([
49
+ (0, graphql_1.Field)({ nullable: true }),
50
+ __metadata("design:type", String)
51
+ ], FilterBasic.prototype, "is", void 0);
52
+ FilterBasic = __decorate([
53
+ (0, graphql_1.InputType)()
54
+ ], FilterBasic);
55
+ let FilterString = class FilterString extends FilterBasic {
56
+ };
57
+ exports.FilterString = FilterString;
58
+ __decorate([
59
+ (0, graphql_1.Field)({ nullable: true }),
60
+ __metadata("design:type", String)
61
+ ], FilterString.prototype, "like", void 0);
62
+ __decorate([
63
+ (0, graphql_1.Field)({ nullable: true }),
64
+ __metadata("design:type", String)
65
+ ], FilterString.prototype, "notLike", void 0);
66
+ __decorate([
67
+ (0, graphql_1.Field)(() => [String], { nullable: true }),
68
+ __metadata("design:type", Array)
69
+ ], FilterString.prototype, "or", void 0);
70
+ __decorate([
71
+ (0, graphql_1.Field)({ nullable: true }),
72
+ __metadata("design:type", String)
73
+ ], FilterString.prototype, "eq", void 0);
74
+ exports.FilterString = FilterString = __decorate([
75
+ (0, graphql_1.InputType)()
76
+ ], FilterString);
77
+ let FilterNumber = class FilterNumber {
78
+ };
79
+ exports.FilterNumber = FilterNumber;
80
+ __decorate([
81
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
82
+ __metadata("design:type", Number)
83
+ ], FilterNumber.prototype, "eq", void 0);
84
+ __decorate([
85
+ (0, graphql_1.Field)(() => [graphql_1.Int], { nullable: true }),
86
+ __metadata("design:type", String)
87
+ ], FilterNumber.prototype, "not", void 0);
88
+ __decorate([
89
+ (0, graphql_1.Field)(() => [graphql_1.Int], { nullable: true }),
90
+ __metadata("design:type", Array)
91
+ ], FilterNumber.prototype, "or", void 0);
92
+ __decorate([
93
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
94
+ __metadata("design:type", Number)
95
+ ], FilterNumber.prototype, "gt", void 0);
96
+ __decorate([
97
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
98
+ __metadata("design:type", Number)
99
+ ], FilterNumber.prototype, "gte", void 0);
100
+ __decorate([
101
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
102
+ __metadata("design:type", Number)
103
+ ], FilterNumber.prototype, "lt", void 0);
104
+ __decorate([
105
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
106
+ __metadata("design:type", Number)
107
+ ], FilterNumber.prototype, "lte", void 0);
108
+ __decorate([
109
+ (0, graphql_1.Field)(() => [graphql_1.Int], { nullable: true }),
110
+ __metadata("design:type", Array)
111
+ ], FilterNumber.prototype, "between", void 0);
112
+ __decorate([
113
+ (0, graphql_1.Field)(() => [graphql_1.Int], { nullable: true }),
114
+ __metadata("design:type", Array)
115
+ ], FilterNumber.prototype, "notBetween", void 0);
116
+ __decorate([
117
+ (0, graphql_1.Field)(() => [graphql_1.Int], { nullable: true }),
118
+ __metadata("design:type", Array)
119
+ ], FilterNumber.prototype, "in", void 0);
120
+ exports.FilterNumber = FilterNumber = __decorate([
121
+ (0, graphql_1.InputType)()
122
+ ], FilterNumber);
123
+ let FilterFloat = class FilterFloat {
124
+ };
125
+ exports.FilterFloat = FilterFloat;
126
+ __decorate([
127
+ (0, graphql_1.Field)(() => graphql_1.Float, { nullable: true }),
128
+ __metadata("design:type", Number)
129
+ ], FilterFloat.prototype, "eq", void 0);
130
+ __decorate([
131
+ (0, graphql_1.Field)(() => [graphql_1.Float], { nullable: true }),
132
+ __metadata("design:type", String)
133
+ ], FilterFloat.prototype, "not", void 0);
134
+ __decorate([
135
+ (0, graphql_1.Field)(() => [graphql_1.Float], { nullable: true }),
136
+ __metadata("design:type", Array)
137
+ ], FilterFloat.prototype, "or", void 0);
138
+ __decorate([
139
+ (0, graphql_1.Field)(() => graphql_1.Float, { nullable: true }),
140
+ __metadata("design:type", Number)
141
+ ], FilterFloat.prototype, "gt", void 0);
142
+ __decorate([
143
+ (0, graphql_1.Field)(() => graphql_1.Float, { nullable: true }),
144
+ __metadata("design:type", Number)
145
+ ], FilterFloat.prototype, "gte", void 0);
146
+ __decorate([
147
+ (0, graphql_1.Field)(() => graphql_1.Float, { nullable: true }),
148
+ __metadata("design:type", Number)
149
+ ], FilterFloat.prototype, "lt", void 0);
150
+ __decorate([
151
+ (0, graphql_1.Field)(() => graphql_1.Float, { nullable: true }),
152
+ __metadata("design:type", Number)
153
+ ], FilterFloat.prototype, "lte", void 0);
154
+ __decorate([
155
+ (0, graphql_1.Field)(() => [graphql_1.Float], { nullable: true }),
156
+ __metadata("design:type", Array)
157
+ ], FilterFloat.prototype, "between", void 0);
158
+ __decorate([
159
+ (0, graphql_1.Field)(() => [graphql_1.Float], { nullable: true }),
160
+ __metadata("design:type", Array)
161
+ ], FilterFloat.prototype, "notBetween", void 0);
162
+ __decorate([
163
+ (0, graphql_1.Field)(() => [graphql_1.Float], { nullable: true }),
164
+ __metadata("design:type", Array)
165
+ ], FilterFloat.prototype, "in", void 0);
166
+ exports.FilterFloat = FilterFloat = __decorate([
167
+ (0, graphql_1.InputType)()
168
+ ], FilterFloat);
169
+ let FilterDate = class FilterDate {
170
+ };
171
+ exports.FilterDate = FilterDate;
172
+ __decorate([
173
+ (0, graphql_1.Field)(() => [Date], { nullable: true }),
174
+ __metadata("design:type", Array)
175
+ ], FilterDate.prototype, "between", void 0);
176
+ __decorate([
177
+ (0, graphql_1.Field)({ nullable: true }),
178
+ __metadata("design:type", String)
179
+ ], FilterDate.prototype, "or", void 0);
180
+ __decorate([
181
+ (0, graphql_1.Field)(() => Date, { nullable: true }),
182
+ __metadata("design:type", Date)
183
+ ], FilterDate.prototype, "gte", void 0);
184
+ __decorate([
185
+ (0, graphql_1.Field)(() => Date, { nullable: true }),
186
+ __metadata("design:type", Date)
187
+ ], FilterDate.prototype, "lte", void 0);
188
+ __decorate([
189
+ (0, graphql_1.Field)(() => Date, { nullable: true }),
190
+ __metadata("design:type", Date)
191
+ ], FilterDate.prototype, "eq", void 0);
192
+ exports.FilterDate = FilterDate = __decorate([
193
+ (0, graphql_1.InputType)()
194
+ ], FilterDate);
195
+ let FilterBoolean = class FilterBoolean extends FilterBasic {
196
+ };
197
+ exports.FilterBoolean = FilterBoolean;
198
+ __decorate([
199
+ (0, graphql_1.Field)({ nullable: true }),
200
+ __metadata("design:type", Boolean)
201
+ ], FilterBoolean.prototype, "eq", void 0);
202
+ __decorate([
203
+ (0, graphql_1.Field)(() => graphql_1.Int, { nullable: true }),
204
+ __metadata("design:type", Number)
205
+ ], FilterBoolean.prototype, "between", void 0);
206
+ __decorate([
207
+ (0, graphql_1.Field)(() => [Boolean], { nullable: true }),
208
+ __metadata("design:type", Array)
209
+ ], FilterBoolean.prototype, "or", void 0);
210
+ __decorate([
211
+ (0, graphql_1.Field)({ nullable: true }),
212
+ __metadata("design:type", Boolean)
213
+ ], FilterBoolean.prototype, "not", void 0);
214
+ exports.FilterBoolean = FilterBoolean = __decorate([
215
+ (0, graphql_1.InputType)()
216
+ ], FilterBoolean);
@@ -0,0 +1 @@
1
+ export declare const formarOrder: (order: any, mapa: any, tipo: any, conexion: any) => Promise<any>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formarOrder = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const lodash_2 = require("lodash");
6
+ const formarOrder = (order, mapa, tipo, conexion) => {
7
+ try {
8
+ return (0, lodash_2.isArray)(order)
9
+ ? Promise.all(order.map(async ({ as, acomodo, key }) => {
10
+ return [
11
+ ...(as != null || as != undefined
12
+ ? [
13
+ {
14
+ model: tipo == 'ESTATICO'
15
+ ? mapa.include[(0, lodash_1.lowerCase)(as)].modelo
16
+ : conexion.getRepository(mapa.include[(0, lodash_1.lowerCase)(as)].modelo),
17
+ as,
18
+ },
19
+ ]
20
+ : []),
21
+ key,
22
+ acomodo,
23
+ ];
24
+ })).then((response) => {
25
+ return response;
26
+ })
27
+ : Promise.resolve([]);
28
+ }
29
+ catch (err) {
30
+ console.log('el param de orden es incorrecto', err);
31
+ return Promise.resolve([]);
32
+ }
33
+ };
34
+ exports.formarOrder = formarOrder;
@@ -0,0 +1 @@
1
+ export declare const formarWhere: (where: any) => any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formarWhere = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const sequelize_1 = require("sequelize");
6
+ const formarWhere = (where) => {
7
+ let nuevo = (0, lodash_1.chain)(where)
8
+ .entries()
9
+ .reduce((ac, [atributo, operator]) => {
10
+ // if(isNumber(operator)){
11
+ // return ({...ac, [ atributo ] : operator })
12
+ // }
13
+ if (!(0, lodash_1.isObject)(operator) && !(0, lodash_1.isNull)(operator) && !(0, lodash_1.isNumber)(operator))
14
+ return { [atributo]: operator };
15
+ if ((0, lodash_1.isObject)(operator)) {
16
+ let [[op, value]] = (0, lodash_1.entries)(operator);
17
+ return { ...ac, [atributo]: { [sequelize_1.Op[op]]: value } };
18
+ }
19
+ return { ...ac, [atributo]: operator };
20
+ }, {})
21
+ .value();
22
+ return nuevo;
23
+ };
24
+ exports.formarWhere = formarWhere;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts degrees to radians.
3
+ *
4
+ * @param degrees Number of degrees.
5
+ */
6
+ export declare function degreesToRadians(degrees: any): number;
7
+ /**
8
+ * Returns the distance between 2 points of coordinates in Google Maps
9
+ *
10
+ * @see https://stackoverflow.com/a/1502821/4241030
11
+ * @param lat1 Latitude of the point A
12
+ * @param lng1 Longitude of the point A
13
+ * @param lat2 Latitude of the point B
14
+ * @param lng2 Longitude of the point B
15
+ */
16
+ export declare function getDistanceBetweenPoints(lat1: any, lng1: any, lat2: any, lng2: any): number;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.degreesToRadians = degreesToRadians;
4
+ exports.getDistanceBetweenPoints = getDistanceBetweenPoints;
5
+ /**
6
+ * Converts degrees to radians.
7
+ *
8
+ * @param degrees Number of degrees.
9
+ */
10
+ function degreesToRadians(degrees) {
11
+ return (degrees * Math.PI) / 180;
12
+ }
13
+ /**
14
+ * Returns the distance between 2 points of coordinates in Google Maps
15
+ *
16
+ * @see https://stackoverflow.com/a/1502821/4241030
17
+ * @param lat1 Latitude of the point A
18
+ * @param lng1 Longitude of the point A
19
+ * @param lat2 Latitude of the point B
20
+ * @param lng2 Longitude of the point B
21
+ */
22
+ function getDistanceBetweenPoints(lat1, lng1, lat2, lng2) {
23
+ // The radius of the planet earth in meters
24
+ let R = 6378137;
25
+ let dLat = degreesToRadians(lat2 - lat1);
26
+ let dLong = degreesToRadians(lng2 - lng1);
27
+ let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
28
+ Math.cos(degreesToRadians(lat1)) *
29
+ Math.cos(degreesToRadians(lat1)) *
30
+ Math.sin(dLong / 2) *
31
+ Math.sin(dLong / 2);
32
+ let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
33
+ let distance = R * c;
34
+ return distance;
35
+ }
@@ -0,0 +1,16 @@
1
+ export interface Fragmentos {
2
+ nombre: string;
3
+ id?: number;
4
+ }
5
+ export interface Key {
6
+ universo: string;
7
+ IdEmpresa?: number;
8
+ fragmentos?: Fragmentos[];
9
+ nombre?: string | null;
10
+ include?: any;
11
+ where?: any;
12
+ body?: any;
13
+ params?: any;
14
+ tipo: 'satelite' | 'query' | 'resolverfield';
15
+ }
16
+ export declare const transformarKey: ({ universo, IdEmpresa, fragmentos, nombre, body, params, tipo, where, include, }: Key) => string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformarKey = void 0;
4
+ const transformarKey = ({ universo, IdEmpresa, fragmentos, nombre, body, params, tipo, where, include, }) => {
5
+ //FIX TEMPORAL DE ULISES
6
+ universo =
7
+ ['usuario'].includes(nombre) &&
8
+ ['marketing', 'ecommerce'].includes(universo)
9
+ ? 'compartidos'
10
+ : universo;
11
+ switch (tipo) {
12
+ case 'satelite':
13
+ return `${universo}:${nombre}:IdEmpresa:${IdEmpresa}:body-${JSON.stringify(body)}-params-${JSON.stringify(params)}`;
14
+ case 'query':
15
+ return `${universo}${nombre ? `:${nombre}` : `:`}IdEmpresa:${IdEmpresa}:${fragmentos.map(({ nombre, id }) => `${nombre}:${id ? id : ''}`)}:where-${where && JSON.stringify(where)}-include-${include && JSON.stringify(include)}`;
16
+ case 'resolverfield':
17
+ return `${universo}${nombre ? `:${nombre}` : `:`}IdEmpresa:${IdEmpresa}:${fragmentos.map(({ nombre, id }) => `${nombre}:${id ? id : ''}`)}:where-${where && JSON.stringify(where)}-include-${include && JSON.stringify(include)}`;
18
+ default:
19
+ return '';
20
+ }
21
+ };
22
+ exports.transformarKey = transformarKey;
@@ -0,0 +1 @@
1
+ export declare var paginar: (cacheManager: any, IdEmpresa: any, pagina: any, modelo: any, resultado: any) => Promise<unknown>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paginar = void 0;
4
+ var tiempo = 86400000;
5
+ var paginar = (cacheManager, IdEmpresa, pagina, modelo, resultado) => {
6
+ return new Promise(async (resolve) => {
7
+ const paginakey$ = `empresa:${IdEmpresa}:pagina:${pagina}`;
8
+ let paginaredis = await cacheManager.get(paginakey$);
9
+ let paginacache = JSON.parse(paginaredis ? paginaredis : '{}');
10
+ cacheManager.set(paginakey$, JSON.stringify({
11
+ ...paginacache,
12
+ [modelo]: {
13
+ ...(paginacache[modelo] ? paginacache[modelo] : {}),
14
+ ...resultado,
15
+ },
16
+ }), 'EX', tiempo);
17
+ resolve(true);
18
+ });
19
+ };
20
+ exports.paginar = paginar;
package/receptor.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import { Conexion, ConexionProps } from './conexion';
3
+ export interface ReceptorConfig {
4
+ globalUrl: string;
5
+ }
6
+ export declare class ReceptorService {
7
+ private cacheManager;
8
+ readonly request: any;
9
+ private httpService;
10
+ private readonly config?;
11
+ conexiones: {
12
+ [key: string]: ConexionProps;
13
+ };
14
+ conexionesActivas: {
15
+ [key: string]: Conexion;
16
+ };
17
+ constructor(cacheManager: any, request: any, httpService: HttpService, config?: ReceptorConfig);
18
+ hola(): void;
19
+ private get globalUrl();
20
+ buscarConexiones(): Promise<any>;
21
+ buscarEmpresa(): Promise<any>;
22
+ buscar({ req }: {
23
+ req: any;
24
+ }, conexion: typeof Conexion, host_?: string): Promise<Conexion>;
25
+ }
package/receptor.js ADDED
@@ -0,0 +1,153 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
45
+ return function (target, key) { decorator(target, key, paramIndex); }
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.ReceptorService = void 0;
49
+ const axios_1 = require("@nestjs/axios");
50
+ const common_1 = require("@nestjs/common");
51
+ const _ = __importStar(require("lodash"));
52
+ const core_1 = require("@nestjs/core");
53
+ const cache_manager_1 = require("@nestjs/cache-manager");
54
+ let ReceptorService = class ReceptorService {
55
+ constructor(cacheManager, request, httpService, config) {
56
+ this.cacheManager = cacheManager;
57
+ this.request = request;
58
+ this.httpService = httpService;
59
+ this.config = config;
60
+ this.conexiones = {};
61
+ this.conexionesActivas = {};
62
+ }
63
+ hola() {
64
+ console.log('holaaaa');
65
+ }
66
+ get globalUrl() {
67
+ if (!this.config?.globalUrl) {
68
+ throw new Error(`globalUrl is not configured in ReceptorService. You must pass it during provider registration.`);
69
+ }
70
+ return this.config.globalUrl;
71
+ }
72
+ async buscarConexiones() {
73
+ const bases = await this.cacheManager.get('basesdedatos');
74
+ if (!bases)
75
+ await this.httpService
76
+ .get(`${this.globalUrl}/global/emisor`)
77
+ .toPromise()
78
+ .then(({ data }) => {
79
+ if (data) {
80
+ this.cacheManager.set('basesdedatos', JSON.stringify(data));
81
+ return data;
82
+ }
83
+ });
84
+ return Promise.resolve(JSON.parse(bases));
85
+ }
86
+ async buscarEmpresa() {
87
+ const KEY = this.request.req.headers['host']?.replace('www.', '');
88
+ let IdEmpresa = await this.cacheManager.get(KEY);
89
+ if (IdEmpresa)
90
+ return IdEmpresa;
91
+ const conexiones = await this.buscarConexiones();
92
+ IdEmpresa = _.findKey(conexiones, (o) => o.dominios
93
+ .map((d) => d.nombre)
94
+ .includes(this.request.req.headers['host']));
95
+ await this.cacheManager.set(KEY, IdEmpresa);
96
+ return IdEmpresa;
97
+ }
98
+ buscar({ req }, conexion, host_) {
99
+ return this.httpService
100
+ .get(`${this.globalUrl}/global/emisor`)
101
+ .toPromise()
102
+ .then(async ({ data }) => {
103
+ console.log('data');
104
+ let IdEmpresa = req.session?.IdEmpresa;
105
+ const host = host_ ?? req.headers['host'];
106
+ const asignar = async () => {
107
+ const conexionActiva = this.conexionesActivas[IdEmpresa];
108
+ console.log('conexionActiva', conexionActiva);
109
+ if (conexionActiva) {
110
+ console.log('ReceptorService.buscar.then.asignar.conexionActiva');
111
+ return conexionActiva;
112
+ }
113
+ const baseDeDatos = data[IdEmpresa];
114
+ console.log('baseDeDatos', baseDeDatos);
115
+ if (baseDeDatos) {
116
+ const coneccion = new conexion(baseDeDatos);
117
+ Object.assign(this.conexionesActivas, {
118
+ [IdEmpresa]: coneccion,
119
+ });
120
+ //ts-ignore
121
+ console.log('ReceptorService.buscar.then.asignar.baseDeDatos', coneccion.config.database);
122
+ return coneccion;
123
+ }
124
+ };
125
+ // console.log({ IdEmpresa, host })
126
+ if (IdEmpresa) {
127
+ const db = await asignar();
128
+ // console.log(db)
129
+ return db;
130
+ }
131
+ if (host) {
132
+ IdEmpresa = _.findKey(data, (o) => o.dominios.map((d) => d.nombre).includes(host));
133
+ console.log('ReceptorService.buscar.then.host', host, IdEmpresa);
134
+ const db = await asignar();
135
+ return db;
136
+ }
137
+ // console.log('ReceptorService.buscar.then', null);
138
+ return null;
139
+ })
140
+ .catch((err) => {
141
+ console.log('no coneta el receptor', err);
142
+ return null;
143
+ });
144
+ }
145
+ };
146
+ exports.ReceptorService = ReceptorService;
147
+ exports.ReceptorService = ReceptorService = __decorate([
148
+ (0, common_1.Injectable)(),
149
+ __param(0, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)),
150
+ __param(1, (0, common_1.Inject)(core_1.REQUEST)),
151
+ __param(3, (0, common_1.Optional)()),
152
+ __metadata("design:paramtypes", [Object, Object, axios_1.HttpService, Object])
153
+ ], ReceptorService);
@@ -0,0 +1,11 @@
1
+ import * as redisStore from 'cache-manager-redis-store';
2
+ export declare const client: any;
3
+ export declare const clientWhatsapp: any;
4
+ export declare const clientSsr: any;
5
+ export declare const redisConfig: {
6
+ store: typeof redisStore;
7
+ host: string;
8
+ db: number;
9
+ port: number;
10
+ };
11
+ export declare const redisSession: any;
package/redisStore.js ADDED
@@ -0,0 +1,78 @@
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.redisSession = exports.redisConfig = exports.clientSsr = exports.clientWhatsapp = exports.client = void 0;
37
+ const redisStore = __importStar(require("cache-manager-redis-store"));
38
+ const Redis = __importStar(require("ioredis"));
39
+ exports.client = new Redis.default({
40
+ port: 6379,
41
+ // host: process.env.NODE_ENV == "production"?"172.19.0.24" :"172.19.0.24",
42
+ host: process.env.NODE_ENV == 'production' ? 'redis' : '127.0.0.1',
43
+ // host: process.env.NODE_ENV == "production"?"172.18.0.11" :"172.18.0.15",
44
+ family: 4,
45
+ db: 3,
46
+ });
47
+ exports.clientWhatsapp = new Redis.default({
48
+ port: 6379,
49
+ // host: process.env.NODE_ENV == "production"?"172.19.0.24" :"172.19.0.24",
50
+ host: process.env.NODE_ENV == 'production' ? 'redis' : '127.0.0.1',
51
+ // host: process.env.NODE_ENV == "production"?"172.18.0.11" :"172.18.0.15",
52
+ family: 4,
53
+ db: 4,
54
+ });
55
+ exports.clientSsr = new Redis.default({
56
+ port: 6379,
57
+ // host: process.env.NODE_ENV == "production"?"172.19.0.24" :"172.19.0.24",
58
+ host: process.env.NODE_ENV == 'production' ? 'redis' : '127.0.0.1',
59
+ // host: process.env.NODE_ENV == "production"?"172.18.0.11" :"172.18.0.15",
60
+ family: 4,
61
+ db: 1,
62
+ });
63
+ exports.redisConfig = {
64
+ store: redisStore,
65
+ // host: process.env.NODE_ENV == "production"?"172.18.0.15" :"72.18.0.15",
66
+ host: process.env.NODE_ENV == 'production' ? 'redis' : '127.0.0.1',
67
+ db: 3,
68
+ // host: process.env.NODE_ENV == "production"?"172.18.0.11" :"172.18.0.15",
69
+ port: 6379,
70
+ };
71
+ exports.redisSession = new Redis.default({
72
+ port: 6379,
73
+ // host: process.env.NODE_ENV == "production"?"172.19.0.24" :"172.19.0.24",
74
+ host: process.env.NODE_ENV == 'production' ? 'redis' : '127.0.0.1',
75
+ // host: process.env.NODE_ENV == "production"?"172.18.0.11" :"172.18.0.15",
76
+ family: 4,
77
+ db: 5,
78
+ });