not-node 6.3.18 → 6.3.20
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/package.json +1 -1
- package/src/bootstrap/logic.js +2 -5
- package/src/generic/logic.js +122 -344
- package/src/generic/route.js +0 -10
- package/src/manifest/route.js +0 -1
package/package.json
CHANGED
package/src/bootstrap/logic.js
CHANGED
|
@@ -14,17 +14,14 @@ module.exports = ({
|
|
|
14
14
|
const phrase = modulePhrase(MODULE_NAME);
|
|
15
15
|
const config = configInit.readerForModule(MODULE_NAME);
|
|
16
16
|
|
|
17
|
-
const LogAction = (
|
|
17
|
+
const LogAction = (action, identity, params = {}) => {
|
|
18
18
|
Log &&
|
|
19
19
|
Log.log({
|
|
20
20
|
time: new Date(),
|
|
21
21
|
module: MODULE_NAME,
|
|
22
22
|
logic: MODEL_NAME,
|
|
23
23
|
action,
|
|
24
|
-
|
|
25
|
-
by,
|
|
26
|
-
role,
|
|
27
|
-
ip,
|
|
24
|
+
...identity,
|
|
28
25
|
params,
|
|
29
26
|
});
|
|
30
27
|
};
|
package/src/generic/logic.js
CHANGED
|
@@ -29,6 +29,19 @@ module.exports = ({
|
|
|
29
29
|
populateBuilders = {},
|
|
30
30
|
defaultPopulate = [],
|
|
31
31
|
}) => {
|
|
32
|
+
const logDebugAction = (action, identity) => {
|
|
33
|
+
Log.debug(
|
|
34
|
+
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
35
|
+
identity?.ip,
|
|
36
|
+
identity?.root
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
const checkShouldOwn = (data, shouldOwn, identity) => {
|
|
40
|
+
if (shouldOwn) {
|
|
41
|
+
data[ownerFieldName] = identity?.uid;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
32
45
|
/**
|
|
33
46
|
* what to populate in action
|
|
34
47
|
*/
|
|
@@ -63,35 +76,13 @@ module.exports = ({
|
|
|
63
76
|
* @param {import('../types').PreparedData} prepared
|
|
64
77
|
* @returns {Promise<Object>}
|
|
65
78
|
*/
|
|
66
|
-
static async _create({
|
|
67
|
-
action,
|
|
68
|
-
data,
|
|
69
|
-
activeUser,
|
|
70
|
-
ip,
|
|
71
|
-
root = false,
|
|
72
|
-
shouldOwn = false,
|
|
73
|
-
}) {
|
|
74
|
-
Log.debug(
|
|
75
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
76
|
-
ip,
|
|
77
|
-
root
|
|
78
|
-
);
|
|
79
|
-
if (shouldOwn) {
|
|
80
|
-
data[ownerFieldName] = activeUser?._id;
|
|
81
|
-
}
|
|
79
|
+
static async _create({ action, data, identity, shouldOwn = false }) {
|
|
80
|
+
logDebugAction(action, identity);
|
|
81
|
+
checkShouldOwn(data, shouldOwn, identity);
|
|
82
82
|
const res = await getModel().add(data);
|
|
83
|
-
LogAction(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
by: activeUser?._id,
|
|
87
|
-
role: activeUser?.role,
|
|
88
|
-
ip,
|
|
89
|
-
root,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
targetId: res._id,
|
|
93
|
-
}
|
|
94
|
-
);
|
|
83
|
+
LogAction(action, identity, {
|
|
84
|
+
targetId: res._id,
|
|
85
|
+
});
|
|
95
86
|
return res;
|
|
96
87
|
}
|
|
97
88
|
|
|
@@ -100,12 +91,10 @@ module.exports = ({
|
|
|
100
91
|
* @param {import('../types').PreparedData} prepared
|
|
101
92
|
* @returns {Promise<Object>} new document
|
|
102
93
|
**/
|
|
103
|
-
static async create({ data,
|
|
94
|
+
static async create({ data, identity }) {
|
|
104
95
|
return await this._create({
|
|
105
96
|
data,
|
|
106
|
-
|
|
107
|
-
ip,
|
|
108
|
-
root,
|
|
97
|
+
identity,
|
|
109
98
|
action: "create",
|
|
110
99
|
shouldOwn: false,
|
|
111
100
|
});
|
|
@@ -116,12 +105,10 @@ module.exports = ({
|
|
|
116
105
|
* @param {import('../types').PreparedData} prepared
|
|
117
106
|
* @returns {Promise<Object>} new document
|
|
118
107
|
**/
|
|
119
|
-
static async createOwn({ data,
|
|
108
|
+
static async createOwn({ data, identity }) {
|
|
120
109
|
return await this._create({
|
|
121
110
|
data,
|
|
122
|
-
|
|
123
|
-
ip,
|
|
124
|
-
root,
|
|
111
|
+
identity,
|
|
125
112
|
action: "createOwn",
|
|
126
113
|
shouldOwn: true,
|
|
127
114
|
});
|
|
@@ -135,37 +122,20 @@ module.exports = ({
|
|
|
135
122
|
static async _updateOne({
|
|
136
123
|
targetId,
|
|
137
124
|
data,
|
|
138
|
-
|
|
125
|
+
identity,
|
|
139
126
|
action,
|
|
140
|
-
root,
|
|
141
|
-
ip,
|
|
142
127
|
shouldOwn = true,
|
|
143
128
|
}) {
|
|
144
|
-
|
|
145
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
146
|
-
targetId,
|
|
147
|
-
ip,
|
|
148
|
-
root
|
|
149
|
-
);
|
|
129
|
+
logDebugAction(action, identity);
|
|
150
130
|
let query = {
|
|
151
131
|
_id: targetId,
|
|
152
132
|
};
|
|
153
|
-
|
|
154
|
-
query[ownerFieldName] = activeUser?._id;
|
|
155
|
-
}
|
|
133
|
+
checkShouldOwn(query, shouldOwn, identity);
|
|
156
134
|
const result = await getModel().update(query, data);
|
|
157
|
-
LogAction(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
role: activeUser?.role,
|
|
162
|
-
ip,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
targetId,
|
|
166
|
-
version: result.__version,
|
|
167
|
-
}
|
|
168
|
-
);
|
|
135
|
+
LogAction(action, identity, {
|
|
136
|
+
targetId,
|
|
137
|
+
version: result.__version,
|
|
138
|
+
});
|
|
169
139
|
return result;
|
|
170
140
|
}
|
|
171
141
|
|
|
@@ -174,13 +144,11 @@ module.exports = ({
|
|
|
174
144
|
* @param {import('../types').PreparedData} prepared
|
|
175
145
|
* @returns {Promise<Object>} updated document
|
|
176
146
|
**/
|
|
177
|
-
static async update({ targetId, data,
|
|
147
|
+
static async update({ targetId, data, identity }) {
|
|
178
148
|
return await this._updateOne({
|
|
179
149
|
targetId,
|
|
180
150
|
data,
|
|
181
|
-
|
|
182
|
-
ip,
|
|
183
|
-
root,
|
|
151
|
+
identity,
|
|
184
152
|
action: "update",
|
|
185
153
|
shouldOwn: false,
|
|
186
154
|
});
|
|
@@ -191,19 +159,11 @@ module.exports = ({
|
|
|
191
159
|
* @param {import('../types').PreparedData} prepared
|
|
192
160
|
* @returns {Promise<Object>} updated document
|
|
193
161
|
**/
|
|
194
|
-
static async updateOwn({
|
|
195
|
-
targetId,
|
|
196
|
-
data,
|
|
197
|
-
activeUser,
|
|
198
|
-
ip,
|
|
199
|
-
root = false,
|
|
200
|
-
}) {
|
|
162
|
+
static async updateOwn({ targetId, data, identity }) {
|
|
201
163
|
return await this._updateOne({
|
|
202
164
|
targetId,
|
|
203
165
|
data,
|
|
204
|
-
|
|
205
|
-
ip,
|
|
206
|
-
root,
|
|
166
|
+
identity,
|
|
207
167
|
action: "updateOwn",
|
|
208
168
|
shouldOwn: true,
|
|
209
169
|
});
|
|
@@ -214,43 +174,19 @@ module.exports = ({
|
|
|
214
174
|
* @param {import('../types').PreparedData} prepared
|
|
215
175
|
* @returns {Promise<Object>} requested document
|
|
216
176
|
**/
|
|
217
|
-
static async _getOne({
|
|
218
|
-
|
|
219
|
-
action,
|
|
220
|
-
ip,
|
|
221
|
-
root,
|
|
222
|
-
activeUser,
|
|
223
|
-
shouldOwn = true,
|
|
224
|
-
}) {
|
|
225
|
-
Log.debug(
|
|
226
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
227
|
-
targetId,
|
|
228
|
-
ip,
|
|
229
|
-
root
|
|
230
|
-
);
|
|
177
|
+
static async _getOne({ targetId, action, identity, shouldOwn = true }) {
|
|
178
|
+
logDebugAction(action, identity);
|
|
231
179
|
let query = {};
|
|
232
|
-
|
|
233
|
-
query[ownerFieldName] = activeUser?._id;
|
|
234
|
-
}
|
|
180
|
+
checkShouldOwn(query, shouldOwn, identity);
|
|
235
181
|
let populate = await getPopulate(action, {
|
|
236
182
|
targetId,
|
|
237
|
-
|
|
238
|
-
ip,
|
|
239
|
-
root,
|
|
183
|
+
identity,
|
|
240
184
|
});
|
|
241
185
|
const result = await getModel().getOne(targetId, populate, query);
|
|
242
|
-
LogAction(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
role: activeUser?.role,
|
|
247
|
-
ip,
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
targetId,
|
|
251
|
-
version: result.__version,
|
|
252
|
-
}
|
|
253
|
-
);
|
|
186
|
+
LogAction(action, identity, {
|
|
187
|
+
targetId,
|
|
188
|
+
version: result.__version,
|
|
189
|
+
});
|
|
254
190
|
return result;
|
|
255
191
|
}
|
|
256
192
|
|
|
@@ -259,13 +195,11 @@ module.exports = ({
|
|
|
259
195
|
* @param {import('../types').PreparedData} prepared
|
|
260
196
|
* @returns {Promise<Object>} requested document
|
|
261
197
|
**/
|
|
262
|
-
static async get({ targetId,
|
|
198
|
+
static async get({ targetId, identity }) {
|
|
263
199
|
return await this._getOne({
|
|
264
200
|
targetId,
|
|
265
201
|
action: "get",
|
|
266
|
-
|
|
267
|
-
ip,
|
|
268
|
-
root,
|
|
202
|
+
identity,
|
|
269
203
|
shouldOwn: false,
|
|
270
204
|
});
|
|
271
205
|
}
|
|
@@ -275,13 +209,11 @@ module.exports = ({
|
|
|
275
209
|
* @param {import('../types').PreparedData} prepared
|
|
276
210
|
* @returns {Promise<Object>} requested document
|
|
277
211
|
**/
|
|
278
|
-
static async getOwn({ targetId,
|
|
212
|
+
static async getOwn({ targetId, identity }) {
|
|
279
213
|
return await this._getOne({
|
|
280
214
|
targetId,
|
|
281
215
|
action: "getOwn",
|
|
282
|
-
|
|
283
|
-
ip,
|
|
284
|
-
root,
|
|
216
|
+
identity,
|
|
285
217
|
shouldOwn: true,
|
|
286
218
|
});
|
|
287
219
|
}
|
|
@@ -294,44 +226,25 @@ module.exports = ({
|
|
|
294
226
|
static async _getOneByID({
|
|
295
227
|
targetID,
|
|
296
228
|
action,
|
|
297
|
-
|
|
298
|
-
root,
|
|
299
|
-
activeUser,
|
|
229
|
+
identity,
|
|
300
230
|
shouldOwn = true,
|
|
301
231
|
}) {
|
|
302
|
-
|
|
303
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
304
|
-
targetID,
|
|
305
|
-
ip,
|
|
306
|
-
root
|
|
307
|
-
);
|
|
232
|
+
logDebugAction(action, identity);
|
|
308
233
|
let query = {};
|
|
309
|
-
|
|
310
|
-
query[ownerFieldName] = activeUser?._id;
|
|
311
|
-
}
|
|
234
|
+
checkShouldOwn(query, shouldOwn, identity);
|
|
312
235
|
let populate = await getPopulate(action, {
|
|
313
236
|
targetID,
|
|
314
|
-
|
|
315
|
-
ip,
|
|
316
|
-
root,
|
|
237
|
+
identity,
|
|
317
238
|
});
|
|
318
239
|
const result = await getModel().getOneByID(
|
|
319
240
|
targetID,
|
|
320
241
|
query,
|
|
321
242
|
populate
|
|
322
243
|
);
|
|
323
|
-
LogAction(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
role: activeUser?.role,
|
|
328
|
-
ip,
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
targetID,
|
|
332
|
-
version: result.__version,
|
|
333
|
-
}
|
|
334
|
-
);
|
|
244
|
+
LogAction(action, identity, {
|
|
245
|
+
targetID,
|
|
246
|
+
version: result.__version,
|
|
247
|
+
});
|
|
335
248
|
return result;
|
|
336
249
|
}
|
|
337
250
|
|
|
@@ -340,13 +253,11 @@ module.exports = ({
|
|
|
340
253
|
* @param {import('../types').PreparedData} prepared
|
|
341
254
|
* @returns {Promise<Object>} requested document
|
|
342
255
|
**/
|
|
343
|
-
static async getByID({ targetID,
|
|
256
|
+
static async getByID({ targetID, identity }) {
|
|
344
257
|
return await this._getOneByID({
|
|
345
258
|
targetID,
|
|
346
259
|
action: "getByID",
|
|
347
|
-
|
|
348
|
-
ip,
|
|
349
|
-
root,
|
|
260
|
+
identity,
|
|
350
261
|
shouldOwn: false,
|
|
351
262
|
});
|
|
352
263
|
}
|
|
@@ -356,13 +267,11 @@ module.exports = ({
|
|
|
356
267
|
* @param {import('../types').PreparedData} prepared
|
|
357
268
|
* @returns {Promise<Object>} requested document
|
|
358
269
|
**/
|
|
359
|
-
static async getByIDOwn({ targetID,
|
|
270
|
+
static async getByIDOwn({ targetID, identity }) {
|
|
360
271
|
return await this._getOneByID({
|
|
361
272
|
targetID,
|
|
362
273
|
action: "getByIDOwn",
|
|
363
|
-
|
|
364
|
-
ip,
|
|
365
|
-
root,
|
|
274
|
+
identity,
|
|
366
275
|
shouldOwn: true,
|
|
367
276
|
});
|
|
368
277
|
}
|
|
@@ -374,36 +283,18 @@ module.exports = ({
|
|
|
374
283
|
**/
|
|
375
284
|
static async _getOneRaw({
|
|
376
285
|
targetId,
|
|
377
|
-
|
|
378
|
-
ip,
|
|
379
|
-
root,
|
|
286
|
+
identity,
|
|
380
287
|
action,
|
|
381
288
|
shouldOwn = true,
|
|
382
289
|
}) {
|
|
383
|
-
|
|
384
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
385
|
-
targetId,
|
|
386
|
-
ip,
|
|
387
|
-
root
|
|
388
|
-
);
|
|
290
|
+
logDebugAction(action, identity);
|
|
389
291
|
let query = {};
|
|
390
|
-
|
|
391
|
-
query[ownerFieldName] = activeUser?._id;
|
|
392
|
-
}
|
|
292
|
+
checkShouldOwn(query, shouldOwn, identity);
|
|
393
293
|
const result = await getModel().getOneRaw(targetId, query);
|
|
394
|
-
LogAction(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
role: activeUser?.role,
|
|
399
|
-
ip,
|
|
400
|
-
root,
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
targetId,
|
|
404
|
-
version: result.__version,
|
|
405
|
-
}
|
|
406
|
-
);
|
|
294
|
+
LogAction(action, identity, {
|
|
295
|
+
targetId,
|
|
296
|
+
version: result.__version,
|
|
297
|
+
});
|
|
407
298
|
return result;
|
|
408
299
|
}
|
|
409
300
|
|
|
@@ -412,14 +303,12 @@ module.exports = ({
|
|
|
412
303
|
* @param {import('../types').PreparedData} prepared
|
|
413
304
|
* @returns {Promise<Object>} requested document
|
|
414
305
|
**/
|
|
415
|
-
static async getRaw({ targetId,
|
|
306
|
+
static async getRaw({ targetId, identity }) {
|
|
416
307
|
return await this._getOneRaw({
|
|
417
308
|
targetId,
|
|
418
|
-
|
|
309
|
+
identity,
|
|
419
310
|
shouldOwn: false,
|
|
420
311
|
action: "getRaw",
|
|
421
|
-
ip,
|
|
422
|
-
root,
|
|
423
312
|
});
|
|
424
313
|
}
|
|
425
314
|
|
|
@@ -428,14 +317,12 @@ module.exports = ({
|
|
|
428
317
|
* @param {import('../types').PreparedData} prepared
|
|
429
318
|
* @returns {Promise<Object>} requested document
|
|
430
319
|
**/
|
|
431
|
-
static async getOwnRaw({ targetId,
|
|
320
|
+
static async getOwnRaw({ targetId, identity }) {
|
|
432
321
|
return await this._getOneRaw({
|
|
433
322
|
targetId,
|
|
434
|
-
|
|
323
|
+
identity,
|
|
435
324
|
shouldOwn: true,
|
|
436
325
|
action: "getOwnRaw",
|
|
437
|
-
ip,
|
|
438
|
-
root,
|
|
439
326
|
});
|
|
440
327
|
}
|
|
441
328
|
|
|
@@ -446,18 +333,11 @@ module.exports = ({
|
|
|
446
333
|
**/
|
|
447
334
|
static async _delete({
|
|
448
335
|
action,
|
|
449
|
-
ip,
|
|
450
|
-
root,
|
|
451
336
|
targetId,
|
|
452
|
-
|
|
337
|
+
identity,
|
|
453
338
|
shouldOwn = false,
|
|
454
339
|
}) {
|
|
455
|
-
|
|
456
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
457
|
-
targetId,
|
|
458
|
-
ip,
|
|
459
|
-
root
|
|
460
|
-
);
|
|
340
|
+
logDebugAction(action, identity);
|
|
461
341
|
const model = getModel();
|
|
462
342
|
const versioning = ModelRoutine.versioning(model);
|
|
463
343
|
if (versioning) {
|
|
@@ -465,12 +345,12 @@ module.exports = ({
|
|
|
465
345
|
if (!itm) {
|
|
466
346
|
throw new DBExceptionDocumentIsNotFound();
|
|
467
347
|
}
|
|
468
|
-
if (shouldOwn && !isOwner(itm,
|
|
348
|
+
if (shouldOwn && !isOwner(itm, identity?.uid)) {
|
|
469
349
|
throw new DBExceptionDocumentIsNotOwnerByActiveUser({
|
|
470
350
|
params: {
|
|
471
351
|
targetId,
|
|
472
|
-
activeUserId:
|
|
473
|
-
role:
|
|
352
|
+
activeUserId: identity?.uid,
|
|
353
|
+
role: identity?.role,
|
|
474
354
|
versioning,
|
|
475
355
|
},
|
|
476
356
|
});
|
|
@@ -479,34 +359,23 @@ module.exports = ({
|
|
|
479
359
|
}
|
|
480
360
|
} else {
|
|
481
361
|
let query = { _id: targetId };
|
|
482
|
-
|
|
483
|
-
query[ownerFieldName] = activeUser?._id;
|
|
484
|
-
}
|
|
362
|
+
checkShouldOwn(query, shouldOwn, identity);
|
|
485
363
|
const result = await model.findOneAndDelete(query).exec();
|
|
486
364
|
if (!deleteResponseSuccess(result)) {
|
|
487
365
|
throw new DBExceptionDeleteWasNotSuccessful({
|
|
488
366
|
params: {
|
|
489
367
|
result,
|
|
490
368
|
targetId,
|
|
491
|
-
activeUserId:
|
|
492
|
-
role:
|
|
369
|
+
activeUserId: identity?.uid,
|
|
370
|
+
role: identity?.role,
|
|
493
371
|
versioning,
|
|
494
372
|
},
|
|
495
373
|
});
|
|
496
374
|
}
|
|
497
375
|
}
|
|
498
|
-
LogAction(
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
by: activeUser?._id,
|
|
502
|
-
role: activeUser?.role,
|
|
503
|
-
ip,
|
|
504
|
-
root,
|
|
505
|
-
},
|
|
506
|
-
{
|
|
507
|
-
targetId,
|
|
508
|
-
}
|
|
509
|
-
);
|
|
376
|
+
LogAction(action, identity, {
|
|
377
|
+
targetId,
|
|
378
|
+
});
|
|
510
379
|
}
|
|
511
380
|
|
|
512
381
|
/**
|
|
@@ -514,13 +383,11 @@ module.exports = ({
|
|
|
514
383
|
* @param {import('../types').PreparedData} prepared
|
|
515
384
|
* @returns {Promise<Object>} requested document
|
|
516
385
|
**/
|
|
517
|
-
static async delete({ targetId,
|
|
386
|
+
static async delete({ targetId, identity }) {
|
|
518
387
|
await this._delete({
|
|
519
388
|
action: "delete",
|
|
520
389
|
targetId,
|
|
521
|
-
|
|
522
|
-
ip,
|
|
523
|
-
activeUser,
|
|
390
|
+
identity,
|
|
524
391
|
shouldOwn: false,
|
|
525
392
|
});
|
|
526
393
|
}
|
|
@@ -530,13 +397,11 @@ module.exports = ({
|
|
|
530
397
|
* @param {import('../types').PreparedData} prepared
|
|
531
398
|
* @returns {Promise<Object>} requested document
|
|
532
399
|
**/
|
|
533
|
-
static async deleteOwn({ targetId,
|
|
400
|
+
static async deleteOwn({ targetId, identity }) {
|
|
534
401
|
await this._delete({
|
|
535
402
|
action: "deleteOwn",
|
|
536
403
|
targetId,
|
|
537
|
-
|
|
538
|
-
root,
|
|
539
|
-
activeUser,
|
|
404
|
+
identity,
|
|
540
405
|
shouldOwn: true,
|
|
541
406
|
});
|
|
542
407
|
}
|
|
@@ -546,51 +411,26 @@ module.exports = ({
|
|
|
546
411
|
* @param {import('../types').PreparedData} prepared
|
|
547
412
|
* @returns {Promise<Array<Object>>}
|
|
548
413
|
*/
|
|
549
|
-
static async _listAll({
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
shouldOwn = false,
|
|
554
|
-
root,
|
|
555
|
-
}) {
|
|
556
|
-
Log.debug(
|
|
557
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
558
|
-
ip,
|
|
559
|
-
root
|
|
560
|
-
);
|
|
561
|
-
let filter;
|
|
562
|
-
if (shouldOwn) {
|
|
563
|
-
filter = {
|
|
564
|
-
[ownerFieldName]: activeUser?._id,
|
|
565
|
-
};
|
|
566
|
-
}
|
|
414
|
+
static async _listAll({ identity, action, shouldOwn = false }) {
|
|
415
|
+
logDebugAction(action, identity);
|
|
416
|
+
let filter = {};
|
|
417
|
+
checkShouldOwn(filter, shouldOwn, identity);
|
|
567
418
|
const result = await getModel().listAll(filter);
|
|
568
|
-
LogAction({
|
|
569
|
-
|
|
570
|
-
by: activeUser?._id,
|
|
571
|
-
role: activeUser?.role,
|
|
572
|
-
ip,
|
|
573
|
-
root,
|
|
574
|
-
shouldOwn,
|
|
575
|
-
});
|
|
576
|
-
return result;
|
|
419
|
+
LogAction(action, identity, { shouldOwn });
|
|
420
|
+
return result.map((itm) => itm.toObject());
|
|
577
421
|
}
|
|
578
422
|
|
|
579
|
-
static async listAll({
|
|
423
|
+
static async listAll({ identity }) {
|
|
580
424
|
return await this._listAll({
|
|
581
|
-
|
|
582
|
-
ip,
|
|
583
|
-
root,
|
|
425
|
+
identity,
|
|
584
426
|
action: "listAll",
|
|
585
427
|
shouldOwn: false,
|
|
586
428
|
});
|
|
587
429
|
}
|
|
588
430
|
|
|
589
|
-
static async listAllOwn({
|
|
431
|
+
static async listAllOwn({ identity }) {
|
|
590
432
|
return await this._listAll({
|
|
591
|
-
|
|
592
|
-
ip,
|
|
593
|
-
root,
|
|
433
|
+
identity,
|
|
594
434
|
action: "listAllOwn",
|
|
595
435
|
shouldOwn: true,
|
|
596
436
|
});
|
|
@@ -598,25 +438,18 @@ module.exports = ({
|
|
|
598
438
|
|
|
599
439
|
static async _listAndCount({
|
|
600
440
|
query,
|
|
601
|
-
activeUser,
|
|
602
|
-
ip,
|
|
603
441
|
action,
|
|
604
|
-
|
|
442
|
+
identity,
|
|
605
443
|
shouldOwn = false,
|
|
606
444
|
}) {
|
|
607
|
-
|
|
608
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
609
|
-
ip,
|
|
610
|
-
root
|
|
611
|
-
);
|
|
445
|
+
logDebugAction(action, identity);
|
|
612
446
|
const { skip, size, sorter, filter, search } = query;
|
|
613
447
|
let populate = await getPopulate(action, {
|
|
614
|
-
|
|
615
|
-
ip,
|
|
448
|
+
identity,
|
|
616
449
|
});
|
|
617
450
|
if (shouldOwn) {
|
|
618
451
|
notFilter.filter.modifyRules(filter, {
|
|
619
|
-
[ownerFieldName]:
|
|
452
|
+
[ownerFieldName]: identity?.uid,
|
|
620
453
|
});
|
|
621
454
|
}
|
|
622
455
|
const result = await getModel().listAndCount(
|
|
@@ -627,60 +460,38 @@ module.exports = ({
|
|
|
627
460
|
search,
|
|
628
461
|
populate
|
|
629
462
|
);
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
by: activeUser?._id,
|
|
633
|
-
role: activeUser?.role,
|
|
634
|
-
ip,
|
|
635
|
-
root,
|
|
636
|
-
shouldOwn,
|
|
637
|
-
});
|
|
463
|
+
result.list = result.list.map((itm) => itm.toObject());
|
|
464
|
+
LogAction(action, identity, { shouldOwn });
|
|
638
465
|
return result;
|
|
639
466
|
}
|
|
640
467
|
|
|
641
|
-
static async listAndCount({ query,
|
|
468
|
+
static async listAndCount({ query, identity }) {
|
|
642
469
|
return await this._listAndCount({
|
|
643
470
|
query,
|
|
644
|
-
|
|
645
|
-
ip,
|
|
646
|
-
root,
|
|
471
|
+
identity,
|
|
647
472
|
action: "listAndCount",
|
|
648
473
|
shouldOwn: false,
|
|
649
474
|
});
|
|
650
475
|
}
|
|
651
476
|
|
|
652
|
-
static async listAndCountOwn({ query,
|
|
477
|
+
static async listAndCountOwn({ query, identity }) {
|
|
653
478
|
return await this._listAndCount({
|
|
654
479
|
query,
|
|
655
|
-
|
|
656
|
-
ip,
|
|
657
|
-
root,
|
|
480
|
+
identity,
|
|
658
481
|
action: "listAndCountOwn",
|
|
659
482
|
shouldOwn: true,
|
|
660
483
|
});
|
|
661
484
|
}
|
|
662
485
|
|
|
663
|
-
static async _list({
|
|
664
|
-
|
|
665
|
-
activeUser,
|
|
666
|
-
ip,
|
|
667
|
-
action,
|
|
668
|
-
root,
|
|
669
|
-
shouldOwn = false,
|
|
670
|
-
}) {
|
|
671
|
-
Log.debug(
|
|
672
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
673
|
-
ip,
|
|
674
|
-
root
|
|
675
|
-
);
|
|
486
|
+
static async _list({ query, identity, action, shouldOwn = false }) {
|
|
487
|
+
logDebugAction(action, identity);
|
|
676
488
|
const { skip, size, sorter, filter } = query;
|
|
677
489
|
let populate = await getPopulate(action, {
|
|
678
|
-
|
|
679
|
-
ip,
|
|
490
|
+
identity,
|
|
680
491
|
});
|
|
681
492
|
if (shouldOwn) {
|
|
682
493
|
notFilter.filter.modifyRules(filter, {
|
|
683
|
-
[ownerFieldName]:
|
|
494
|
+
[ownerFieldName]: identity?.uid,
|
|
684
495
|
});
|
|
685
496
|
}
|
|
686
497
|
const result = await getModel().listAndPopulate(
|
|
@@ -690,90 +501,57 @@ module.exports = ({
|
|
|
690
501
|
filter,
|
|
691
502
|
populate
|
|
692
503
|
);
|
|
693
|
-
LogAction({
|
|
694
|
-
|
|
695
|
-
by: activeUser?._id,
|
|
696
|
-
role: activeUser?.role,
|
|
697
|
-
ip,
|
|
698
|
-
root,
|
|
699
|
-
shouldOwn,
|
|
700
|
-
});
|
|
701
|
-
return result;
|
|
504
|
+
LogAction(action, identity, { shouldOwn });
|
|
505
|
+
return result.map((itm) => itm.toObject());
|
|
702
506
|
}
|
|
703
507
|
|
|
704
|
-
static async list({ query,
|
|
508
|
+
static async list({ query, identity }) {
|
|
705
509
|
return await this._list({
|
|
706
510
|
query,
|
|
707
|
-
|
|
708
|
-
ip,
|
|
709
|
-
root,
|
|
511
|
+
identity,
|
|
710
512
|
action: "list",
|
|
711
513
|
shouldOwn: false,
|
|
712
514
|
});
|
|
713
515
|
}
|
|
714
516
|
|
|
715
|
-
static async listOwn({ query,
|
|
517
|
+
static async listOwn({ query, identity }) {
|
|
716
518
|
return await this._list({
|
|
717
519
|
query,
|
|
718
|
-
|
|
719
|
-
ip,
|
|
720
|
-
root,
|
|
520
|
+
identity,
|
|
721
521
|
action: "listOwn",
|
|
722
522
|
shouldOwn: true,
|
|
723
523
|
});
|
|
724
524
|
}
|
|
725
525
|
|
|
726
|
-
static async _count({
|
|
727
|
-
|
|
728
|
-
activeUser,
|
|
729
|
-
ip,
|
|
730
|
-
action,
|
|
731
|
-
root,
|
|
732
|
-
shouldOwn = false,
|
|
733
|
-
}) {
|
|
734
|
-
Log.debug(
|
|
735
|
-
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
736
|
-
ip,
|
|
737
|
-
root
|
|
738
|
-
);
|
|
526
|
+
static async _count({ query, action, identity, shouldOwn = false }) {
|
|
527
|
+
logDebugAction(action, identity);
|
|
739
528
|
const { filter, search } = query;
|
|
740
529
|
if (shouldOwn) {
|
|
741
530
|
notFilter.filter.modifyRules(filter, {
|
|
742
|
-
[ownerFieldName]:
|
|
531
|
+
[ownerFieldName]: identity?.uid,
|
|
743
532
|
});
|
|
744
533
|
}
|
|
745
534
|
if (search) {
|
|
746
535
|
notFilter.filter.modifyRules(search, filter);
|
|
747
536
|
}
|
|
748
537
|
const result = await getModel().countWithFilter(search || filter);
|
|
749
|
-
LogAction({
|
|
750
|
-
action,
|
|
751
|
-
by: activeUser?._id,
|
|
752
|
-
role: activeUser?.role,
|
|
753
|
-
ip,
|
|
754
|
-
root,
|
|
755
|
-
shouldOwn,
|
|
756
|
-
});
|
|
538
|
+
LogAction(action, identity, { shouldOwn });
|
|
757
539
|
return result;
|
|
758
540
|
}
|
|
759
541
|
|
|
760
|
-
static async count({ query,
|
|
542
|
+
static async count({ query, identity }) {
|
|
761
543
|
return await this._count({
|
|
762
544
|
query,
|
|
763
|
-
|
|
764
|
-
ip,
|
|
765
|
-
root,
|
|
545
|
+
identity,
|
|
766
546
|
action: "count",
|
|
767
547
|
shouldOwn: false,
|
|
768
548
|
});
|
|
769
549
|
}
|
|
770
550
|
|
|
771
|
-
static async countOwn({ query,
|
|
551
|
+
static async countOwn({ query, identity }) {
|
|
772
552
|
return await this._count({
|
|
773
553
|
query,
|
|
774
|
-
|
|
775
|
-
ip,
|
|
776
|
-
root,
|
|
554
|
+
identity,
|
|
777
555
|
action: "countOwn",
|
|
778
556
|
shouldOwn: true,
|
|
779
557
|
});
|
package/src/generic/route.js
CHANGED
|
@@ -22,7 +22,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
22
22
|
...this.exceptionParamsPacker(prepared)
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
|
-
prepared.root = true;
|
|
26
25
|
return await getLogic().create(prepared);
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -36,7 +35,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
36
35
|
...this.exceptionParamsPacker(prepared)
|
|
37
36
|
);
|
|
38
37
|
}
|
|
39
|
-
prepared.root = true;
|
|
40
38
|
return await getLogic().get(prepared);
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -50,7 +48,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
50
48
|
...this.exceptionParamsPacker(prepared)
|
|
51
49
|
);
|
|
52
50
|
}
|
|
53
|
-
prepared.root = true;
|
|
54
51
|
return await getLogic().getByID(prepared);
|
|
55
52
|
}
|
|
56
53
|
|
|
@@ -64,7 +61,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
64
61
|
...this.exceptionParamsPacker(prepared)
|
|
65
62
|
);
|
|
66
63
|
}
|
|
67
|
-
prepared.root = true;
|
|
68
64
|
return await getLogic().getRaw(prepared);
|
|
69
65
|
}
|
|
70
66
|
|
|
@@ -78,7 +74,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
78
74
|
...this.exceptionParamsPacker(prepared)
|
|
79
75
|
);
|
|
80
76
|
}
|
|
81
|
-
prepared.root = true;
|
|
82
77
|
return await getLogic().update(prepared);
|
|
83
78
|
}
|
|
84
79
|
|
|
@@ -92,7 +87,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
92
87
|
...this.exceptionParamsPacker(prepared)
|
|
93
88
|
);
|
|
94
89
|
}
|
|
95
|
-
prepared.root = true;
|
|
96
90
|
return await getLogic().listAll(prepared);
|
|
97
91
|
}
|
|
98
92
|
|
|
@@ -106,7 +100,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
106
100
|
...this.exceptionParamsPacker(prepared)
|
|
107
101
|
);
|
|
108
102
|
}
|
|
109
|
-
prepared.root = true;
|
|
110
103
|
return await getLogic().listAndCount(prepared);
|
|
111
104
|
}
|
|
112
105
|
|
|
@@ -120,7 +113,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
120
113
|
...this.exceptionParamsPacker(prepared)
|
|
121
114
|
);
|
|
122
115
|
}
|
|
123
|
-
prepared.root = true;
|
|
124
116
|
return await getLogic().list(prepared);
|
|
125
117
|
}
|
|
126
118
|
|
|
@@ -134,7 +126,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
134
126
|
...this.exceptionParamsPacker(prepared)
|
|
135
127
|
);
|
|
136
128
|
}
|
|
137
|
-
prepared.root = true;
|
|
138
129
|
return await getLogic().count(prepared);
|
|
139
130
|
}
|
|
140
131
|
|
|
@@ -148,7 +139,6 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
148
139
|
...this.exceptionParamsPacker(prepared)
|
|
149
140
|
);
|
|
150
141
|
}
|
|
151
|
-
prepared.root = true;
|
|
152
142
|
return await getLogic().delete(prepared);
|
|
153
143
|
}
|
|
154
144
|
|