@ubs-platform/crud-base 1.4.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.
- package/base-crud-controller.d.ts +53 -0
- package/base-crud-controller.js +295 -0
- package/base-crud-controller.js.map +1 -0
- package/base-crud-klass.d.ts +2 -0
- package/base-crud-klass.js +7 -0
- package/base-crud-klass.js.map +1 -0
- package/base-crud-service.d.ts +34 -0
- package/base-crud-service.js +127 -0
- package/base-crud-service.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +23 -0
- package/index.js.map +1 -0
- package/package.json +1 -0
- package/repository-wrap-mongo.d.ts +18 -0
- package/repository-wrap-mongo.js +39 -0
- package/repository-wrap-mongo.js.map +1 -0
- package/repository-wrap.d.ts +14 -0
- package/repository-wrap.js +3 -0
- package/repository-wrap.js.map +1 -0
- package/util/search.util.d.ts +7 -0
- package/util/search.util.js +32 -0
- package/util/search.util.js.map +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BaseCrudService } from '@ubs-platform/crud-base';
|
|
2
|
+
import { SearchRequest } from '@ubs-platform/crud-base-common';
|
|
3
|
+
import { UserAuthBackendDTO } from '@ubs-platform/users-common';
|
|
4
|
+
import { Optional } from '@ubs-platform/crud-base-common/utils';
|
|
5
|
+
export type RoleAuthorizationConfigKey = 'EDIT' | 'ADD' | 'REMOVE' | 'GETALL' | 'GETID' | 'ALL';
|
|
6
|
+
export type RoleAuthorizationDetailed = {
|
|
7
|
+
needsAuthenticated?: boolean;
|
|
8
|
+
roles?: string[];
|
|
9
|
+
};
|
|
10
|
+
export type RoleAuthorization = null | undefined | boolean | RoleAuthorizationDetailed;
|
|
11
|
+
export interface ControllerConfiguration {
|
|
12
|
+
authorization: {
|
|
13
|
+
[key in RoleAuthorizationConfigKey]?: RoleAuthorization;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function CrudControllerConfig(r: ControllerConfiguration): (target: Function) => void;
|
|
17
|
+
export declare class BaseCrudController<MODEL, ID, INPUT, OUTPUT, SEARCH> {
|
|
18
|
+
servicex: BaseCrudService<MODEL, ID, INPUT, OUTPUT, SEARCH>;
|
|
19
|
+
constructor(servicex: BaseCrudService<MODEL, ID, INPUT, OUTPUT, SEARCH>);
|
|
20
|
+
fetchAll(s?: SEARCH, user?: UserAuthBackendDTO): Promise<OUTPUT[]>;
|
|
21
|
+
search(s: SEARCH & SearchRequest, user?: UserAuthBackendDTO): Promise<import("@ubs-platform/crud-base-common").SearchResult<OUTPUT>>;
|
|
22
|
+
fetchOne({ id }: {
|
|
23
|
+
id: any;
|
|
24
|
+
}, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
25
|
+
add(body: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
26
|
+
edit(body: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
27
|
+
remove({ id }: {
|
|
28
|
+
id: any;
|
|
29
|
+
}, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
30
|
+
checkUser(operation: 'ADD' | 'EDIT' | 'REMOVE' | 'GETALL' | 'GETID', user: Optional<UserAuthBackendDTO>, queriesAndPaths: Optional<{
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}>, body: Optional<INPUT>): Promise<void>;
|
|
33
|
+
manipulateSearch(user: Optional<UserAuthBackendDTO>, queriesAndPaths: Optional<SEARCH>): Promise<any>;
|
|
34
|
+
}
|
|
35
|
+
export declare const BaseCrudControllerGenerator: <MODEL, ID, INPUT, OUTPUT, SEARCH>(r: ControllerConfiguration) => {
|
|
36
|
+
new (servicex: BaseCrudService<MODEL, ID, INPUT, OUTPUT, SEARCH>): {
|
|
37
|
+
servicex: BaseCrudService<MODEL, ID, INPUT, OUTPUT, SEARCH>;
|
|
38
|
+
fetchAll(s?: SEARCH, user?: UserAuthBackendDTO): Promise<OUTPUT[]>;
|
|
39
|
+
search(s: SEARCH & SearchRequest, user?: UserAuthBackendDTO): Promise<import("@ubs-platform/crud-base-common").SearchResult<OUTPUT>>;
|
|
40
|
+
fetchOne({ id }: {
|
|
41
|
+
id: any;
|
|
42
|
+
}, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
43
|
+
add(body: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
44
|
+
edit(body: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
45
|
+
remove({ id }: {
|
|
46
|
+
id: any;
|
|
47
|
+
}, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
48
|
+
checkUser(operation: "ADD" | "EDIT" | "REMOVE" | "GETALL" | "GETID", user: Optional<UserAuthBackendDTO>, queriesAndPaths: Optional<{
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}>, body: Optional<INPUT>): Promise<void>;
|
|
51
|
+
manipulateSearch(user: Optional<UserAuthBackendDTO>, queriesAndPaths: Optional<SEARCH>): Promise<any>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,295 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BaseCrudControllerGenerator = exports.BaseCrudController = void 0;
|
|
16
|
+
exports.CrudControllerConfig = CrudControllerConfig;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const users_microservice_helper_1 = require("@ubs-platform/users-microservice-helper");
|
|
19
|
+
const users_roles_1 = require("@ubs-platform/users-roles");
|
|
20
|
+
const findExistAuth = (field, r) => {
|
|
21
|
+
let a = r.authorization[field] || r.authorization.ALL;
|
|
22
|
+
if (a === true) {
|
|
23
|
+
return { needsAuthenticated: true, roles: [] };
|
|
24
|
+
}
|
|
25
|
+
else if (!a) {
|
|
26
|
+
return { needsAuthenticated: false, roles: [] };
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const detailed = a;
|
|
30
|
+
if (detailed.needsAuthenticated == null) {
|
|
31
|
+
detailed.needsAuthenticated = !!(detailed.roles?.length);
|
|
32
|
+
}
|
|
33
|
+
return detailed;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function CrudControllerConfig(r) {
|
|
37
|
+
return function (target) {
|
|
38
|
+
const proto = target.prototype;
|
|
39
|
+
const baseProto = Object.getPrototypeOf(proto);
|
|
40
|
+
const baseClass = baseProto.constructor;
|
|
41
|
+
const methodRoles = [
|
|
42
|
+
['fetchAll', 'GETALL'],
|
|
43
|
+
['search', 'GETALL'],
|
|
44
|
+
['fetchOne', 'GETID'],
|
|
45
|
+
['add', 'ADD'],
|
|
46
|
+
['edit', 'EDIT'],
|
|
47
|
+
['remove', 'REMOVE'],
|
|
48
|
+
];
|
|
49
|
+
for (const [methodName, role] of methodRoles) {
|
|
50
|
+
let searchProto = baseProto;
|
|
51
|
+
let descriptor;
|
|
52
|
+
while (searchProto && searchProto !== Object.prototype) {
|
|
53
|
+
descriptor = Object.getOwnPropertyDescriptor(searchProto, methodName);
|
|
54
|
+
if (descriptor)
|
|
55
|
+
break;
|
|
56
|
+
searchProto = Object.getPrototypeOf(searchProto);
|
|
57
|
+
}
|
|
58
|
+
if (!descriptor || typeof descriptor.value !== 'function')
|
|
59
|
+
continue;
|
|
60
|
+
const originalFn = descriptor.value;
|
|
61
|
+
const wrappedFn = async function (...args) {
|
|
62
|
+
return originalFn.apply(this, args);
|
|
63
|
+
};
|
|
64
|
+
for (const key of Reflect.getMetadataKeys(originalFn)) {
|
|
65
|
+
Reflect.defineMetadata(key, Reflect.getMetadata(key, originalFn), wrappedFn);
|
|
66
|
+
}
|
|
67
|
+
Object.defineProperty(proto, methodName, { ...descriptor, value: wrappedFn });
|
|
68
|
+
for (const key of Reflect.getMetadataKeys(baseClass, methodName)) {
|
|
69
|
+
Reflect.defineMetadata(key, Reflect.getMetadata(key, baseClass, methodName), target, methodName);
|
|
70
|
+
}
|
|
71
|
+
const authorization = findExistAuth(role, r);
|
|
72
|
+
const guards = [
|
|
73
|
+
authorization.needsAuthenticated ? users_microservice_helper_1.JwtAuthGuard : null,
|
|
74
|
+
authorization.needsAuthenticated && authorization.roles?.length ? users_roles_1.RolesGuard : null,
|
|
75
|
+
].filter(Boolean);
|
|
76
|
+
const newDescriptor = Object.getOwnPropertyDescriptor(proto, methodName);
|
|
77
|
+
if (guards.length) {
|
|
78
|
+
(0, common_1.UseGuards)(...guards)(proto, methodName, newDescriptor);
|
|
79
|
+
}
|
|
80
|
+
(0, users_roles_1.Roles)(authorization.roles || [])(proto, methodName, newDescriptor);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
class BaseCrudController {
|
|
85
|
+
constructor(servicex) {
|
|
86
|
+
this.servicex = servicex;
|
|
87
|
+
}
|
|
88
|
+
async fetchAll(s, user) {
|
|
89
|
+
await this.checkUser('GETALL', user, s, null);
|
|
90
|
+
const manipulatedSearch = await this.manipulateSearch(user, s);
|
|
91
|
+
return await this.servicex.fetchAll(manipulatedSearch, user);
|
|
92
|
+
}
|
|
93
|
+
async search(s, user) {
|
|
94
|
+
await this.checkUser('GETALL', user, s, null);
|
|
95
|
+
const manipulatedSearch = await this.manipulateSearch(user, s);
|
|
96
|
+
return await this.servicex.searchPagination(manipulatedSearch, user);
|
|
97
|
+
}
|
|
98
|
+
async fetchOne({ id }, user) {
|
|
99
|
+
await this.checkUser('GETID', user, { id }, null);
|
|
100
|
+
return await this.servicex.fetchOne(id, user);
|
|
101
|
+
}
|
|
102
|
+
async add(body, user) {
|
|
103
|
+
await this.checkUser('ADD', user, null, body);
|
|
104
|
+
return await this.servicex.create(body, user);
|
|
105
|
+
}
|
|
106
|
+
async edit(body, user) {
|
|
107
|
+
if (this.servicex.getIdFieldNameFromInput(body) == null) {
|
|
108
|
+
throw new common_1.NotFoundException();
|
|
109
|
+
}
|
|
110
|
+
await this.checkUser('EDIT', user, null, body);
|
|
111
|
+
return await this.servicex.edit(body, user);
|
|
112
|
+
}
|
|
113
|
+
async remove({ id }, user) {
|
|
114
|
+
await this.checkUser('REMOVE', user, { id }, null);
|
|
115
|
+
return await this.servicex.remove(id, user);
|
|
116
|
+
}
|
|
117
|
+
async checkUser(operation, user, queriesAndPaths, body) { }
|
|
118
|
+
async manipulateSearch(user, queriesAndPaths) {
|
|
119
|
+
return queriesAndPaths;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.BaseCrudController = BaseCrudController;
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, common_1.Get)(),
|
|
125
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
126
|
+
__param(0, (0, common_1.Query)()),
|
|
127
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
128
|
+
__metadata("design:type", Function),
|
|
129
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
130
|
+
__metadata("design:returntype", Promise)
|
|
131
|
+
], BaseCrudController.prototype, "fetchAll", null);
|
|
132
|
+
__decorate([
|
|
133
|
+
(0, common_1.Get)('_search'),
|
|
134
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
135
|
+
__param(0, (0, common_1.Query)()),
|
|
136
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], BaseCrudController.prototype, "search", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, common_1.Get)('/:id'),
|
|
143
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
144
|
+
__param(0, (0, common_1.Param)()),
|
|
145
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], BaseCrudController.prototype, "fetchOne", null);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, common_1.Post)(),
|
|
152
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
153
|
+
__param(0, (0, common_1.Body)()),
|
|
154
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
155
|
+
__metadata("design:type", Function),
|
|
156
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
157
|
+
__metadata("design:returntype", Promise)
|
|
158
|
+
], BaseCrudController.prototype, "add", null);
|
|
159
|
+
__decorate([
|
|
160
|
+
(0, common_1.Put)(),
|
|
161
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
162
|
+
__param(0, (0, common_1.Body)()),
|
|
163
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
164
|
+
__metadata("design:type", Function),
|
|
165
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
166
|
+
__metadata("design:returntype", Promise)
|
|
167
|
+
], BaseCrudController.prototype, "edit", null);
|
|
168
|
+
__decorate([
|
|
169
|
+
(0, common_1.Delete)(':id'),
|
|
170
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
171
|
+
__param(0, (0, common_1.Param)()),
|
|
172
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
173
|
+
__metadata("design:type", Function),
|
|
174
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
175
|
+
__metadata("design:returntype", Promise)
|
|
176
|
+
], BaseCrudController.prototype, "remove", null);
|
|
177
|
+
const BaseCrudControllerGenerator = (r) => {
|
|
178
|
+
const RoleConfig = (field) => {
|
|
179
|
+
const authorization = findExistAuth(field, r);
|
|
180
|
+
const guard = (0, common_1.UseGuards)(...[
|
|
181
|
+
authorization.needsAuthenticated ? users_microservice_helper_1.JwtAuthGuard : null,
|
|
182
|
+
authorization.needsAuthenticated && authorization.roles
|
|
183
|
+
? users_roles_1.RolesGuard
|
|
184
|
+
: null,
|
|
185
|
+
].filter((a) => a));
|
|
186
|
+
const roles = (0, users_roles_1.Roles)(authorization.roles);
|
|
187
|
+
return (target, propKey, descriptor) => {
|
|
188
|
+
guard(target, propKey, descriptor);
|
|
189
|
+
roles(target, propKey, descriptor);
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
let service;
|
|
193
|
+
class ControllerClass {
|
|
194
|
+
constructor(servicex) {
|
|
195
|
+
this.servicex = servicex;
|
|
196
|
+
service = servicex;
|
|
197
|
+
}
|
|
198
|
+
async fetchAll(s, user) {
|
|
199
|
+
await this.checkUser('GETALL', user, s, null);
|
|
200
|
+
const manipulatedSearch = await this.manipulateSearch(user, s);
|
|
201
|
+
return await service.fetchAll(manipulatedSearch, user);
|
|
202
|
+
}
|
|
203
|
+
async search(s, user) {
|
|
204
|
+
await this.checkUser('GETALL', user, s, null);
|
|
205
|
+
const manipulatedSearch = await this.manipulateSearch(user, s);
|
|
206
|
+
return await service.searchPagination(manipulatedSearch, user);
|
|
207
|
+
}
|
|
208
|
+
async fetchOne({ id }, user) {
|
|
209
|
+
await this.checkUser('GETID', user, { id }, null);
|
|
210
|
+
return await service.fetchOne(id, user);
|
|
211
|
+
}
|
|
212
|
+
async add(body, user) {
|
|
213
|
+
await this.checkUser('ADD', user, null, body);
|
|
214
|
+
return await service.create(body, user);
|
|
215
|
+
}
|
|
216
|
+
async edit(body, user) {
|
|
217
|
+
if (this.servicex.getIdFieldNameFromInput(body) == null) {
|
|
218
|
+
throw new common_1.NotFoundException();
|
|
219
|
+
}
|
|
220
|
+
await this.checkUser('EDIT', user, null, body);
|
|
221
|
+
return await service.edit(body, user);
|
|
222
|
+
}
|
|
223
|
+
async remove({ id }, user) {
|
|
224
|
+
await this.checkUser('REMOVE', user, { id }, null);
|
|
225
|
+
return await service.remove(id, user);
|
|
226
|
+
}
|
|
227
|
+
async checkUser(operation, user, queriesAndPaths, body) { }
|
|
228
|
+
async manipulateSearch(user, queriesAndPaths) {
|
|
229
|
+
return queriesAndPaths;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
__decorate([
|
|
233
|
+
RoleConfig('GETALL'),
|
|
234
|
+
(0, common_1.Get)(),
|
|
235
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
236
|
+
__param(0, (0, common_1.Query)()),
|
|
237
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
238
|
+
__metadata("design:type", Function),
|
|
239
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
240
|
+
__metadata("design:returntype", Promise)
|
|
241
|
+
], ControllerClass.prototype, "fetchAll", null);
|
|
242
|
+
__decorate([
|
|
243
|
+
RoleConfig('GETALL'),
|
|
244
|
+
(0, common_1.Get)('_search'),
|
|
245
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
246
|
+
__param(0, (0, common_1.Query)()),
|
|
247
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
248
|
+
__metadata("design:type", Function),
|
|
249
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
250
|
+
__metadata("design:returntype", Promise)
|
|
251
|
+
], ControllerClass.prototype, "search", null);
|
|
252
|
+
__decorate([
|
|
253
|
+
(0, common_1.Get)('/:id'),
|
|
254
|
+
RoleConfig('GETID'),
|
|
255
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
256
|
+
__param(0, (0, common_1.Param)()),
|
|
257
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
258
|
+
__metadata("design:type", Function),
|
|
259
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
260
|
+
__metadata("design:returntype", Promise)
|
|
261
|
+
], ControllerClass.prototype, "fetchOne", null);
|
|
262
|
+
__decorate([
|
|
263
|
+
RoleConfig('ADD'),
|
|
264
|
+
(0, common_1.Post)(),
|
|
265
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
266
|
+
__param(0, (0, common_1.Body)()),
|
|
267
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
268
|
+
__metadata("design:type", Function),
|
|
269
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
270
|
+
__metadata("design:returntype", Promise)
|
|
271
|
+
], ControllerClass.prototype, "add", null);
|
|
272
|
+
__decorate([
|
|
273
|
+
RoleConfig('EDIT'),
|
|
274
|
+
(0, common_1.Put)(),
|
|
275
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
276
|
+
__param(0, (0, common_1.Body)()),
|
|
277
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
278
|
+
__metadata("design:type", Function),
|
|
279
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
280
|
+
__metadata("design:returntype", Promise)
|
|
281
|
+
], ControllerClass.prototype, "edit", null);
|
|
282
|
+
__decorate([
|
|
283
|
+
(0, common_1.Delete)(':id'),
|
|
284
|
+
RoleConfig('REMOVE'),
|
|
285
|
+
(0, common_1.UseGuards)(users_microservice_helper_1.UserIntercept),
|
|
286
|
+
__param(0, (0, common_1.Param)()),
|
|
287
|
+
__param(1, (0, users_microservice_helper_1.CurrentUser)()),
|
|
288
|
+
__metadata("design:type", Function),
|
|
289
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
290
|
+
__metadata("design:returntype", Promise)
|
|
291
|
+
], ControllerClass.prototype, "remove", null);
|
|
292
|
+
return ControllerClass;
|
|
293
|
+
};
|
|
294
|
+
exports.BaseCrudControllerGenerator = BaseCrudControllerGenerator;
|
|
295
|
+
//# sourceMappingURL=base-crud-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-crud-controller.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/base-crud-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAkFA,oDAoEC;AAtJD,2CAUwB;AAExB,uFAIiD;AAEjD,2DAA8D;AA8B9D,MAAM,aAAa,GAAG,CAClB,KAAiC,EACjC,CAA0B,EACD,EAAE;IAC3B,IAAI,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC;IACtD,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACb,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACnD,CAAC;SAAM,IAAI,CAAC,CAAC,EAAE,CAAC;QACZ,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC;SAAM,CAAC;QACJ,MAAM,QAAQ,GAAG,CAA8B,CAAC;QAChD,IAAI,QAAQ,CAAC,kBAAkB,IAAI,IAAI,EAAE,CAAC;YACtC,QAAQ,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACL,CAAC,CAAC;AAkBF,SAAgB,oBAAoB,CAAC,CAA0B;IAC3D,OAAO,UAAU,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AAA,uCAAW,GAAE,CAAA;;;;iDAKjB;IAKK;QAHL,IAAA,YAAG,EAAC,MAAM,CAAC;QACX,UAAU,CAAC,OAAO,CAAC;QACnB,IAAA,kBAAS,EAAC,yCAAa,CAAC;QAEpB,WAAA,IAAA,cAAK,GAAE,CAAA;QACP,WAAA,IAAA,uCAAW,GAAE,CAAA;;;;mDAIjB;IAKK;QAHL,UAAU,CAAC,KAAK,CAAC;QACjB,IAAA,aAAI,GAAE;QACN,IAAA,kBAAS,EAAC,yCAAa,CAAC;QAEpB,WAAA,IAAA,aAAI,GAAE,CAAA;QACN,WAAA,IAAA,uCAAW,GAAE,CAAA;;;;8CAIjB;IAKK;QAHL,UAAU,CAAC,MAAM,CAAC;QAClB,IAAA,YAAG,GAAE;QACL,IAAA,kBAAS,EAAC,yCAAa,CAAC;QAEpB,WAAA,IAAA,aAAI,GAAE,CAAA;QACN,WAAA,IAAA,uCAAW,GAAE,CAAA;;;;+CAOjB;IAKK;QAHL,IAAA,eAAM,EAAC,KAAK,CAAC;QACb,UAAU,CAAC,QAAQ,CAAC;QACpB,IAAA,kBAAS,EAAC,yCAAa,CAAC;QAEpB,WAAA,IAAA,cAAK,GAAE,CAAA;QACP,WAAA,IAAA,uCAAW,GAAE,CAAA;;;;iDAIjB;IAiBL,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAC;AAnHW,QAAA,2BAA2B,+BAmHtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-crud-klass.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/base-crud-klass.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAa;CAAG;AAA7B,sCAA6B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SearchRequest, SearchResult } from '@ubs-platform/crud-base-common';
|
|
2
|
+
import { FilterQuery } from 'mongoose';
|
|
3
|
+
import { BaseCrudKlass } from './base-crud-klass';
|
|
4
|
+
import { UserAuthBackendDTO } from '@ubs-platform/users-common';
|
|
5
|
+
import { IRepositoryWrap } from './repository-wrap';
|
|
6
|
+
import { CacheManagerService } from '@ubs-platform/cache-manager';
|
|
7
|
+
export declare abstract class BaseCrudService<MODEL, ID, INPUT, OUTPUT, SEARCH> extends BaseCrudKlass {
|
|
8
|
+
m: IRepositoryWrap<MODEL, ID, any>;
|
|
9
|
+
protected readonly isCacheEnabled = true;
|
|
10
|
+
protected readonly cacheLiveTimeMs = 3000;
|
|
11
|
+
protected readonly cacheKeyPrefix: string;
|
|
12
|
+
protected readonly cacheManager?: CacheManagerService;
|
|
13
|
+
constructor(m: IRepositoryWrap<MODEL, ID, any>);
|
|
14
|
+
abstract generateNewModel(): MODEL;
|
|
15
|
+
abstract getIdFieldNameFromInput(i: INPUT): ID;
|
|
16
|
+
abstract getIdFieldNameFromModel(i: MODEL): ID;
|
|
17
|
+
abstract toOutput(m: MODEL): Promise<OUTPUT> | OUTPUT;
|
|
18
|
+
abstract moveIntoModel(model: MODEL, i: INPUT): Promise<MODEL> | MODEL;
|
|
19
|
+
abstract searchParams(s?: Partial<SEARCH>, u?: UserAuthBackendDTO): Promise<FilterQuery<MODEL>>;
|
|
20
|
+
convertAndReturnTheList(list: MODEL[], user?: UserAuthBackendDTO): Promise<OUTPUT[]>;
|
|
21
|
+
searchPagination(searchAndPagination?: SEARCH & SearchRequest, user?: UserAuthBackendDTO): Promise<SearchResult<OUTPUT>>;
|
|
22
|
+
fetchAll(s?: Partial<SEARCH>, user?: UserAuthBackendDTO): Promise<OUTPUT[]>;
|
|
23
|
+
fetchOne(id: ID, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
24
|
+
create(input: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
25
|
+
edit(input: INPUT, user?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
26
|
+
remove(id: ID, ruser?: UserAuthBackendDTO): Promise<OUTPUT>;
|
|
27
|
+
protected withShortCache<T>(key: string, cb: () => Promise<T>): Promise<T>;
|
|
28
|
+
protected buildCacheKey(method: string, ...parts: unknown[]): string;
|
|
29
|
+
protected serializeCachePart(part: unknown): string;
|
|
30
|
+
protected invalidateSelfCache(): void;
|
|
31
|
+
afterCreate(m: OUTPUT, input: INPUT, user?: UserAuthBackendDTO): Promise<void>;
|
|
32
|
+
beforeCreateOrEdit(model: MODEL, input: INPUT, mode: 'EDIT' | 'CREATE', user?: UserAuthBackendDTO): Promise<void>;
|
|
33
|
+
beforeRemove(model: MODEL, user?: UserAuthBackendDTO): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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.BaseCrudService = void 0;
|
|
13
|
+
const base_crud_klass_1 = require("./base-crud-klass");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const cache_manager_1 = require("@ubs-platform/cache-manager");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
class BaseCrudService extends base_crud_klass_1.BaseCrudKlass {
|
|
18
|
+
constructor(m) {
|
|
19
|
+
super();
|
|
20
|
+
this.m = m;
|
|
21
|
+
this.isCacheEnabled = true;
|
|
22
|
+
this.cacheLiveTimeMs = 3000;
|
|
23
|
+
const klassName = this.constructor?.name?.trim();
|
|
24
|
+
this.cacheKeyPrefix = klassName
|
|
25
|
+
? `crud:${klassName}`
|
|
26
|
+
: `crud:${(0, crypto_1.randomUUID)()}`;
|
|
27
|
+
}
|
|
28
|
+
async convertAndReturnTheList(list, user) {
|
|
29
|
+
const outputList = [];
|
|
30
|
+
for (let index = 0; index < list.length; index++) {
|
|
31
|
+
const item = list[index];
|
|
32
|
+
outputList.push(await this.toOutput(item));
|
|
33
|
+
}
|
|
34
|
+
return outputList;
|
|
35
|
+
}
|
|
36
|
+
async searchPagination(searchAndPagination, user) {
|
|
37
|
+
return this.withShortCache(this.buildCacheKey('searchPagination', searchAndPagination, user), async () => {
|
|
38
|
+
const page = searchAndPagination?.page || 0, size = searchAndPagination?.size || 10;
|
|
39
|
+
let s = await this.searchParams(searchAndPagination, user);
|
|
40
|
+
let sort;
|
|
41
|
+
if (searchAndPagination?.sortBy &&
|
|
42
|
+
searchAndPagination.sortRotation) {
|
|
43
|
+
sort = {};
|
|
44
|
+
sort[searchAndPagination.sortBy] =
|
|
45
|
+
searchAndPagination.sortRotation;
|
|
46
|
+
}
|
|
47
|
+
return (await this.m.modelSearch(size, page, sort, {
|
|
48
|
+
$match: s,
|
|
49
|
+
})).mapAsync((a) => this.toOutput(a));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async fetchAll(s, user) {
|
|
53
|
+
return this.withShortCache(this.buildCacheKey('fetchAll', s, user), async () => {
|
|
54
|
+
const list = await this.m.find(await this.searchParams(s, user));
|
|
55
|
+
return await this.convertAndReturnTheList(list, user);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async fetchOne(id, user) {
|
|
59
|
+
return this.withShortCache(this.buildCacheKey('fetchOne', id, user), async () => {
|
|
60
|
+
return this.toOutput((await this.m.findById(id)));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async create(input, user) {
|
|
64
|
+
let newModel = this.generateNewModel();
|
|
65
|
+
await this.moveIntoModel(newModel, input);
|
|
66
|
+
await this.beforeCreateOrEdit(newModel, input, 'CREATE', user);
|
|
67
|
+
await this.m.saveModel(newModel);
|
|
68
|
+
this.invalidateSelfCache();
|
|
69
|
+
const out = await this.toOutput(newModel);
|
|
70
|
+
await this.afterCreate(out, input, user);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
async edit(input, user) {
|
|
74
|
+
const newModelFirst = await this.m.findById(this.getIdFieldNameFromInput(input));
|
|
75
|
+
const newModel = await this.moveIntoModel(newModelFirst, input);
|
|
76
|
+
await this.beforeCreateOrEdit(newModel, input, 'EDIT', user);
|
|
77
|
+
await this.m.saveModel(newModel);
|
|
78
|
+
this.invalidateSelfCache();
|
|
79
|
+
return this.toOutput(newModel);
|
|
80
|
+
}
|
|
81
|
+
async remove(id, ruser) {
|
|
82
|
+
let ac = (await this.m.findById(id));
|
|
83
|
+
await this.beforeRemove(ac, ruser);
|
|
84
|
+
await this.m.deleteById(id);
|
|
85
|
+
this.invalidateSelfCache();
|
|
86
|
+
return this.toOutput(ac);
|
|
87
|
+
}
|
|
88
|
+
async withShortCache(key, cb) {
|
|
89
|
+
if (!this.isCacheEnabled || !this.cacheManager) {
|
|
90
|
+
return cb();
|
|
91
|
+
}
|
|
92
|
+
return this.cacheManager.getOrCallAsync(key, cb, {
|
|
93
|
+
livetime: this.cacheLiveTimeMs,
|
|
94
|
+
livetimeExtending: 'ON_GET',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
buildCacheKey(method, ...parts) {
|
|
98
|
+
const serialized = parts.map((part) => this.serializeCachePart(part));
|
|
99
|
+
return `${this.cacheKeyPrefix}:${method}:${serialized.join('|')}`;
|
|
100
|
+
}
|
|
101
|
+
serializeCachePart(part) {
|
|
102
|
+
try {
|
|
103
|
+
return JSON.stringify(part);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return String(part);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
invalidateSelfCache() {
|
|
110
|
+
if (!this.isCacheEnabled || !this.cacheManager) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const escapedPrefix = this.cacheKeyPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
114
|
+
this.cacheManager.invalidateRegex(new RegExp(`^${escapedPrefix}:`));
|
|
115
|
+
}
|
|
116
|
+
async afterCreate(m, input, user) { }
|
|
117
|
+
async beforeCreateOrEdit(model, input, mode, user) { }
|
|
118
|
+
async beforeRemove(model, user) {
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.BaseCrudService = BaseCrudService;
|
|
122
|
+
__decorate([
|
|
123
|
+
(0, common_1.Optional)(),
|
|
124
|
+
(0, common_1.Inject)(cache_manager_1.CacheManagerService),
|
|
125
|
+
__metadata("design:type", cache_manager_1.CacheManagerService)
|
|
126
|
+
], BaseCrudService.prototype, "cacheManager", void 0);
|
|
127
|
+
//# sourceMappingURL=base-crud-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-crud-service.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/base-crud-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,uDAAkD;AAGlD,2CAAkD;AAClD,+DAAkE;AAClE,mCAAoC;AAGpC,MAAsB,eAMpB,SAAQ,+BAAa;IASnB,YAAmB,CAAkC;QACjD,KAAK,EAAE,CAAC;QADO,MAAC,GAAD,CAAC,CAAiC;QARlC,mBAAc,GAAG,IAAI,CAAC;QACtB,oBAAe,GAAG,IAAI,CAAC;QAStC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,SAAS;YAC3B,CAAC,CAAC,QAAQ,SAAS,EAAE;YACrB,CAAC,CAAC,QAAQ,IAAA,mBAAU,GAAE,EAAE,CAAC;IACjC,CAAC;IAYD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DAAC"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base-crud-service"), exports);
|
|
18
|
+
__exportStar(require("./base-crud-klass"), exports);
|
|
19
|
+
__exportStar(require("./base-crud-controller"), exports);
|
|
20
|
+
__exportStar(require("./repository-wrap-mongo"), exports);
|
|
21
|
+
__exportStar(require("./repository-wrap"), exports);
|
|
22
|
+
__exportStar(require("./util/search.util"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAClC,yDAAuC;AACvC,0DAAwC;AACxC,oDAAkC;AAClC,qDAAmC"}
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@ubs-platform/crud-base","repository":{"type":"git","url":"git+https://github.com/ubs-platform/ubs-mona-mr.git"},"homepage":"https://github.com/ubs-platform/ubs-mona-mr","version":"1.4.0","iksir":{"type":"LIBRARY","libraryMode":"PEER","buildSubFolder":""},"peerDependencies":{"@nestjs/common":"^11.1.19","@ubs-platform/users-microservice-helper":"1.4.0","@ubs-platform/users-roles":"1.4.0","@ubs-platform/cache-manager":"1.4.0","@ubs-platform/crud-base-common":"1.4.0"}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { IRepositoryWrap } from './repository-wrap';
|
|
3
|
+
import { RawSearchResult } from '@ubs-platform/crud-base-common/search-result';
|
|
4
|
+
export declare class MongoRepositoryWrap<MODEL> implements IRepositoryWrap<MODEL, string, Model<MODEL>> {
|
|
5
|
+
m: Model<MODEL>;
|
|
6
|
+
constructor(m: Model<MODEL>);
|
|
7
|
+
findById(id: string): Promise<MODEL | null>;
|
|
8
|
+
findOne(params: any): Promise<MODEL | null>;
|
|
9
|
+
saveModel(m: MODEL): Promise<MODEL>;
|
|
10
|
+
deleteById(id: string): Promise<void>;
|
|
11
|
+
search(params: any): Promise<MODEL[]>;
|
|
12
|
+
modelSearch(size: number | string, page: number | string, sort: {
|
|
13
|
+
[key: string]: 1 | -1 | 'asc' | 'desc';
|
|
14
|
+
}, ...searchParamsQuery: any[]): Promise<RawSearchResult<MODEL>>;
|
|
15
|
+
findAll(): Promise<MODEL[]>;
|
|
16
|
+
find(params: any): Promise<MODEL[]>;
|
|
17
|
+
rawRepository(): Model<MODEL>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoRepositoryWrap = void 0;
|
|
4
|
+
const search_util_1 = require("./util/search.util");
|
|
5
|
+
class MongoRepositoryWrap {
|
|
6
|
+
constructor(m) {
|
|
7
|
+
this.m = m;
|
|
8
|
+
}
|
|
9
|
+
async findById(id) {
|
|
10
|
+
return this.m.findById(id).exec();
|
|
11
|
+
}
|
|
12
|
+
async findOne(params) {
|
|
13
|
+
return this.m.findOne(params).exec();
|
|
14
|
+
}
|
|
15
|
+
async saveModel(m) {
|
|
16
|
+
const modelInstance = new this.m(m);
|
|
17
|
+
return modelInstance.save();
|
|
18
|
+
}
|
|
19
|
+
async deleteById(id) {
|
|
20
|
+
await this.m.findByIdAndDelete(id).exec();
|
|
21
|
+
}
|
|
22
|
+
async search(params) {
|
|
23
|
+
return this.m.find(params).exec();
|
|
24
|
+
}
|
|
25
|
+
async modelSearch(size, page, sort, ...searchParamsQuery) {
|
|
26
|
+
return search_util_1.MongooseSearchUtil.modelSearch(this.m, size, page, sort, ...searchParamsQuery);
|
|
27
|
+
}
|
|
28
|
+
async findAll() {
|
|
29
|
+
return this.m.find().exec();
|
|
30
|
+
}
|
|
31
|
+
async find(params) {
|
|
32
|
+
return this.m.find(params).exec();
|
|
33
|
+
}
|
|
34
|
+
rawRepository() {
|
|
35
|
+
return this.m;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.MongoRepositoryWrap = MongoRepositoryWrap;
|
|
39
|
+
//# sourceMappingURL=repository-wrap-mongo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-wrap-mongo.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/repository-wrap-mongo.ts"],"names":[],"mappings":";;;AAGA,oDAAwD;AAExD,MAAa,mBAAmB;IAG5B,YAAmB,CAAe;QAAf,MAAC,GAAD,CAAC,CAAc;IAAG,CAAC;IAEtC,KAAK,CAAC,QAAQ,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAW;QACrB,OAAO,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,CAAQ;QACpB,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,aAAa,CAAC,IAAI,EAA2B,CAAC;IACzD,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,EAAU;QACvB,MAAM,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,MAAW;QACpB,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,WAAW,CACb,IAAqB,EACrB,IAAqB,EACrB,IAAgD,EAGhD,GAAG,iBAAwB;QAE3B,OAAO,gCAAkB,CAAC,WAAW,CACjC,IAAI,CAAC,CAAC,EACN,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,GAAG,iBAAiB,CACvB,CAAC;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAW;QAClB,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,aAAa;QACT,OAAO,IAAI,CAAC,CAAC,CAAC;IAClB,CAAC;CACJ;AApDD,kDAoDC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RawSearchResult } from "@ubs-platform/crud-base-common/search-result";
|
|
2
|
+
export interface IRepositoryWrap<MODEL, ID, REPO extends any> {
|
|
3
|
+
findById(id: ID): Promise<MODEL | null>;
|
|
4
|
+
saveModel(m: MODEL): Promise<MODEL>;
|
|
5
|
+
deleteById(id: ID): Promise<void>;
|
|
6
|
+
search(params: any): Promise<MODEL[]>;
|
|
7
|
+
findAll(): Promise<MODEL[]>;
|
|
8
|
+
find(params: any): Promise<MODEL[]>;
|
|
9
|
+
findOne(params: any): Promise<MODEL | null>;
|
|
10
|
+
modelSearch(size: number | string, page: number | string, sort: {
|
|
11
|
+
[key: string]: 1 | -1 | 'asc' | 'desc';
|
|
12
|
+
}, ...searchParamsQuery: any[]): Promise<RawSearchResult<MODEL>>;
|
|
13
|
+
rawRepository(): REPO;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-wrap.js","sourceRoot":"","sources":["../../../../../libs/crud-base/src/repository-wrap.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RawSearchResult } from '@ubs-platform/crud-base-common';
|
|
2
|
+
import { Model } from 'mongoose';
|
|
3
|
+
export declare class MongooseSearchUtil {
|
|
4
|
+
static modelSearch<OUTPUT>(model: Model<OUTPUT>, size: number | string, page: number | string, sort: {
|
|
5
|
+
[key: string]: 1 | -1 | 'asc' | 'desc';
|
|
6
|
+
}, ...searchParamsQuery: any[]): Promise<RawSearchResult<OUTPUT>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongooseSearchUtil = void 0;
|
|
4
|
+
const crud_base_common_1 = require("@ubs-platform/crud-base-common");
|
|
5
|
+
class MongooseSearchUtil {
|
|
6
|
+
static async modelSearch(model, size, page, sort, ...searchParamsQuery) {
|
|
7
|
+
size = parseInt(size) || 10;
|
|
8
|
+
page = parseInt(page) || 0;
|
|
9
|
+
const mongoPipe = [
|
|
10
|
+
...searchParamsQuery,
|
|
11
|
+
{
|
|
12
|
+
$facet: {
|
|
13
|
+
total: [{ $count: 'total' }],
|
|
14
|
+
data: [
|
|
15
|
+
sort && Object.keys(sort).length > 0
|
|
16
|
+
? { $sort: sort }
|
|
17
|
+
: null,
|
|
18
|
+
{ $skip: (size || 10) * (page || 0) },
|
|
19
|
+
{ $limit: parseInt(size) },
|
|
20
|
+
].filter((a) => a),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
const results = await model.aggregate(mongoPipe);
|
|
25
|
+
const maxItemLength = results[0].total[0]?.total || 0;
|
|
26
|
+
const itemLengthThing = Math.ceil(maxItemLength / size);
|
|
27
|
+
const maxPagesIndex = size ? itemLengthThing - 1 : 0;
|
|
28
|
+
return new crud_base_common_1.RawSearchResult(results[0]?.data || [], page, size, maxItemLength, maxPagesIndex, maxPagesIndex == page, page == 0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.MongooseSearchUtil = MongooseSearchUtil;
|
|
32
|
+
//# sourceMappingURL=search.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.util.js","sourceRoot":"","sources":["../../../../../../libs/crud-base/src/util/search.util.ts"],"names":[],"mappings":";;;AAAA,qEAAiE;AAMjE,MAAa,kBAAkB;IAS3B,MAAM,CAAC,KAAK,CAAC,WAAW,CACpB,KAAoB,EACpB,IAAqB,EACrB,IAAqB,EACrB,IAAgD,EAGhD,GAAG,iBAAwB;QAG3B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAO3B,MAAM,SAAS,GAAG;YACd,GAAG,iBAAiB;YACpB;gBACI,MAAM,EAAE;oBACJ,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;oBAC5B,IAAI,EAAE;wBAEF,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;4BAChC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE;4BACjB,CAAC,CAAC,IAAI;wBACV,EAAE,KA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