identity-admin 1.4.4 → 1.6.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/README.md +126 -126
- package/lib/Dashboard.d.ts +14 -14
- package/lib/Dashboard.js +95 -88
- package/lib/container/helpers/HelperInversify.d.ts +6 -6
- package/lib/container/helpers/HelperInversify.js +10 -10
- package/lib/container/helpers/HelperTypes.d.ts +5 -5
- package/lib/container/helpers/HelperTypes.js +7 -7
- package/lib/container/index.d.ts +1 -1
- package/lib/container/index.js +14 -14
- package/lib/container/repositories/RepositoryInversify.d.ts +4 -4
- package/lib/container/repositories/RepositoryInversify.js +13 -13
- package/lib/container/repositories/RepositoryTypes.d.ts +4 -4
- package/lib/container/repositories/RepositoryTypes.js +6 -6
- package/lib/container/types.d.ts +8 -8
- package/lib/container/types.js +9 -9
- package/lib/controllers/ActionController.d.ts +8 -8
- package/lib/controllers/ActionController.js +79 -79
- package/lib/controllers/DashboardController.d.ts +36 -36
- package/lib/controllers/DashboardController.js +349 -335
- package/lib/controllers/ResourceController.d.ts +11 -9
- package/lib/controllers/ResourceController.js +109 -104
- package/lib/helpers/ActionsGenerator.d.ts +9 -9
- package/lib/helpers/ActionsGenerator.js +101 -77
- package/lib/helpers/FiltersHelper.d.ts +7 -0
- package/lib/helpers/FiltersHelper.js +64 -0
- package/lib/helpers/LocalesHelper.d.ts +4 -4
- package/lib/helpers/LocalesHelper.js +73 -73
- package/lib/helpers/ResourceGenerator.d.ts +4 -4
- package/lib/helpers/ResourceGenerator.js +110 -68
- package/lib/helpers/ResourceHelper.d.ts +23 -22
- package/lib/helpers/ResourceHelper.js +305 -286
- package/lib/helpers/SchemaGenerator.d.ts +5 -5
- package/lib/helpers/SchemaGenerator.js +92 -87
- package/lib/helpers/SchemaHelper.d.ts +5 -5
- package/lib/helpers/SchemaHelper.js +21 -21
- package/lib/locales/ar.json +1 -0
- package/lib/locales/en.json +50 -10
- package/lib/middlewares/isAuth.d.ts +13 -13
- package/lib/middlewares/isAuth.js +43 -43
- package/lib/models/ModelNames.d.ts +4 -4
- package/lib/models/ModelNames.js +7 -7
- package/lib/models/request-log/IRequestLog.d.ts +22 -22
- package/lib/models/request-log/IRequestLog.js +2 -2
- package/lib/models/request-log/RequestLog.d.ts +3 -3
- package/lib/models/request-log/RequestLog.js +51 -51
- package/lib/repositories/DashboardRepository.d.ts +5 -5
- package/lib/repositories/DashboardRepository.js +12 -12
- package/lib/repositories/Repository.d.ts +68 -68
- package/lib/repositories/Repository.js +212 -212
- package/lib/repositories/RequestLogRepository.d.ts +10 -10
- package/lib/repositories/RequestLogRepository.js +54 -54
- package/lib/repositories/SaveResult.d.ts +14 -14
- package/lib/repositories/SaveResult.js +18 -18
- package/lib/router/index.d.ts +8 -8
- package/lib/router/index.js +97 -97
- package/lib/types/DashbordConfig.d.ts +21 -19
- package/lib/types/DashbordConfig.js +2 -2
- package/lib/types/IConfigurationFile.d.ts +5 -0
- package/lib/types/IConfigurationFile.js +2 -0
- package/lib/types/IResourceFile.d.ts +145 -125
- package/lib/types/IResourceFile.js +2 -2
- package/lib/types/helpers.d.ts +28 -15
- package/lib/types/helpers.js +35 -21
- package/lib/utils/ResourceUtils.d.ts +2 -2
- package/lib/utils/ResourceUtils.js +7 -7
- package/lib/utils/ResponseUtils.d.ts +10 -10
- package/lib/utils/ResponseUtils.js +38 -38
- package/lib/utils/StringUtils.d.ts +9 -9
- package/lib/utils/StringUtils.js +46 -46
- package/lib/view/asset-manifest.json +13 -13
- package/lib/view/assets/icons/delete_icon.svg +3 -3
- package/lib/view/assets/icons/flags/ic_flag_cn.svg +9 -9
- package/lib/view/assets/icons/flags/ic_flag_sa.svg +9 -9
- package/lib/view/assets/icons/flags/ic_flag_vn.svg +9 -9
- package/lib/view/assets/icons/info_icon.svg +3 -3
- package/lib/view/assets/icons/navbar/ic_banking.svg +5 -5
- package/lib/view/assets/icons/navbar/ic_invoice.svg +4 -4
- package/lib/view/assets/icons/navbar/ic_kanban.svg +7 -7
- package/lib/view/assets/icons/navbar/ic_menu_item.svg +8 -8
- package/lib/view/assets/icons/small_info_icon.svg +3 -3
- package/lib/view/assets/illustrations/Group 16.svg +4 -4
- package/lib/view/assets/illustrations/logo.svg +5 -5
- package/lib/view/favicon/browserconfig.xml +9 -9
- package/lib/view/favicon/safari-pinned-tab.svg +182 -182
- package/lib/view/favicon/site.webmanifest +19 -19
- package/lib/view/fonts/index.css +18 -18
- package/lib/view/index.html +1 -1
- package/lib/view/manifest.json +20 -20
- package/lib/view/robots.txt +3 -3
- package/lib/view/static/js/{148.b6f24fc9.chunk.js → 148.b05fe2c8.chunk.js} +1 -1
- package/lib/view/static/js/{705.b2b55cc3.chunk.js → 705.f86db82e.chunk.js} +1 -1
- package/lib/view/static/js/802.3f287a2c.chunk.js +1 -0
- package/lib/view/static/js/main.da8f09ec.js +2 -0
- package/lib/view/static/js/{main.bc5ec798.js.LICENSE.txt → main.da8f09ec.js.LICENSE.txt} +225 -223
- package/package.json +51 -51
- package/lib/view/static/js/939.f35326c5.chunk.js +0 -1
- package/lib/view/static/js/main.bc5ec798.js +0 -2
|
@@ -1,335 +1,349 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
-
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
-
};
|
|
23
|
-
var DashboardController_1;
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const inversify_express_utils_1 = require("inversify-express-utils");
|
|
26
|
-
const mongoose_1 = require("mongoose");
|
|
27
|
-
const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
|
|
28
|
-
const express_validator_1 = require("express-validator");
|
|
29
|
-
const ResourceGenerator_1 = __importDefault(require("../helpers/ResourceGenerator"));
|
|
30
|
-
const ResourceHelper_1 = __importDefault(require("../helpers/ResourceHelper"));
|
|
31
|
-
const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
|
|
32
|
-
const mongoose_2 = __importDefault(require("mongoose"));
|
|
33
|
-
const inversify_1 = require("inversify");
|
|
34
|
-
const Repository_1 = __importDefault(require("../repositories/Repository"));
|
|
35
|
-
const ResourceUtils_1 = require("../utils/ResourceUtils");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
filter =
|
|
135
|
-
}
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
records
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (!
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
__decorate([
|
|
315
|
-
(0, inversify_express_utils_1.
|
|
316
|
-
__param(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
(0, inversify_express_utils_1.
|
|
321
|
-
__param(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
(0, inversify_express_utils_1.
|
|
326
|
-
__param(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
(0,
|
|
331
|
-
__param(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
var DashboardController_1;
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const inversify_express_utils_1 = require("inversify-express-utils");
|
|
26
|
+
const mongoose_1 = require("mongoose");
|
|
27
|
+
const ResponseUtils_1 = __importDefault(require("../utils/ResponseUtils"));
|
|
28
|
+
const express_validator_1 = require("express-validator");
|
|
29
|
+
const ResourceGenerator_1 = __importDefault(require("../helpers/ResourceGenerator"));
|
|
30
|
+
const ResourceHelper_1 = __importDefault(require("../helpers/ResourceHelper"));
|
|
31
|
+
const StringUtils_1 = __importDefault(require("../utils/StringUtils"));
|
|
32
|
+
const mongoose_2 = __importDefault(require("mongoose"));
|
|
33
|
+
const inversify_1 = require("inversify");
|
|
34
|
+
const Repository_1 = __importDefault(require("../repositories/Repository"));
|
|
35
|
+
const ResourceUtils_1 = require("../utils/ResourceUtils");
|
|
36
|
+
const FiltersHelper_1 = __importDefault(require("../helpers/FiltersHelper"));
|
|
37
|
+
let DashboardController = DashboardController_1 = class DashboardController {
|
|
38
|
+
constructor(resource, repository, resources) {
|
|
39
|
+
this.resource = resource;
|
|
40
|
+
this.repository = repository;
|
|
41
|
+
this.resources = resources;
|
|
42
|
+
if (!repository && resource) {
|
|
43
|
+
this.repository = new Repository_1.default(resource.properties.resource);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
validateRequest(req, res) {
|
|
47
|
+
const errors = (0, express_validator_1.validationResult)(req);
|
|
48
|
+
if (!errors.isEmpty()) {
|
|
49
|
+
ResponseUtils_1.default.send(res, 422, errors.array()[0].msg, errors);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
paginateParams(request) {
|
|
55
|
+
const page = request.query.page ? +request.query.page : DashboardController_1.DEFAULT_PAGE;
|
|
56
|
+
const perPage = request.query.perPage ? +request.query.perPage : DashboardController_1.DEFAULT_PER_PAGE;
|
|
57
|
+
return { page, perPage };
|
|
58
|
+
}
|
|
59
|
+
getSearchableSubStringFilter(resource, filter, subString) {
|
|
60
|
+
const schema = resource.properties.resource.schema.paths;
|
|
61
|
+
const searchBy = ResourceHelper_1.default.getSchemaTitle(schema, this.resource);
|
|
62
|
+
if (searchBy === '_id') {
|
|
63
|
+
if (!mongoose_2.default.isValidObjectId(subString.source)) {
|
|
64
|
+
return filter;
|
|
65
|
+
}
|
|
66
|
+
filter[searchBy] = subString.source;
|
|
67
|
+
return filter;
|
|
68
|
+
}
|
|
69
|
+
filter[searchBy] = subString;
|
|
70
|
+
return filter;
|
|
71
|
+
}
|
|
72
|
+
getScopeFilter(filter, scope) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
getVisibileExtrsActions(currentUser, record, resource, repository, modelName) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const data = {
|
|
78
|
+
record: record.toObject(),
|
|
79
|
+
currentUser,
|
|
80
|
+
resource: {
|
|
81
|
+
name: modelName,
|
|
82
|
+
path: StringUtils_1.default.lowerCaseFirstLetter(modelName),
|
|
83
|
+
repository
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
if (!resource.properties.actions || !resource.properties.actions.extras) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
var extraActionsArray = [];
|
|
90
|
+
const extraActions = resource.properties.actions.extras;
|
|
91
|
+
for (var i = 0; i < extraActions.length; i++) {
|
|
92
|
+
const extraAction = extraActions[i];
|
|
93
|
+
if (!extraAction.isVisible) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
const isVisible = extraAction.isVisible(data);
|
|
97
|
+
if (isVisible) {
|
|
98
|
+
extraActionsArray.push(extraAction.key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return extraActionsArray;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
index(req, res) {
|
|
105
|
+
var _a, _b, _c;
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
if (!this.validateRequest(req, res)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const paginateParams = this.paginateParams(req);
|
|
111
|
+
const searchableSubString = req.query.filter ? new RegExp(req.query.filter, 'i') : undefined;
|
|
112
|
+
const scope = req.query.scope;
|
|
113
|
+
const currentUser = req.user;
|
|
114
|
+
const modelName = req.params.resource;
|
|
115
|
+
const filtersQuery = req.query.filters;
|
|
116
|
+
const filters = filtersQuery ? filtersQuery.split("^^") : undefined;
|
|
117
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
118
|
+
if (!resource) {
|
|
119
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
120
|
+
}
|
|
121
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
122
|
+
const modifiedResource = ResourceGenerator_1.default.generate(resource);
|
|
123
|
+
const sort = req.query.order;
|
|
124
|
+
const sortBy = req.query.orderBy;
|
|
125
|
+
const sortQuery = {};
|
|
126
|
+
sortQuery[sortBy] = sort;
|
|
127
|
+
if (sortBy !== '_id') {
|
|
128
|
+
sortQuery._id = 'asc';
|
|
129
|
+
}
|
|
130
|
+
const populate = req.query.populate;
|
|
131
|
+
var filter = {};
|
|
132
|
+
const crudOperations = resource.properties.crudOperations;
|
|
133
|
+
if (crudOperations && crudOperations.index) {
|
|
134
|
+
filter = crudOperations.index.before(filter, currentUser);
|
|
135
|
+
}
|
|
136
|
+
if (scope && resource.properties.filters && resource.properties.filters.scopes && resource.properties.filters.scopes.isAccessible) {
|
|
137
|
+
if (resource.properties.filters.scopes.manual) {
|
|
138
|
+
filter = resource.properties.filters.scopes.manual.handler(filter, scope);
|
|
139
|
+
}
|
|
140
|
+
else if (resource.properties.filters.scopes.auto) {
|
|
141
|
+
const key = resource.properties.filters.scopes.auto.key;
|
|
142
|
+
if (key) {
|
|
143
|
+
filter[key] = scope;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (searchableSubString) {
|
|
148
|
+
filter = this.getSearchableSubStringFilter(resource, filter, searchableSubString);
|
|
149
|
+
}
|
|
150
|
+
filter = FiltersHelper_1.default.appendFilters(filter, filters);
|
|
151
|
+
var records = [];
|
|
152
|
+
var pageInfo = undefined;
|
|
153
|
+
if (!req.query.page && !req.query.perPage) {
|
|
154
|
+
records = yield repository.findMany({
|
|
155
|
+
sort: sortQuery,
|
|
156
|
+
filter,
|
|
157
|
+
populate: modifiedResource.properties.populatedString
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const page = yield repository.paginate({
|
|
162
|
+
sort: sortQuery,
|
|
163
|
+
filter,
|
|
164
|
+
paginateParams: paginateParams,
|
|
165
|
+
populate: modifiedResource.properties.populatedString
|
|
166
|
+
});
|
|
167
|
+
records = page.records;
|
|
168
|
+
pageInfo = page.pageInfo;
|
|
169
|
+
}
|
|
170
|
+
var documents = [];
|
|
171
|
+
for (var i = 0; i < records.length; i++) {
|
|
172
|
+
const record = records[i];
|
|
173
|
+
const extraActionKeys = yield this.getVisibileExtrsActions(currentUser, record, resource, repository, modifiedResource.properties.modelName);
|
|
174
|
+
if (extraActionKeys) {
|
|
175
|
+
const recordFlatten = record.toObject();
|
|
176
|
+
recordFlatten.extraActionKeys = extraActionKeys;
|
|
177
|
+
documents.push(recordFlatten);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
documents.push(record);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return ResponseUtils_1.default.send(res, 200, 'OK', {
|
|
184
|
+
records: documents,
|
|
185
|
+
pageInfo,
|
|
186
|
+
//options: modifiedResource
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
create(req, res) {
|
|
191
|
+
var _a, _b, _c;
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
if (!this.validateRequest(req, res)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const modelName = req.params.resource;
|
|
197
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
198
|
+
if (!resource) {
|
|
199
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
200
|
+
}
|
|
201
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
202
|
+
const modifiedResource = ResourceGenerator_1.default.generate(resource);
|
|
203
|
+
var recordParams = req.body;
|
|
204
|
+
const currentUser = req.user;
|
|
205
|
+
const crudOperations = resource.properties.crudOperations;
|
|
206
|
+
if (crudOperations && crudOperations.create) {
|
|
207
|
+
recordParams = crudOperations.create.before(recordParams, currentUser);
|
|
208
|
+
}
|
|
209
|
+
var record;
|
|
210
|
+
if (recordParams.password) {
|
|
211
|
+
const user = new mongoose_1.Mongoose.prototype.model(modifiedResource.properties.modelName)(recordParams);
|
|
212
|
+
const set = yield user.setPassword(recordParams.password);
|
|
213
|
+
record = yield repository.saveInstance(user);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
record = yield repository.save(recordParams);
|
|
217
|
+
}
|
|
218
|
+
if (!record.isValid() || !record.document) {
|
|
219
|
+
return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', record.getErrors());
|
|
220
|
+
}
|
|
221
|
+
return ResponseUtils_1.default.created(res, {
|
|
222
|
+
record
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
update(req, res) {
|
|
227
|
+
var _a, _b, _c;
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
if (!this.validateRequest(req, res)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const modelName = req.params.resource;
|
|
233
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
234
|
+
if (!resource) {
|
|
235
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
236
|
+
}
|
|
237
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
238
|
+
const recordId = req.params.id;
|
|
239
|
+
var recordParams = req.body;
|
|
240
|
+
var record = yield repository.findById(recordId);
|
|
241
|
+
if (!record) {
|
|
242
|
+
return ResponseUtils_1.default.send(res, 404, 'record Not Found');
|
|
243
|
+
}
|
|
244
|
+
const recordSaveResult = yield repository.update(record, recordParams);
|
|
245
|
+
if (!recordSaveResult.isValid()) {
|
|
246
|
+
return ResponseUtils_1.default.unprocessable(res, 'Invalid Data', recordSaveResult.getErrors());
|
|
247
|
+
}
|
|
248
|
+
// if (resource.properties.modelName === ModelNames.Settings) {
|
|
249
|
+
// await AppSettings.run()
|
|
250
|
+
// }
|
|
251
|
+
return ResponseUtils_1.default.ok(res, {
|
|
252
|
+
record: recordSaveResult
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
show(req, res) {
|
|
257
|
+
var _a, _b, _c, _d, _e;
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
if (!this.validateRequest(req, res)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const modelName = req.params.resource;
|
|
263
|
+
const recordId = req.params.id;
|
|
264
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
265
|
+
if (!resource) {
|
|
266
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
267
|
+
}
|
|
268
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
269
|
+
const modifiedResource = ResourceGenerator_1.default.generate(resource);
|
|
270
|
+
var record = yield repository.findOne({
|
|
271
|
+
filter: {
|
|
272
|
+
_id: recordId
|
|
273
|
+
},
|
|
274
|
+
populate: modifiedResource.properties.populatedString
|
|
275
|
+
});
|
|
276
|
+
if (!record) {
|
|
277
|
+
return ResponseUtils_1.default.send(res, 404, 'record not found');
|
|
278
|
+
}
|
|
279
|
+
record = record.toObject();
|
|
280
|
+
//record = await this.getExtras(record._id.toString(), record, this.getExtraRepository())
|
|
281
|
+
record = yield ResourceHelper_1.default.addExtraFields(modifiedResource.showProperties, modifiedResource.properties.model, record, StringUtils_1.default.lowerCaseFirstLetter(modifiedResource.properties.modelName), resource);
|
|
282
|
+
const afterMethod = (_e = (_d = resource.properties.crudOperations) === null || _d === void 0 ? void 0 : _d.show) === null || _e === void 0 ? void 0 : _e.after;
|
|
283
|
+
let extras = {};
|
|
284
|
+
if (afterMethod && record) {
|
|
285
|
+
extras = yield afterMethod(record);
|
|
286
|
+
}
|
|
287
|
+
return ResponseUtils_1.default.ok(res, Object.assign(Object.assign({}, extras), { record: record ? record : null }));
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
delete(req, res) {
|
|
291
|
+
var _a, _b, _c;
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
if (!this.validateRequest(req, res)) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const modelName = req.params.resource;
|
|
297
|
+
const recordId = req.params.id;
|
|
298
|
+
const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
|
|
299
|
+
if (!resource) {
|
|
300
|
+
return ResponseUtils_1.default.notFound(res, 'Resource not found', []);
|
|
301
|
+
}
|
|
302
|
+
const repository = (_c = this.repository) !== null && _c !== void 0 ? _c : new Repository_1.default(resource.properties.resource);
|
|
303
|
+
const record = yield repository.findById(recordId);
|
|
304
|
+
if (!record) {
|
|
305
|
+
return ResponseUtils_1.default.send(res, 404, 'record Not Found');
|
|
306
|
+
}
|
|
307
|
+
yield repository.remove({ _id: record._id });
|
|
308
|
+
return ResponseUtils_1.default.send(res, 200, 'OK');
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
DashboardController.DEFAULT_PAGE = 1;
|
|
313
|
+
DashboardController.DEFAULT_PER_PAGE = 30;
|
|
314
|
+
__decorate([
|
|
315
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
316
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
317
|
+
], DashboardController.prototype, "validateRequest", null);
|
|
318
|
+
__decorate([
|
|
319
|
+
(0, inversify_express_utils_1.httpGet)('/'),
|
|
320
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
321
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
322
|
+
], DashboardController.prototype, "index", null);
|
|
323
|
+
__decorate([
|
|
324
|
+
(0, inversify_express_utils_1.httpPost)('/'),
|
|
325
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
326
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
327
|
+
], DashboardController.prototype, "create", null);
|
|
328
|
+
__decorate([
|
|
329
|
+
(0, inversify_express_utils_1.httpPatch)('/:id'),
|
|
330
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
331
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
332
|
+
], DashboardController.prototype, "update", null);
|
|
333
|
+
__decorate([
|
|
334
|
+
(0, inversify_express_utils_1.httpGet)('/:id'),
|
|
335
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
336
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
337
|
+
], DashboardController.prototype, "show", null);
|
|
338
|
+
__decorate([
|
|
339
|
+
(0, inversify_express_utils_1.httpDelete)('/:id'),
|
|
340
|
+
__param(0, (0, inversify_express_utils_1.request)()),
|
|
341
|
+
__param(1, (0, inversify_express_utils_1.response)())
|
|
342
|
+
], DashboardController.prototype, "delete", null);
|
|
343
|
+
DashboardController = DashboardController_1 = __decorate([
|
|
344
|
+
(0, inversify_1.injectable)(),
|
|
345
|
+
__param(0, (0, inversify_1.unmanaged)()),
|
|
346
|
+
__param(1, (0, inversify_1.unmanaged)()),
|
|
347
|
+
__param(2, (0, inversify_1.unmanaged)())
|
|
348
|
+
], DashboardController);
|
|
349
|
+
exports.default = DashboardController;
|