not-node 6.0.2 → 6.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
22
22
  const incField = `${firstLetterToLower(MODEL_NAME)}ID`;
23
23
  return {
24
24
  targetId: req.params[incField],
25
- activeUser: req.user,
26
- activeUserId: req.user._id,
25
+ activeUser: req?.user,
26
+ activeUserId: req?.user._id,
27
27
  ip: getIP(req),
28
28
  };
29
29
  }
@@ -21,8 +21,8 @@ module.exports = ({ MODULE_NAME, actionName }) => {
21
21
  extract(req) {
22
22
  return {
23
23
  targetId: req.params._id,
24
- activeUser: req.user,
25
- activeUserId: req.user._id,
24
+ activeUser: req?.user,
25
+ activeUserId: req?.user._id,
26
26
  ip: getIP(req),
27
27
  };
28
28
  }
@@ -43,8 +43,8 @@ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
43
43
  filter,
44
44
  search,
45
45
  },
46
- activeUser: req.user,
47
- activeUserId: req.user._id,
46
+ activeUser: req?.user,
47
+ activeUserId: req?.user._id,
48
48
  ip: getIP(req),
49
49
  };
50
50
  }
@@ -72,14 +72,14 @@ module.exports = ({
72
72
  root
73
73
  );
74
74
  if (shouldOwn) {
75
- data[ownerFieldName] = activeUser._id;
75
+ data[ownerFieldName] = activeUser?._id;
76
76
  }
77
77
  const res = await getModel().add(data);
78
78
  LogAction(
79
79
  {
80
80
  action,
81
- by: activeUser._id,
82
- role: activeUser.role,
81
+ by: activeUser?._id,
82
+ role: activeUser?.role,
83
83
  ip,
84
84
  root,
85
85
  },
@@ -149,14 +149,14 @@ module.exports = ({
149
149
  _id: targetId,
150
150
  };
151
151
  if (shouldOwn) {
152
- query[ownerFieldName] = activeUser._id;
152
+ query[ownerFieldName] = activeUser?._id;
153
153
  }
154
154
  const result = await getModel().update(query, data);
155
155
  LogAction(
156
156
  {
157
157
  action,
158
- by: activeUser._id,
159
- role: activeUser.role,
158
+ by: activeUser?._id,
159
+ role: activeUser?.role,
160
160
  ip,
161
161
  },
162
162
  {
@@ -243,7 +243,7 @@ module.exports = ({
243
243
  );
244
244
  let query = {};
245
245
  if (shouldOwn) {
246
- query[ownerFieldName] = activeUser._id;
246
+ query[ownerFieldName] = activeUser?._id;
247
247
  }
248
248
  let populate = getPopulate(action, {
249
249
  targetId,
@@ -255,8 +255,8 @@ module.exports = ({
255
255
  LogAction(
256
256
  {
257
257
  action,
258
- by: activeUser._id,
259
- role: activeUser.role,
258
+ by: activeUser?._id,
259
+ role: activeUser?.role,
260
260
  ip,
261
261
  },
262
262
  {
@@ -333,7 +333,7 @@ module.exports = ({
333
333
  );
334
334
  let query = {};
335
335
  if (shouldOwn) {
336
- query[ownerFieldName] = activeUser._id;
336
+ query[ownerFieldName] = activeUser?._id;
337
337
  }
338
338
  let populate = getPopulate(action, {
339
339
  targetID,
@@ -349,8 +349,8 @@ module.exports = ({
349
349
  LogAction(
350
350
  {
351
351
  action,
352
- by: activeUser._id,
353
- role: activeUser.role,
352
+ by: activeUser?._id,
353
+ role: activeUser?.role,
354
354
  ip,
355
355
  },
356
356
  {
@@ -427,14 +427,14 @@ module.exports = ({
427
427
  );
428
428
  let query = {};
429
429
  if (shouldOwn) {
430
- query[ownerFieldName] = activeUser._id;
430
+ query[ownerFieldName] = activeUser?._id;
431
431
  }
432
432
  const result = await getModel().getOneRaw(targetId, query);
433
433
  LogAction(
434
434
  {
435
435
  action,
436
- by: activeUser._id,
437
- role: activeUser.role,
436
+ by: activeUser?._id,
437
+ role: activeUser?.role,
438
438
  ip,
439
439
  root,
440
440
  },
@@ -516,12 +516,12 @@ module.exports = ({
516
516
  if (!itm) {
517
517
  throw new DBExceptionDocumentIsNotFound();
518
518
  }
519
- if (shouldOwn && !isOwner(itm, activeUser._id)) {
519
+ if (shouldOwn && !isOwner(itm, activeUser?._id)) {
520
520
  throw new DBExceptionDocumentIsNotOwnerByActiveUser({
521
521
  params: {
522
522
  targetId,
523
- activeUserId: activeUser._id,
524
- role: activeUser.role,
523
+ activeUserId: activeUser?._id,
524
+ role: activeUser?.role,
525
525
  versioning,
526
526
  },
527
527
  });
@@ -531,7 +531,7 @@ module.exports = ({
531
531
  } else {
532
532
  let query = { _id: targetId };
533
533
  if (shouldOwn) {
534
- query[ownerFieldName] = activeUser._id;
534
+ query[ownerFieldName] = activeUser?._id;
535
535
  }
536
536
  const result = await model.findOneAndDelete(query).exec();
537
537
  if (!deleteResponseSuccess(result)) {
@@ -539,8 +539,8 @@ module.exports = ({
539
539
  params: {
540
540
  result,
541
541
  targetId,
542
- activeUserId: activeUser._id,
543
- role: activeUser.role,
542
+ activeUserId: activeUser?._id,
543
+ role: activeUser?.role,
544
544
  versioning,
545
545
  },
546
546
  });
@@ -549,8 +549,8 @@ module.exports = ({
549
549
  LogAction(
550
550
  {
551
551
  action,
552
- by: activeUser._id,
553
- role: activeUser.role,
552
+ by: activeUser?._id,
553
+ role: activeUser?.role,
554
554
  ip,
555
555
  root,
556
556
  },
@@ -615,14 +615,14 @@ module.exports = ({
615
615
  let filter;
616
616
  if (shouldOwn) {
617
617
  filter = {
618
- [ownerFieldName]: activeUser._id,
618
+ [ownerFieldName]: activeUser?._id,
619
619
  };
620
620
  }
621
621
  const result = await getModel().listAll(filter);
622
622
  LogAction({
623
623
  action,
624
- by: activeUser._id,
625
- role: activeUser.role,
624
+ by: activeUser?._id,
625
+ role: activeUser?.role,
626
626
  ip,
627
627
  root,
628
628
  shouldOwn,
@@ -670,7 +670,7 @@ module.exports = ({
670
670
  });
671
671
  if (shouldOwn) {
672
672
  notFilter.filter.modifyRules(filter, {
673
- [ownerFieldName]: activeUser._id,
673
+ [ownerFieldName]: activeUser?._id,
674
674
  });
675
675
  }
676
676
  const result = await getModel().listAndCount(
@@ -683,8 +683,8 @@ module.exports = ({
683
683
  );
684
684
  LogAction({
685
685
  action,
686
- by: activeUser._id,
687
- role: activeUser.role,
686
+ by: activeUser?._id,
687
+ role: activeUser?.role,
688
688
  ip,
689
689
  root,
690
690
  shouldOwn,
@@ -734,7 +734,7 @@ module.exports = ({
734
734
  });
735
735
  if (shouldOwn) {
736
736
  notFilter.filter.modifyRules(filter, {
737
- [ownerFieldName]: activeUser._id,
737
+ [ownerFieldName]: activeUser?._id,
738
738
  });
739
739
  }
740
740
  const result = await getModel().listAndPopulate(
@@ -746,8 +746,8 @@ module.exports = ({
746
746
  );
747
747
  LogAction({
748
748
  action,
749
- by: activeUser._id,
750
- role: activeUser.role,
749
+ by: activeUser?._id,
750
+ role: activeUser?.role,
751
751
  ip,
752
752
  root,
753
753
  shouldOwn,
@@ -793,7 +793,7 @@ module.exports = ({
793
793
  const { filter, search } = query;
794
794
  if (shouldOwn) {
795
795
  notFilter.filter.modifyRules(filter, {
796
- [ownerFieldName]: activeUser._id,
796
+ [ownerFieldName]: activeUser?._id,
797
797
  });
798
798
  }
799
799
  if (search) {
@@ -802,8 +802,8 @@ module.exports = ({
802
802
  const result = await getModel().countWithFilter(search || filter);
803
803
  LogAction({
804
804
  action,
805
- by: activeUser._id,
806
- role: activeUser.role,
805
+ by: activeUser?._id,
806
+ role: activeUser?.role,
807
807
  ip,
808
808
  root,
809
809
  shouldOwn,
@@ -106,7 +106,7 @@ module.exports = class ModelFabricate {
106
106
  }
107
107
 
108
108
  static createIndexesForText(schema, targetModule) {
109
- if (targetModule.enrich.textIndex) {
109
+ if (targetModule.enrich && targetModule.enrich.textIndex) {
110
110
  schema.index(targetModule.enrich.textIndex, {
111
111
  name: Object.keys(targetModule.enrich.textIndex).join("__"),
112
112
  });