test-entity-library-asm 2.2.6 → 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 -2
- package/dist/index.js +8 -42
- package/dist/repositories/VerifyLocalRepository.d.ts +4 -13
- package/dist/repositories/VerifyLocalRepository.js +12 -7
- package/package.json +1 -1
- package/src/{repositories/VerifyLocalRepository.ts → CustomRepository.ts} +17 -20
- package/src/entities.views.routes.ts +2 -0
- package/src/index.ts +13 -36
|
@@ -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,5 +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
|
-
export declare const createCustomRepository: <T extends ObjectLiteral>(entity: EntityTarget<T>, dataSource: DataSource) => Repository<T>;
|
|
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
|
@@ -1,19 +1,4 @@
|
|
|
1
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
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -70,6 +55,7 @@ var async_hooks_1 = require("async_hooks");
|
|
|
70
55
|
var dotenv_1 = require("dotenv");
|
|
71
56
|
var path_1 = require("path");
|
|
72
57
|
var typeorm_1 = require("typeorm");
|
|
58
|
+
var _1 = require(".");
|
|
73
59
|
__exportStar(require("./entities.views.routes"), exports);
|
|
74
60
|
var asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
75
61
|
var connection = null;
|
|
@@ -185,44 +171,24 @@ function getTimeZone() {
|
|
|
185
171
|
return (_a = store === null || store === void 0 ? void 0 : store.get('timezone')) !== null && _a !== void 0 ? _a : 'UTC';
|
|
186
172
|
}
|
|
187
173
|
exports.getTimeZone = getTimeZone;
|
|
188
|
-
// Función para obtener repositorios personalizados
|
|
189
|
-
// export async function getRepositoryByName(repositoryName: string) {
|
|
190
|
-
// if (!connection) {
|
|
191
|
-
// connection = createDataBaseSource()
|
|
192
|
-
// await connection.initialize()
|
|
193
|
-
// }
|
|
194
|
-
// switch (repositoryName) {
|
|
195
|
-
// case 'VerifyLocalRepository':
|
|
196
|
-
// return connection.getCustomRepository(VerifyLocalRepository)
|
|
197
|
-
// // return getCustomRepository(VerifyLocalRepository)
|
|
198
|
-
// default:
|
|
199
|
-
// return null
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
174
|
var getRepositoryByEntity = function (entity) { return __awaiter(void 0, void 0, void 0, function () {
|
|
203
|
-
var dataSource;
|
|
204
175
|
return __generator(this, function (_a) {
|
|
205
176
|
switch (_a.label) {
|
|
206
177
|
case 0:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return [4 /*yield*/,
|
|
178
|
+
if (!!connection) return [3 /*break*/, 2];
|
|
179
|
+
connection = createDataBaseSource();
|
|
180
|
+
return [4 /*yield*/, connection.initialize()];
|
|
210
181
|
case 1:
|
|
211
182
|
_a.sent();
|
|
212
183
|
_a.label = 2;
|
|
213
|
-
case 2: return [2 /*return*/, (0, exports.createCustomRepository)(entity,
|
|
184
|
+
case 2: return [2 /*return*/, (0, exports.createCustomRepository)(entity, connection)];
|
|
214
185
|
}
|
|
215
186
|
});
|
|
216
187
|
}); };
|
|
217
188
|
exports.getRepositoryByEntity = getRepositoryByEntity;
|
|
218
189
|
var createCustomRepository = function (entity, dataSource) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return _super.call(this, target, dataSource.manager) || this;
|
|
223
|
-
}
|
|
224
|
-
return CustomRepository;
|
|
225
|
-
}(typeorm_1.Repository));
|
|
226
|
-
return new CustomRepository(entity, dataSource);
|
|
190
|
+
return dataSource
|
|
191
|
+
.getRepository(entity)
|
|
192
|
+
.extend(new _1.CustomRepository(entity, dataSource));
|
|
227
193
|
};
|
|
228
194
|
exports.createCustomRepository = createCustomRepository;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
getVerifyLocals(status: number | null, page: number, pageSize: number, filters: any): Promise<{
|
|
6
|
-
data: VerifyLocal[];
|
|
7
|
-
total: number;
|
|
8
|
-
page: number;
|
|
9
|
-
pageSize: number;
|
|
10
|
-
totalPages: number;
|
|
11
|
-
}>;
|
|
12
|
-
}
|
|
13
|
-
export default VerifyLocalRepository;
|
|
1
|
+
import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm';
|
|
2
|
+
export declare const createCustomRepository: <T extends ObjectLiteral>(entity: EntityTarget<T>, dataSource: DataSource) => Repository<T> & {
|
|
3
|
+
getVerifyLocals: Function;
|
|
4
|
+
};
|
|
@@ -51,13 +51,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.createCustomRepository = void 0;
|
|
54
55
|
var typeorm_1 = require("typeorm");
|
|
55
|
-
var
|
|
56
|
-
__extends(
|
|
57
|
-
function
|
|
58
|
-
return _super.
|
|
56
|
+
var CustomRepository = /** @class */ (function (_super) {
|
|
57
|
+
__extends(CustomRepository, _super);
|
|
58
|
+
function CustomRepository() {
|
|
59
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
CustomRepository.prototype.getVerifyLocals = function (status, page, pageSize, filters) {
|
|
61
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
63
|
var queryBuilder, globalValue, _a, data, total;
|
|
63
64
|
return __generator(this, function (_b) {
|
|
@@ -132,6 +133,10 @@ var VerifyLocalRepository = /** @class */ (function (_super) {
|
|
|
132
133
|
});
|
|
133
134
|
});
|
|
134
135
|
};
|
|
135
|
-
return
|
|
136
|
+
return CustomRepository;
|
|
136
137
|
}(typeorm_1.Repository));
|
|
137
|
-
|
|
138
|
+
var createCustomRepository = function (entity, dataSource) {
|
|
139
|
+
var baseRepository = dataSource.getRepository(entity);
|
|
140
|
+
return baseRepository.extend(CustomRepository.prototype);
|
|
141
|
+
};
|
|
142
|
+
exports.createCustomRepository = createCustomRepository;
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VerifyLocal } from '../entities/VerifyLocal'
|
|
1
|
+
import { DataSource, EntityTarget, Repository, ObjectLiteral } from 'typeorm'
|
|
3
2
|
|
|
4
|
-
class
|
|
5
|
-
constructor(target: EntityTarget<
|
|
3
|
+
export class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
4
|
+
constructor(target: EntityTarget<T>, dataSource: DataSource) {
|
|
6
5
|
super(target, dataSource.manager)
|
|
7
6
|
}
|
|
8
7
|
|
|
@@ -12,28 +11,25 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
12
11
|
pageSize: number,
|
|
13
12
|
filters: any
|
|
14
13
|
) {
|
|
15
|
-
const queryBuilder = this.createQueryBuilder('
|
|
14
|
+
const queryBuilder = this.createQueryBuilder('entity')
|
|
16
15
|
.skip((page - 1) * pageSize)
|
|
17
16
|
.take(pageSize)
|
|
18
17
|
|
|
19
|
-
// Filtro por estado si está definido
|
|
20
18
|
if (status !== null && status >= 0) {
|
|
21
|
-
queryBuilder.andWhere('
|
|
19
|
+
queryBuilder.andWhere('entity.status = :status', { status })
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
// Filtro global que busca en múltiples campos
|
|
25
22
|
if (filters['global'] && filters['global'].value) {
|
|
26
23
|
const globalValue = `%${filters['global'].value}%`
|
|
27
24
|
queryBuilder.andWhere(
|
|
28
|
-
'(JSON_EXTRACT(
|
|
29
|
-
'OR JSON_EXTRACT(
|
|
30
|
-
'OR JSON_EXTRACT(
|
|
31
|
-
'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)',
|
|
32
29
|
{ globalValue }
|
|
33
30
|
)
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
// Filtros específicos de columnas
|
|
37
33
|
Object.keys(filters).forEach((key) => {
|
|
38
34
|
if (key !== 'global' && filters[key].constraints) {
|
|
39
35
|
const filter = filters[key]
|
|
@@ -48,7 +44,7 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
48
44
|
switch (matchMode) {
|
|
49
45
|
case 'startsWith':
|
|
50
46
|
queryBuilder.andWhere(
|
|
51
|
-
`JSON_EXTRACT(
|
|
47
|
+
`JSON_EXTRACT(entity.${
|
|
52
48
|
key.split('.')[0]
|
|
53
49
|
}, "${jsonPath}") LIKE :${key}`,
|
|
54
50
|
{
|
|
@@ -58,7 +54,7 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
58
54
|
break
|
|
59
55
|
case 'contains':
|
|
60
56
|
queryBuilder.andWhere(
|
|
61
|
-
`JSON_EXTRACT(
|
|
57
|
+
`JSON_EXTRACT(entity.${
|
|
62
58
|
key.split('.')[0]
|
|
63
59
|
}, "${jsonPath}") LIKE :${key}`,
|
|
64
60
|
{
|
|
@@ -68,7 +64,7 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
68
64
|
break
|
|
69
65
|
case 'equals':
|
|
70
66
|
queryBuilder.andWhere(
|
|
71
|
-
`JSON_EXTRACT(
|
|
67
|
+
`JSON_EXTRACT(entity.${
|
|
72
68
|
key.split('.')[0]
|
|
73
69
|
}, "${jsonPath}") = :${key}`,
|
|
74
70
|
{
|
|
@@ -78,7 +74,7 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
78
74
|
break
|
|
79
75
|
case 'dateIs':
|
|
80
76
|
queryBuilder.andWhere(
|
|
81
|
-
`DATE(JSON_EXTRACT(
|
|
77
|
+
`DATE(JSON_EXTRACT(entity.${
|
|
82
78
|
key.split('.')[0]
|
|
83
79
|
}, "${jsonPath}")) = :${key}`,
|
|
84
80
|
{
|
|
@@ -86,7 +82,6 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
86
82
|
}
|
|
87
83
|
)
|
|
88
84
|
break
|
|
89
|
-
// Agregar otros modos de coincidencia según sea necesario
|
|
90
85
|
default:
|
|
91
86
|
break
|
|
92
87
|
}
|
|
@@ -104,6 +99,8 @@ class VerifyLocalRepository extends Repository<VerifyLocal> {
|
|
|
104
99
|
totalPages: Math.ceil(total / pageSize),
|
|
105
100
|
}
|
|
106
101
|
}
|
|
107
|
-
}
|
|
108
102
|
|
|
109
|
-
|
|
103
|
+
async anyOtherRepository(args: any) {
|
|
104
|
+
// Implementa otro método personalizado aquí
|
|
105
|
+
}
|
|
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
|
@@ -2,13 +2,9 @@ import { AsyncLocalStorage } from 'async_hooks'
|
|
|
2
2
|
import { config } from 'dotenv'
|
|
3
3
|
import { NextFunction, Request, Response } from 'express'
|
|
4
4
|
import { resolve } from 'path'
|
|
5
|
-
import {
|
|
6
|
-
DataSource,
|
|
7
|
-
EntityTarget,
|
|
8
|
-
ObjectLiteral,
|
|
9
|
-
Repository
|
|
10
|
-
} from 'typeorm'
|
|
5
|
+
import { DataSource, EntityTarget, ObjectLiteral, Repository } from 'typeorm'
|
|
11
6
|
import { IType } from './interfaces'
|
|
7
|
+
import { CustomRepository } from '.'
|
|
12
8
|
export * from './entities.views.routes'
|
|
13
9
|
|
|
14
10
|
const asyncLocalStorage = new AsyncLocalStorage<Map<string, string>>()
|
|
@@ -110,40 +106,21 @@ export function getTimeZone(): string {
|
|
|
110
106
|
return store?.get('timezone') ?? 'UTC'
|
|
111
107
|
}
|
|
112
108
|
|
|
113
|
-
// Función para obtener repositorios personalizados
|
|
114
|
-
// export async function getRepositoryByName(repositoryName: string) {
|
|
115
|
-
// if (!connection) {
|
|
116
|
-
// connection = createDataBaseSource()
|
|
117
|
-
// await connection.initialize()
|
|
118
|
-
// }
|
|
119
|
-
|
|
120
|
-
// switch (repositoryName) {
|
|
121
|
-
// case 'VerifyLocalRepository':
|
|
122
|
-
// return connection.getCustomRepository(VerifyLocalRepository)
|
|
123
|
-
// // return getCustomRepository(VerifyLocalRepository)
|
|
124
|
-
// default:
|
|
125
|
-
// return null
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
|
-
|
|
129
109
|
export const getRepositoryByEntity = async <T extends ObjectLiteral>(
|
|
130
110
|
entity: EntityTarget<T>
|
|
131
|
-
): Promise<Repository<T>> => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await
|
|
111
|
+
): Promise<Repository<T> & CustomRepository<T>> => {
|
|
112
|
+
if (!connection) {
|
|
113
|
+
connection = createDataBaseSource()
|
|
114
|
+
await connection.initialize()
|
|
135
115
|
}
|
|
136
|
-
return createCustomRepository(entity,
|
|
137
|
-
}
|
|
116
|
+
return createCustomRepository(entity, connection)
|
|
117
|
+
}
|
|
138
118
|
|
|
139
119
|
export const createCustomRepository = <T extends ObjectLiteral>(
|
|
140
120
|
entity: EntityTarget<T>,
|
|
141
121
|
dataSource: DataSource
|
|
142
|
-
): Repository<T> => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return new CustomRepository(entity, dataSource);
|
|
149
|
-
}
|
|
122
|
+
): Repository<T> & CustomRepository<T> => {
|
|
123
|
+
return dataSource
|
|
124
|
+
.getRepository(entity)
|
|
125
|
+
.extend(new CustomRepository(entity, dataSource))
|
|
126
|
+
}
|