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 | const entityAction_1 = require("../core/decorators/entityAction");
|
12 | const postfilter_1 = require("../core/decorators/postfilter");
|
13 | const dynamic_repository_1 = require('../core/dynamic/dynamic-repository');
|
14 | const Q = require('q');
|
15 |
|
16 | const logger = require("../logging");
|
17 | class AuthorizationRepository extends dynamic_repository_1.DynamicRepository {
|
18 | constructor(...args) {
|
19 | super(...args);
|
20 | this.logger = logger.winstonLog;
|
21 | }
|
22 |
|
23 | preCreate(params) {
|
24 | return Q.resolve(params);
|
25 | }
|
26 | postCreate(params) {
|
27 | return Q.when(params);
|
28 | }
|
29 | preUpdate(params) {
|
30 | return Q.resolve(params);
|
31 | }
|
32 | postUpdate(params) {
|
33 | return Q.when(params);
|
34 | }
|
35 | preBulkCreate(params) {
|
36 | return Q.resolve(params);
|
37 | }
|
38 | preBulkDelete(params) {
|
39 | return Q.resolve(params);
|
40 | }
|
41 | postBulkCreate(params) {
|
42 | return Q.resolve(params);
|
43 | }
|
44 | preBulkUpdate(params) {
|
45 | return Q.when(params);
|
46 | }
|
47 | postBulkUpdate(params) {
|
48 | return Q.when(params);
|
49 | }
|
50 | preDelete(params) {
|
51 | return Q.when(params);
|
52 | }
|
53 | postDelete(params) {
|
54 | return Q.when(params);
|
55 | }
|
56 | postBulkDelete(params) {
|
57 | return Q.when(params);
|
58 | }
|
59 | preRead(params) {
|
60 | return Q.when(params);
|
61 | }
|
62 | postRead(params) {
|
63 | return Q.when(params);
|
64 | }
|
65 | preBulkRead(params) {
|
66 | return Q.when(params);
|
67 | }
|
68 | postBulkRead(params) {
|
69 | return Q.when(params);
|
70 | }
|
71 | bulkPost(objArr, batchSize) {
|
72 | let actionEntities = this.getEntityFromArgs.apply(this, arguments);
|
73 | if (!actionEntities) {
|
74 | actionEntities = [];
|
75 | }
|
76 | this.logEntityInfo("bulkPost", objArr);
|
77 | return this.preBulkCreate(actionEntities)
|
78 | .then((params) => {
|
79 | let entitiesToCreate = new Array();
|
80 | params.forEach((input) => { entitiesToCreate.push(input.inputEntity); });
|
81 | arguments[0] = entitiesToCreate;
|
82 | arguments[arguments.length - 1] = undefined;
|
83 | return super.bulkPost.apply(this, arguments).then((createdDbOEntites) => {
|
84 | let indexInMainCollection = 0;
|
85 | createdDbOEntites.forEach((createdEntity) => {
|
86 | actionEntities[indexInMainCollection].newPersistentEntity = createdEntity;
|
87 | indexInMainCollection++;
|
88 | });
|
89 | return this.postBulkCreate(actionEntities).then((result) => {
|
90 | return result.map(x => x.newPersistentEntity);
|
91 | });
|
92 | }, (error) => {
|
93 | return Q.reject(error);
|
94 | });
|
95 | }, (error) => {
|
96 | return Q.reject(error);
|
97 | });
|
98 | }
|
99 | bulkPut(objArr, batchSize, donotLoadChilds) {
|
100 | if (!objArr || !objArr.length)
|
101 | return Q.when(objArr);
|
102 | let actionEntities = this.getEntityFromArgs.apply(this, arguments);
|
103 | if (!actionEntities) {
|
104 | actionEntities = [];
|
105 | }
|
106 | this.logEntityInfo("bulkPut", objArr);
|
107 | return this.preBulkUpdate(actionEntities)
|
108 | .then((params) => {
|
109 | let entitiesToUpdate = new Array();
|
110 | params.forEach((input) => { input.newPersistentEntity.__dbEntity = input.oldPersistentEntity; entitiesToUpdate.push(input.newPersistentEntity); });
|
111 | arguments[0] = entitiesToUpdate;
|
112 | arguments[arguments.length - 1] = undefined;
|
113 | return super.bulkPut.apply(this, arguments).then((createdDbOEntites) => {
|
114 | let indexInMainCollection = 0;
|
115 | createdDbOEntites.forEach((createdEntity) => {
|
116 | actionEntities[indexInMainCollection].newPersistentEntity = createdEntity;
|
117 | indexInMainCollection++;
|
118 | });
|
119 | return this.postBulkUpdate(actionEntities).then((result) => result.map(x => x.newPersistentEntity));
|
120 | }, (error) => {
|
121 | return Q.reject(error);
|
122 | });
|
123 | }, (error) => {
|
124 | return Q.reject(error);
|
125 | });
|
126 | }
|
127 | bulkDel(params) {
|
128 | let actionParams = this.getEntityFromArgs.apply(this, arguments);
|
129 | let entitiesToDelete = [];
|
130 | if (!actionParams) {
|
131 | actionParams = [];
|
132 | }
|
133 | this.logEntityInfo("bulkDel", params);
|
134 | actionParams.forEach((input) => { entitiesToDelete.push(input.newPersistentEntity); });
|
135 | return this.preBulkDelete(actionParams)
|
136 | .then((params) => {
|
137 | return super.bulkDel(entitiesToDelete).then((updatedDbObj) => {
|
138 | return this.postBulkDelete(actionParams).then((result) => result.map(x => x.newPersistentEntity));
|
139 | }, (error) => {
|
140 | return Q.reject(error);
|
141 | });
|
142 | }, (error) => {
|
143 | return Q.reject(error);
|
144 | });
|
145 | }
|
146 |
|
147 |
|
148 | bulkPutMany(objIds, obj) {
|
149 | obj._id = objIds[0];
|
150 | this.logEntityInfo("bulkPutMany", objIds);
|
151 | return super.bulkPutMany(objIds, obj);
|
152 | }
|
153 | findOne(id, donotLoadChilds) {
|
154 | let params = this.getEntityFromArgs.apply(this, arguments);
|
155 | if (!params) {
|
156 | params = {};
|
157 | }
|
158 | return this.preRead(params).then(result => {
|
159 | return this.postRead(result).then((updatedParams) => {
|
160 | return Q.resolve(updatedParams.newPersistentEntity);
|
161 | }).catch(exc => {
|
162 | return Q.reject(exc);
|
163 | });
|
164 | }).catch(exc => {
|
165 | return Q.reject(exc);
|
166 | });
|
167 | }
|
168 | findMany(ids, toLoadEmbededChilds) {
|
169 | let actionEntities = this.getEntityFromArgs.apply(this, arguments);
|
170 | if (!actionEntities) {
|
171 | actionEntities = [];
|
172 | }
|
173 | return this.preBulkRead(actionEntities).then(results => {
|
174 | return this.postBulkRead(results).then(newResults => {
|
175 | return Q.when(newResults.map(entity => entity.newPersistentEntity));
|
176 | }).catch(exc => {
|
177 | this.logger.logError(exc);
|
178 | return Q.reject(exc);
|
179 | });
|
180 | }).catch(exc => {
|
181 | this.logger.logError(exc);
|
182 | return Q.reject(exc);
|
183 | });
|
184 | }
|
185 | findWhere(query, selectedFields, queryOptions, toLoadChilds) {
|
186 | let actionEntities = this.getEntityFromArgs.apply(this, arguments);
|
187 | if (!actionEntities) {
|
188 | actionEntities = [];
|
189 | }
|
190 | return this.preBulkRead(actionEntities).then(results => {
|
191 | return this.postBulkRead(results).then(newResults => {
|
192 | return Q.when(newResults.map(entity => entity.newPersistentEntity));
|
193 | }).catch(exc => {
|
194 | this.logger.logError(exc);
|
195 | return Q.reject(exc);
|
196 | });
|
197 | }).catch(exc => {
|
198 | this.logger.logError(exc);
|
199 | return Q.reject(exc);
|
200 | });
|
201 | }
|
202 | findByField(fieldName, value) {
|
203 | return super.findByField(fieldName, value);
|
204 | }
|
205 | findChild(id, prop) {
|
206 | return super.findChild(id, prop);
|
207 | }
|
208 | put(id, obj) {
|
209 | let resultEntityActionObj = this.getEntityFromArgs.apply(this, arguments);
|
210 | if (!resultEntityActionObj) {
|
211 | resultEntityActionObj = {};
|
212 | }
|
213 | this.logEntityInfo("put", obj);
|
214 | return this.preUpdate(resultEntityActionObj)
|
215 | .then((params) => {
|
216 | params.newPersistentEntity.__dbEntity = params.oldPersistentEntity;
|
217 | return super.put(id, params.newPersistentEntity).then((updatedDbObj) => {
|
218 | resultEntityActionObj.newPersistentEntity = updatedDbObj;
|
219 | return this.postUpdate(resultEntityActionObj).then((updatedEntity) => {
|
220 | return Q.when(updatedEntity.newPersistentEntity);
|
221 | }, (exc) => {
|
222 | return Q.reject(exc);
|
223 | });
|
224 | }, (error) => {
|
225 | return Q.reject(error);
|
226 | });
|
227 | }, (error) => {
|
228 | return Q.reject(error);
|
229 | });
|
230 |
|
231 | }
|
232 | post(obj) {
|
233 | this.logEntityInfo("post", obj);
|
234 | let resultEntityActionObj = this.getEntityFromArgs.apply(this, arguments);
|
235 | if (!resultEntityActionObj) {
|
236 | resultEntityActionObj = {};
|
237 | }
|
238 | return this.preCreate(resultEntityActionObj)
|
239 | .then((params) => {
|
240 | return super.post(params.inputEntity).then((updatedDbObj) => {
|
241 | resultEntityActionObj.newPersistentEntity = updatedDbObj;
|
242 | return this.postCreate(resultEntityActionObj).then((result) => result.newPersistentEntity);
|
243 | }, (error) => {
|
244 | return Q.reject(error);
|
245 | });
|
246 | }, (error) => {
|
247 | return Q.reject(error);
|
248 | });
|
249 | }
|
250 | delete(obj) {
|
251 | let resultEntityActionObj = this.getEntityFromArgs.apply(this, arguments);
|
252 | if (!resultEntityActionObj) {
|
253 | resultEntityActionObj = {};
|
254 | }
|
255 | this.logEntityInfo("delete", resultEntityActionObj.newPersistentEntity._id);
|
256 | return this.preDelete(resultEntityActionObj)
|
257 | .then((params) => {
|
258 | return super.delete(resultEntityActionObj.newPersistentEntity._id).then((updatedDbObj) => {
|
259 | resultEntityActionObj.newPersistentEntity = updatedDbObj;
|
260 | return this.postDelete(resultEntityActionObj).then((result) => result.newPersistentEntity);
|
261 | }, (error) => {
|
262 | return Q.reject(error);
|
263 | });
|
264 | }, (error) => {
|
265 | return Q.reject(error);
|
266 | });
|
267 | }
|
268 | patch(id, obj) {
|
269 | this.logEntityInfo("patch", obj);
|
270 | let resultEntityActionObj = this.getEntityFromArgs.apply(this, arguments);
|
271 | if (!resultEntityActionObj) {
|
272 | resultEntityActionObj = {};
|
273 | }
|
274 | return this.preUpdate(resultEntityActionObj)
|
275 | .then((params) => {
|
276 | params.inputEntity.__dbEntity = params.oldPersistentEntity;
|
277 | return super.patch(id, params.inputEntity).then((updatedDbObj) => {
|
278 | resultEntityActionObj.newPersistentEntity = updatedDbObj;
|
279 |
|
280 | return this.postUpdate(resultEntityActionObj).then((updatedEntity) => {
|
281 | return Q.when(updatedEntity.newPersistentEntity);
|
282 | }, (exc) => {
|
283 | return Q.reject(exc);
|
284 | });
|
285 | }, (error) => {
|
286 | return Q.reject(error);
|
287 | });
|
288 | }, (error) => {
|
289 | return Q.reject(error);
|
290 | });
|
291 | }
|
292 |
|
293 | findAll() {
|
294 | let actionEntities = this.getEntityFromArgs.apply(this, arguments);
|
295 | if (!actionEntities) {
|
296 | actionEntities = [];
|
297 | }
|
298 | return this.postBulkRead(actionEntities).then((newResults) => {
|
299 | return Q.when(newResults.map((x) => x.newPersistentEntity));
|
300 | }).catch(exc => {
|
301 | this.logger.logError(exc);
|
302 | return Q.reject(exc);
|
303 | });
|
304 | }
|
305 | getEntityType() {
|
306 | return super.getEntityType();
|
307 | }
|
308 | getEntityFromArgs() {
|
309 | let args = Array.apply(null, arguments);
|
310 | let params = args[args.length - 1];
|
311 | return params;
|
312 | }
|
313 | logEntityInfo(methodName, obj) {
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | }
|
320 | }
|
321 | __decorate([
|
322 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canCreateEntities" }),
|
323 | __metadata('design:type', Function),
|
324 | __metadata('design:paramtypes', [Array, Number]),
|
325 | __metadata('design:returntype', Object)
|
326 | ], AuthorizationRepository.prototype, "bulkPost", null);
|
327 | __decorate([
|
328 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canSaveEntities" }),
|
329 | __metadata('design:type', Function),
|
330 | __metadata('design:paramtypes', [Array, Number, Boolean]),
|
331 | __metadata('design:returntype', void 0)
|
332 | ], AuthorizationRepository.prototype, "bulkPut", null);
|
333 | __decorate([
|
334 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canSaveEntities" }),
|
335 | __metadata('design:type', Function),
|
336 | __metadata('design:paramtypes', [Array]),
|
337 | __metadata('design:returntype', void 0)
|
338 | ], AuthorizationRepository.prototype, "bulkDel", null);
|
339 | __decorate([
|
340 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canReadActionEntity" }),
|
341 | __metadata('design:type', Function),
|
342 | __metadata('design:paramtypes', [Object, Boolean]),
|
343 | __metadata('design:returntype', Object)
|
344 | ], AuthorizationRepository.prototype, "findOne", null);
|
345 | __decorate([
|
346 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canReadActionEntities" }),
|
347 | __metadata('design:type', Function),
|
348 | __metadata('design:paramtypes', [Array, Boolean]),
|
349 | __metadata('design:returntype', Object)
|
350 | ], AuthorizationRepository.prototype, "findMany", null);
|
351 | __decorate([
|
352 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canReadActionEntities" }),
|
353 | __metadata('design:type', Function),
|
354 | __metadata('design:paramtypes', [Object, Object, Object, Boolean]),
|
355 | __metadata('design:returntype', Object)
|
356 | ], AuthorizationRepository.prototype, "findWhere", null);
|
357 | __decorate([
|
358 | postfilter_1.postfilter({ serviceName: "authorizationService", methodName: "canReadChildren" }),
|
359 | __metadata('design:type', Function),
|
360 | __metadata('design:paramtypes', [Object, Object]),
|
361 | __metadata('design:returntype', Object)
|
362 | ], AuthorizationRepository.prototype, "findChild", null);
|
363 | __decorate([
|
364 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canSaveEntity" }),
|
365 | __metadata('design:type', Function),
|
366 | __metadata('design:paramtypes', [Object, Object]),
|
367 | __metadata('design:returntype', Object)
|
368 | ], AuthorizationRepository.prototype, "put", null);
|
369 | __decorate([
|
370 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canSaveEntity" }),
|
371 | __metadata('design:type', Function),
|
372 | __metadata('design:paramtypes', [Object]),
|
373 | __metadata('design:returntype', Object)
|
374 | ], AuthorizationRepository.prototype, "post", null);
|
375 | __decorate([
|
376 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canDeleteEntity" }),
|
377 | __metadata('design:type', Function),
|
378 | __metadata('design:paramtypes', [Object]),
|
379 | __metadata('design:returntype', void 0)
|
380 | ], AuthorizationRepository.prototype, "delete", null);
|
381 | __decorate([
|
382 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canSaveEntity" }),
|
383 | __metadata('design:type', Function),
|
384 | __metadata('design:paramtypes', [Object, Object]),
|
385 | __metadata('design:returntype', void 0)
|
386 | ], AuthorizationRepository.prototype, "patch", null);
|
387 | __decorate([
|
388 | entityAction_1.entityAction({ serviceName: "authorizationService", methodName: "canReadActionEntities" }),
|
389 | __metadata('design:type', Function),
|
390 | __metadata('design:paramtypes', []),
|
391 | __metadata('design:returntype', Object)
|
392 | ], AuthorizationRepository.prototype, "findAll", null);
|
393 | exports.AuthorizationRepository = AuthorizationRepository;
|
394 | Object.defineProperty(exports, "__esModule", { value: true });
|
395 | exports.default = AuthorizationRepository;
|
396 |
|
397 |
|