test-entity-library-asm 2.2.7 → 2.2.8
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/dist/CustomRepository.d.ts +12 -0
- package/dist/CustomRepository.js +141 -0
- package/dist/entities.views.routes.d.ts +1 -0
- package/dist/entities.views.routes.js +3 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -32
- package/package.json +1 -1
- package/src/{repositories/VerifyLocalRepository.ts → CustomRepository.ts} +17 -23
- package/src/entities.views.routes.ts +2 -0
- package/src/index.ts +14 -33
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm';
|
|
2
|
+
export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
3
|
+
constructor(target: EntityTarget<T>, dataSource: DataSource);
|
|
4
|
+
getVerifyLocals(status: number | null, page: number, pageSize: number, filters: any): Promise<{
|
|
5
|
+
data: T[];
|
|
6
|
+
total: number;
|
|
7
|
+
page: number;
|
|
8
|
+
pageSize: number;
|
|
9
|
+
totalPages: number;
|
|
10
|
+
}>;
|
|
11
|
+
anyOtherRepository(args: any): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.CustomRepository = void 0;
|
|
55
|
+
var typeorm_1 = require("typeorm");
|
|
56
|
+
var CustomRepository = /** @class */ (function (_super) {
|
|
57
|
+
__extends(CustomRepository, _super);
|
|
58
|
+
function CustomRepository(target, dataSource) {
|
|
59
|
+
return _super.call(this, target, dataSource.manager) || this;
|
|
60
|
+
}
|
|
61
|
+
CustomRepository.prototype.getVerifyLocals = function (status, page, pageSize, filters) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var queryBuilder, globalValue, _a, data, total;
|
|
64
|
+
return __generator(this, function (_b) {
|
|
65
|
+
switch (_b.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
queryBuilder = this.createQueryBuilder('entity')
|
|
68
|
+
.skip((page - 1) * pageSize)
|
|
69
|
+
.take(pageSize);
|
|
70
|
+
if (status !== null && status >= 0) {
|
|
71
|
+
queryBuilder.andWhere('entity.status = :status', { status: status });
|
|
72
|
+
}
|
|
73
|
+
if (filters['global'] && filters['global'].value) {
|
|
74
|
+
globalValue = "%".concat(filters['global'].value, "%");
|
|
75
|
+
queryBuilder.andWhere('(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
|
|
76
|
+
'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
|
|
77
|
+
'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
|
|
78
|
+
'OR entity.status LIKE :globalValue)', { globalValue: globalValue });
|
|
79
|
+
}
|
|
80
|
+
Object.keys(filters).forEach(function (key) {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
82
|
+
if (key !== 'global' && filters[key].constraints) {
|
|
83
|
+
var filter = filters[key];
|
|
84
|
+
var value = filter.constraints[0].value;
|
|
85
|
+
var matchMode = filter.constraints[0].matchMode;
|
|
86
|
+
if (value !== null) {
|
|
87
|
+
var jsonPath = key
|
|
88
|
+
.split('.')
|
|
89
|
+
.map(function (segment) { return "$.".concat(segment); })
|
|
90
|
+
.join('');
|
|
91
|
+
switch (matchMode) {
|
|
92
|
+
case 'startsWith':
|
|
93
|
+
queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") LIKE :").concat(key), (_a = {},
|
|
94
|
+
_a[key] = "".concat(value, "%"),
|
|
95
|
+
_a));
|
|
96
|
+
break;
|
|
97
|
+
case 'contains':
|
|
98
|
+
queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") LIKE :").concat(key), (_b = {},
|
|
99
|
+
_b[key] = "%".concat(value, "%"),
|
|
100
|
+
_b));
|
|
101
|
+
break;
|
|
102
|
+
case 'equals':
|
|
103
|
+
queryBuilder.andWhere("JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\") = :").concat(key), (_c = {},
|
|
104
|
+
_c[key] = value,
|
|
105
|
+
_c));
|
|
106
|
+
break;
|
|
107
|
+
case 'dateIs':
|
|
108
|
+
queryBuilder.andWhere("DATE(JSON_EXTRACT(entity.".concat(key.split('.')[0], ", \"").concat(jsonPath, "\")) = :").concat(key), (_d = {},
|
|
109
|
+
_d[key] = value,
|
|
110
|
+
_d));
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return [4 /*yield*/, queryBuilder.getManyAndCount()];
|
|
119
|
+
case 1:
|
|
120
|
+
_a = _b.sent(), data = _a[0], total = _a[1];
|
|
121
|
+
return [2 /*return*/, {
|
|
122
|
+
data: data,
|
|
123
|
+
total: total,
|
|
124
|
+
page: page,
|
|
125
|
+
pageSize: pageSize,
|
|
126
|
+
totalPages: Math.ceil(total / pageSize),
|
|
127
|
+
}];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
CustomRepository.prototype.anyOtherRepository = function (args) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
return [2 /*return*/];
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
return CustomRepository;
|
|
140
|
+
}(typeorm_1.Repository));
|
|
141
|
+
exports.CustomRepository = CustomRepository;
|
|
@@ -42,3 +42,4 @@ export { BusinessType } from './entities/BusinessType';
|
|
|
42
42
|
export { AuthenticationCredential } from './entities/AuthenticationCredential';
|
|
43
43
|
export { PosSystem } from './entities/PosSystem';
|
|
44
44
|
export { VerifyLocal } from './entities/VerifyLocal';
|
|
45
|
+
export { CustomRepository } from './CustomRepository';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VerifyLocal = exports.PosSystem = exports.AuthenticationCredential = exports.BusinessType = exports.LocalsCompany = exports.UserAddress = exports.User = exports.TypeMeasureIngredient = exports.TerminalSession = exports.Terminal = exports.Square = exports.RequestStatus = exports.RequestProductGroupComplement = exports.RequestProduct = exports.Request = exports.Region = exports.ProductTopping = exports.ProductIngredient = exports.ProductGroupComplement = exports.ProductGroup = exports.Product = exports.Plan = exports.PaymentMethod = exports.PartnerRole = exports.PartnerPermission = exports.PartnerNotification = exports.Partner = exports.MasterRole = exports.MasterPermission = exports.Master = exports.LocalQualification = exports.Local = exports.DiscountCodeUser = exports.DiscountCodeCompany = exports.Day = exports.Country = exports.Configuration = exports.Company = exports.CodeRedemptionHistoryUser = exports.CodeRedemptionHistoryCompany = exports.City = exports.ScheduleCategory = exports.Category = exports.BusinessTypeProduct = void 0;
|
|
3
|
+
exports.CustomRepository = exports.VerifyLocal = exports.PosSystem = exports.AuthenticationCredential = exports.BusinessType = exports.LocalsCompany = exports.UserAddress = exports.User = exports.TypeMeasureIngredient = exports.TerminalSession = exports.Terminal = exports.Square = exports.RequestStatus = exports.RequestProductGroupComplement = exports.RequestProduct = exports.Request = exports.Region = exports.ProductTopping = exports.ProductIngredient = exports.ProductGroupComplement = exports.ProductGroup = exports.Product = exports.Plan = exports.PaymentMethod = exports.PartnerRole = exports.PartnerPermission = exports.PartnerNotification = exports.Partner = exports.MasterRole = exports.MasterPermission = exports.Master = exports.LocalQualification = exports.Local = exports.DiscountCodeUser = exports.DiscountCodeCompany = exports.Day = exports.Country = exports.Configuration = exports.Company = exports.CodeRedemptionHistoryUser = exports.CodeRedemptionHistoryCompany = exports.City = exports.ScheduleCategory = exports.Category = exports.BusinessTypeProduct = void 0;
|
|
4
4
|
var BusinessTypeProduct_1 = require("./entities/BusinessTypeProduct");
|
|
5
5
|
Object.defineProperty(exports, "BusinessTypeProduct", { enumerable: true, get: function () { return BusinessTypeProduct_1.BusinessTypeProduct; } });
|
|
6
6
|
var Category_1 = require("./entities/Category");
|
|
@@ -89,3 +89,5 @@ var PosSystem_1 = require("./entities/PosSystem");
|
|
|
89
89
|
Object.defineProperty(exports, "PosSystem", { enumerable: true, get: function () { return PosSystem_1.PosSystem; } });
|
|
90
90
|
var VerifyLocal_1 = require("./entities/VerifyLocal");
|
|
91
91
|
Object.defineProperty(exports, "VerifyLocal", { enumerable: true, get: function () { return VerifyLocal_1.VerifyLocal; } });
|
|
92
|
+
var CustomRepository_1 = require("./CustomRepository");
|
|
93
|
+
Object.defineProperty(exports, "CustomRepository", { enumerable: true, get: function () { return CustomRepository_1.CustomRepository; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from 'express';
|
|
2
2
|
import { DataSource, EntityTarget, ObjectLiteral, Repository } from 'typeorm';
|
|
3
|
+
import { CustomRepository } from '.';
|
|
3
4
|
export * from './entities.views.routes';
|
|
4
5
|
export declare function createDataBaseSource(): DataSource;
|
|
5
6
|
export declare function showEntityNameEntity<T extends ObjectLiteral>(entity: EntityTarget<T>): Promise<Repository<T>>;
|
|
@@ -7,6 +8,5 @@ export declare function showEntity(entityName: string): Promise<any>;
|
|
|
7
8
|
export declare function callStoredProcedure(storedProcedure: any, elements: any): Promise<any>;
|
|
8
9
|
export declare function timezoneMiddleware(req: Request, res: Response, next: NextFunction): void;
|
|
9
10
|
export declare function getTimeZone(): string;
|
|
10
|
-
export declare const getRepositoryByEntity: <T extends ObjectLiteral>(entity: EntityTarget<T>) => Promise<Repository<T> &
|
|
11
|
-
|
|
12
|
-
}>;
|
|
11
|
+
export declare const getRepositoryByEntity: <T extends ObjectLiteral>(entity: EntityTarget<T>) => Promise<Repository<T> & CustomRepository<T>>;
|
|
12
|
+
export declare const createCustomRepository: <T extends ObjectLiteral>(entity: EntityTarget<T>, dataSource: DataSource) => Repository<T> & CustomRepository<T>;
|
package/dist/index.js
CHANGED
|
@@ -50,12 +50,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.getRepositoryByEntity = exports.getTimeZone = exports.timezoneMiddleware = exports.callStoredProcedure = exports.showEntity = exports.showEntityNameEntity = exports.createDataBaseSource = void 0;
|
|
53
|
+
exports.createCustomRepository = exports.getRepositoryByEntity = exports.getTimeZone = exports.timezoneMiddleware = exports.callStoredProcedure = exports.showEntity = exports.showEntityNameEntity = exports.createDataBaseSource = void 0;
|
|
54
54
|
var async_hooks_1 = require("async_hooks");
|
|
55
55
|
var dotenv_1 = require("dotenv");
|
|
56
56
|
var path_1 = require("path");
|
|
57
57
|
var typeorm_1 = require("typeorm");
|
|
58
|
-
var
|
|
58
|
+
var _1 = require(".");
|
|
59
59
|
__exportStar(require("./entities.views.routes"), exports);
|
|
60
60
|
var asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
61
61
|
var connection = null;
|
|
@@ -171,44 +171,24 @@ function getTimeZone() {
|
|
|
171
171
|
return (_a = store === null || store === void 0 ? void 0 : store.get('timezone')) !== null && _a !== void 0 ? _a : 'UTC';
|
|
172
172
|
}
|
|
173
173
|
exports.getTimeZone = getTimeZone;
|
|
174
|
-
// Función para obtener repositorios personalizados
|
|
175
|
-
// export async function getRepositoryByName(repositoryName: string) {
|
|
176
|
-
// if (!connection) {
|
|
177
|
-
// connection = createDataBaseSource()
|
|
178
|
-
// await connection.initialize()
|
|
179
|
-
// }
|
|
180
|
-
// switch (repositoryName) {
|
|
181
|
-
// case 'VerifyLocalRepository':
|
|
182
|
-
// return connection.getCustomRepository(VerifyLocalRepository)
|
|
183
|
-
// // return getCustomRepository(VerifyLocalRepository)
|
|
184
|
-
// default:
|
|
185
|
-
// return null
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
174
|
var getRepositoryByEntity = function (entity) { return __awaiter(void 0, void 0, void 0, function () {
|
|
189
|
-
var dataSource;
|
|
190
175
|
return __generator(this, function (_a) {
|
|
191
176
|
switch (_a.label) {
|
|
192
177
|
case 0:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return [4 /*yield*/,
|
|
178
|
+
if (!!connection) return [3 /*break*/, 2];
|
|
179
|
+
connection = createDataBaseSource();
|
|
180
|
+
return [4 /*yield*/, connection.initialize()];
|
|
196
181
|
case 1:
|
|
197
182
|
_a.sent();
|
|
198
183
|
_a.label = 2;
|
|
199
|
-
case 2: return [2 /*return*/, (0,
|
|
184
|
+
case 2: return [2 /*return*/, (0, exports.createCustomRepository)(entity, connection)];
|
|
200
185
|
}
|
|
201
186
|
});
|
|
202
187
|
}); };
|
|
203
188
|
exports.getRepositoryByEntity = getRepositoryByEntity;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// super(target, dataSource.manager);
|
|
211
|
-
// }
|
|
212
|
-
// }
|
|
213
|
-
// return new CustomRepository(entity, dataSource);
|
|
214
|
-
// }
|
|
189
|
+
var createCustomRepository = function (entity, dataSource) {
|
|
190
|
+
return dataSource
|
|
191
|
+
.getRepository(entity)
|
|
192
|
+
.extend(new _1.CustomRepository(entity, dataSource));
|
|
193
|
+
};
|
|
194
|
+
exports.createCustomRepository = createCustomRepository;
|
package/package.json
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
3
|
+
export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
4
|
+
constructor(target: EntityTarget<T>, dataSource: DataSource) {
|
|
5
|
+
super(target, dataSource.manager)
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
async getVerifyLocals(
|
|
5
9
|
status: number | null,
|
|
6
10
|
page: number,
|
|
7
11
|
pageSize: number,
|
|
8
12
|
filters: any
|
|
9
13
|
) {
|
|
10
|
-
const queryBuilder = this.createQueryBuilder('
|
|
14
|
+
const queryBuilder = this.createQueryBuilder('entity')
|
|
11
15
|
.skip((page - 1) * pageSize)
|
|
12
16
|
.take(pageSize)
|
|
13
17
|
|
|
14
|
-
// Filtro por estado si está definido
|
|
15
18
|
if (status !== null && status >= 0) {
|
|
16
|
-
queryBuilder.andWhere('
|
|
19
|
+
queryBuilder.andWhere('entity.status = :status', { status })
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
// Filtro global que busca en múltiples campos
|
|
20
22
|
if (filters['global'] && filters['global'].value) {
|
|
21
23
|
const globalValue = `%${filters['global'].value}%`
|
|
22
24
|
queryBuilder.andWhere(
|
|
23
|
-
'(JSON_EXTRACT(
|
|
24
|
-
'OR JSON_EXTRACT(
|
|
25
|
-
'OR JSON_EXTRACT(
|
|
26
|
-
'OR
|
|
25
|
+
'(JSON_EXTRACT(entity.local_information, "$.name") LIKE :globalValue ' +
|
|
26
|
+
'OR JSON_EXTRACT(entity.local_information, "$.square.address") LIKE :globalValue ' +
|
|
27
|
+
'OR JSON_EXTRACT(entity.local_information, "$.address.formatted_address") LIKE :globalValue ' +
|
|
28
|
+
'OR entity.status LIKE :globalValue)',
|
|
27
29
|
{ globalValue }
|
|
28
30
|
)
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
// Filtros específicos de columnas
|
|
32
33
|
Object.keys(filters).forEach((key) => {
|
|
33
34
|
if (key !== 'global' && filters[key].constraints) {
|
|
34
35
|
const filter = filters[key]
|
|
@@ -43,7 +44,7 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
43
44
|
switch (matchMode) {
|
|
44
45
|
case 'startsWith':
|
|
45
46
|
queryBuilder.andWhere(
|
|
46
|
-
`JSON_EXTRACT(
|
|
47
|
+
`JSON_EXTRACT(entity.${
|
|
47
48
|
key.split('.')[0]
|
|
48
49
|
}, "${jsonPath}") LIKE :${key}`,
|
|
49
50
|
{
|
|
@@ -53,7 +54,7 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
53
54
|
break
|
|
54
55
|
case 'contains':
|
|
55
56
|
queryBuilder.andWhere(
|
|
56
|
-
`JSON_EXTRACT(
|
|
57
|
+
`JSON_EXTRACT(entity.${
|
|
57
58
|
key.split('.')[0]
|
|
58
59
|
}, "${jsonPath}") LIKE :${key}`,
|
|
59
60
|
{
|
|
@@ -63,7 +64,7 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
63
64
|
break
|
|
64
65
|
case 'equals':
|
|
65
66
|
queryBuilder.andWhere(
|
|
66
|
-
`JSON_EXTRACT(
|
|
67
|
+
`JSON_EXTRACT(entity.${
|
|
67
68
|
key.split('.')[0]
|
|
68
69
|
}, "${jsonPath}") = :${key}`,
|
|
69
70
|
{
|
|
@@ -73,7 +74,7 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
73
74
|
break
|
|
74
75
|
case 'dateIs':
|
|
75
76
|
queryBuilder.andWhere(
|
|
76
|
-
`DATE(JSON_EXTRACT(
|
|
77
|
+
`DATE(JSON_EXTRACT(entity.${
|
|
77
78
|
key.split('.')[0]
|
|
78
79
|
}, "${jsonPath}")) = :${key}`,
|
|
79
80
|
{
|
|
@@ -81,7 +82,6 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
81
82
|
}
|
|
82
83
|
)
|
|
83
84
|
break
|
|
84
|
-
// Agregar otros modos de coincidencia según sea necesario
|
|
85
85
|
default:
|
|
86
86
|
break
|
|
87
87
|
}
|
|
@@ -99,14 +99,8 @@ class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
|
99
99
|
totalPages: Math.ceil(total / pageSize),
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
}
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
dataSource: DataSource
|
|
107
|
-
): Repository<T> & { getVerifyLocals: Function } => {
|
|
108
|
-
const baseRepository = dataSource.getRepository(entity)
|
|
109
|
-
return baseRepository.extend(CustomRepository.prototype) as Repository<T> & {
|
|
110
|
-
getVerifyLocals: Function
|
|
103
|
+
async anyOtherRepository(args: any) {
|
|
104
|
+
// Implementa otro método personalizado aquí
|
|
111
105
|
}
|
|
112
106
|
}
|
|
@@ -42,3 +42,5 @@ export { BusinessType } from './entities/BusinessType'
|
|
|
42
42
|
export { AuthenticationCredential } from './entities/AuthenticationCredential'
|
|
43
43
|
export { PosSystem } from './entities/PosSystem'
|
|
44
44
|
export { VerifyLocal } from './entities/VerifyLocal'
|
|
45
|
+
|
|
46
|
+
export { CustomRepository } from './CustomRepository'
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { NextFunction, Request, Response } from 'express'
|
|
|
4
4
|
import { resolve } from 'path'
|
|
5
5
|
import { DataSource, EntityTarget, ObjectLiteral, Repository } from 'typeorm'
|
|
6
6
|
import { IType } from './interfaces'
|
|
7
|
-
import {
|
|
7
|
+
import { CustomRepository } from '.'
|
|
8
8
|
export * from './entities.views.routes'
|
|
9
9
|
|
|
10
10
|
const asyncLocalStorage = new AsyncLocalStorage<Map<string, string>>()
|
|
@@ -106,40 +106,21 @@ export function getTimeZone(): string {
|
|
|
106
106
|
return store?.get('timezone') ?? 'UTC'
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
// Función para obtener repositorios personalizados
|
|
110
|
-
// export async function getRepositoryByName(repositoryName: string) {
|
|
111
|
-
// if (!connection) {
|
|
112
|
-
// connection = createDataBaseSource()
|
|
113
|
-
// await connection.initialize()
|
|
114
|
-
// }
|
|
115
|
-
|
|
116
|
-
// switch (repositoryName) {
|
|
117
|
-
// case 'VerifyLocalRepository':
|
|
118
|
-
// return connection.getCustomRepository(VerifyLocalRepository)
|
|
119
|
-
// // return getCustomRepository(VerifyLocalRepository)
|
|
120
|
-
// default:
|
|
121
|
-
// return null
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
|
|
125
109
|
export const getRepositoryByEntity = async <T extends ObjectLiteral>(
|
|
126
110
|
entity: EntityTarget<T>
|
|
127
|
-
): Promise<Repository<T> &
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await
|
|
111
|
+
): Promise<Repository<T> & CustomRepository<T>> => {
|
|
112
|
+
if (!connection) {
|
|
113
|
+
connection = createDataBaseSource()
|
|
114
|
+
await connection.initialize()
|
|
131
115
|
}
|
|
132
|
-
return createCustomRepository(entity,
|
|
116
|
+
return createCustomRepository(entity, connection)
|
|
133
117
|
}
|
|
134
118
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// }
|
|
144
|
-
// return new CustomRepository(entity, dataSource);
|
|
145
|
-
// }
|
|
119
|
+
export const createCustomRepository = <T extends ObjectLiteral>(
|
|
120
|
+
entity: EntityTarget<T>,
|
|
121
|
+
dataSource: DataSource
|
|
122
|
+
): Repository<T> & CustomRepository<T> => {
|
|
123
|
+
return dataSource
|
|
124
|
+
.getRepository(entity)
|
|
125
|
+
.extend(new CustomRepository(entity, dataSource))
|
|
126
|
+
}
|