@optimiser/common 1.0.363 → 1.0.364

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.
@@ -24,7 +24,7 @@ declare function SyncParentObjectData(pageData: AnyObjectInterface, objectID: Ob
24
24
  * Delete field in other collection after delete records
25
25
  * @param mongodbTransactionQueryopts to maintain session for transactions
26
26
  */
27
- declare function DeleteFieldInOtherCollection(objectName: string, objectIDs: ObjectId, db: Db, params?: AnyObjectInterface): Promise<void>;
27
+ declare function DeleteFieldInOtherCollection(objectName: string, objectIDs: ObjectId, db: Db, params?: AnyObjectInterface, comMasterDb?: Db): Promise<void>;
28
28
  declare function ReactivateFieldInOtherCollection(objectName: string, objectIDs: ObjectId, db: Db): void;
29
29
  declare function SyncFieldInSameCollection(objectName: string, objectIDs: ObjectId[], db: Db, comMasterDb: Db): Promise<any>;
30
30
  declare function SyncFieldInSameCollectionByObjectID(objectName: string, objectID: ObjectId, db: Db): void;
@@ -765,7 +765,7 @@ exports.SyncParentObjectData = SyncParentObjectData;
765
765
  * @param mongodbTransactionQueryopts to maintain session for transactions
766
766
  */
767
767
  //
768
- function DeleteFieldInOtherCollection(objectName, objectIDs, db, params) {
768
+ function DeleteFieldInOtherCollection(objectName, objectIDs, db, params, comMasterDb) {
769
769
  return __awaiter(this, void 0, void 0, function () {
770
770
  var mongoQueryOpts, querys_1;
771
771
  var _this = this;
@@ -776,102 +776,117 @@ function DeleteFieldInOtherCollection(objectName, objectIDs, db, params) {
776
776
  mongoQueryOpts = __assign({}, params.mongodbQueryOpts);
777
777
  }
778
778
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
779
- var querys, data, i, obj, query, alias, j, alias, i, query, error_1;
779
+ var querys, data, i, obj, query, alias, j, alias, project, UseMasterDatabase, i, query, dbConnection, error_1;
780
780
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
781
781
  return __generator(this, function (_k) {
782
782
  switch (_k.label) {
783
783
  case 0:
784
- _k.trys.push([0, 8, , 9]);
784
+ _k.trys.push([0, 12, , 13]);
785
785
  querys = [];
786
786
  return [4 /*yield*/, db.collection('ObjectSchema').aggregate([{ $unwind: "$Fields" },
787
787
  { $match: { $or: [{ "Fields.LookupObject": objectName }, { "Fields.ExtraLookupObjects": { $elemMatch: { "from": objectName } } }] } },
788
788
  ], mongoQueryOpts).toArray()];
789
789
  case 1:
790
790
  data = _k.sent();
791
- if (!(data && data.length > 0)) return [3 /*break*/, 7];
792
- for (i = 0; i < data.length; i++) {
793
- obj = data[i];
794
- query = { ObjectName: obj.Name };
795
- if (obj.Fields.LookupObject == objectName) {
796
- alias = obj.Fields.Name + constants_1.default.LookupAlias;
797
- query.match = (_a = {},
798
- _a[alias + '._id'] = { $in: objectIDs },
799
- _a);
800
- if (obj.Fields.UIDataType == 'multilookup' || obj.Fields.UIDataType == 'multiselect') {
801
- query.set = (_b = {},
802
- _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false,
803
- _b);
804
- query.arrayFilters = (_c = {},
805
- _c['e._id'] = { $in: objectIDs },
806
- _c);
791
+ if (!(data && data.length > 0)) return [3 /*break*/, 11];
792
+ i = 0;
793
+ _k.label = 2;
794
+ case 2:
795
+ if (!(i < data.length)) return [3 /*break*/, 5];
796
+ obj = data[i];
797
+ query = { ObjectName: obj.Name };
798
+ if (obj.Fields.LookupObject == objectName) {
799
+ alias = obj.Fields.Name + constants_1.default.LookupAlias;
800
+ query.match = (_a = {},
801
+ _a[alias + '._id'] = { $in: objectIDs },
802
+ _a);
803
+ if (obj.Fields.UIDataType == 'multilookup' || obj.Fields.UIDataType == 'multiselect') {
804
+ query.set = (_b = {},
805
+ _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false,
806
+ _b);
807
+ query.arrayFilters = (_c = {},
808
+ _c['e._id'] = { $in: objectIDs },
809
+ _c);
810
+ }
811
+ else {
812
+ /*On deletion of Pipeline or Event, Removing Pipeline/Event Id and LookupData from Activity*/
813
+ if (((objectName == "Pipeline" && obj.Fields.Name == "PipelineID") || (objectName == "Events" && obj.Fields.Name == "EventID")) && obj.Name == "Activity") {
814
+ query.set = (_d = {},
815
+ _d[obj.Fields.Name] = null,
816
+ _d[alias] = null,
817
+ _d);
807
818
  }
808
819
  else {
809
- /*On deletion of Pipeline or Event, Removing Pipeline/Event Id and LookupData from Activity*/
810
- if (((objectName == "Pipeline" && obj.Fields.Name == "PipelineID") || (objectName == "Events" && obj.Fields.Name == "EventID")) && obj.Name == "Activity") {
811
- query.set = (_d = {},
812
- _d[obj.Fields.Name] = null,
813
- _d[alias] = null,
814
- _d);
815
- }
816
- else {
817
- query.set = (_e = {},
818
- _e[alias + '.IsActive'] = false,
819
- _e);
820
- }
820
+ query.set = (_e = {},
821
+ _e[alias + '.IsActive'] = false,
822
+ _e);
821
823
  }
822
824
  }
823
- else if (obj.Fields.ExtraLookupObjects) {
824
- for (j = 0; j < obj.Fields.ExtraLookupObjects.length; j++) {
825
- if (obj.Fields.ExtraLookupObjects[j].from == objectName) {
826
- alias = obj.Fields.Name + constants_1.default.LookupAlias + '.' + obj.Fields.ExtraLookupObjects[j].as;
827
- query.match = (_f = {},
828
- _f[alias + '._id'] = { $in: objectIDs },
829
- _f);
830
- if (obj.Fields.UIDataType == 'multilookup') {
831
- query.set = (_g = {},
832
- _g[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].' + obj.Fields.ExtraLookupObjects[j].as + '.IsActive'] = false,
833
- _g);
834
- query.arrayFilters = (_h = {},
835
- _h['e.' + obj.Fields.ExtraLookupObjects[j].as + '._id'] = { $in: objectIDs },
836
- _h);
837
- }
838
- else
839
- query.set = (_j = {},
840
- _j[alias + '.IsActive'] = false,
841
- _j);
825
+ }
826
+ else if (obj.Fields.ExtraLookupObjects) {
827
+ for (j = 0; j < obj.Fields.ExtraLookupObjects.length; j++) {
828
+ if (obj.Fields.ExtraLookupObjects[j].from == objectName) {
829
+ alias = obj.Fields.Name + constants_1.default.LookupAlias + '.' + obj.Fields.ExtraLookupObjects[j].as;
830
+ query.match = (_f = {},
831
+ _f[alias + '._id'] = { $in: objectIDs },
832
+ _f);
833
+ if (obj.Fields.UIDataType == 'multilookup') {
834
+ query.set = (_g = {},
835
+ _g[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].' + obj.Fields.ExtraLookupObjects[j].as + '.IsActive'] = false,
836
+ _g);
837
+ query.arrayFilters = (_h = {},
838
+ _h['e.' + obj.Fields.ExtraLookupObjects[j].as + '._id'] = { $in: objectIDs },
839
+ _h);
842
840
  }
841
+ else
842
+ query.set = (_j = {},
843
+ _j[alias + '.IsActive'] = false,
844
+ _j);
843
845
  }
844
846
  }
845
- if (query.set && query.match) {
846
- querys.push(query);
847
- }
848
847
  }
849
- if (!(querys.length > 0)) return [3 /*break*/, 7];
850
- i = 0;
851
- _k.label = 2;
852
- case 2:
853
- if (!(i < querys.length)) return [3 /*break*/, 7];
854
- query = querys[i];
855
- if (!(query.arrayFilters !== undefined)) return [3 /*break*/, 4];
856
- return [4 /*yield*/, db.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, __assign({ arrayFilters: [query.arrayFilters] }, mongoQueryOpts))];
848
+ project = { '_id': 0, 'UseMasterDatabase': 1 };
849
+ return [4 /*yield*/, db.collection('Page').findOne({ 'ObjectName': obj.Name, 'UseMasterDatabase': true }, project)];
857
850
  case 3:
858
- _k.sent();
859
- return [3 /*break*/, 6];
860
- case 4: return [4 /*yield*/, db.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, mongoQueryOpts)];
851
+ UseMasterDatabase = _k.sent();
852
+ if (UseMasterDatabase) {
853
+ query['UseMasterDatabase'] = true;
854
+ }
855
+ if (query.set && query.match) {
856
+ querys.push(query);
857
+ }
858
+ _k.label = 4;
859
+ case 4:
860
+ i++;
861
+ return [3 /*break*/, 2];
861
862
  case 5:
862
- _k.sent();
863
+ if (!(querys.length > 0)) return [3 /*break*/, 11];
864
+ i = 0;
863
865
  _k.label = 6;
864
866
  case 6:
865
- i++;
866
- return [3 /*break*/, 2];
867
+ if (!(i < querys.length)) return [3 /*break*/, 11];
868
+ query = querys[i];
869
+ dbConnection = (query.UseMasterDatabase) ? comMasterDb : db;
870
+ if (!(query.arrayFilters !== undefined)) return [3 /*break*/, 8];
871
+ return [4 /*yield*/, dbConnection.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, __assign({ arrayFilters: [query.arrayFilters] }, mongoQueryOpts))];
867
872
  case 7:
873
+ _k.sent();
874
+ return [3 /*break*/, 10];
875
+ case 8: return [4 /*yield*/, dbConnection.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, mongoQueryOpts)];
876
+ case 9:
877
+ _k.sent();
878
+ _k.label = 10;
879
+ case 10:
880
+ i++;
881
+ return [3 /*break*/, 6];
882
+ case 11:
868
883
  resolve();
869
- return [3 /*break*/, 9];
870
- case 8:
884
+ return [3 /*break*/, 13];
885
+ case 12:
871
886
  error_1 = _k.sent();
872
887
  reject(error_1);
873
- return [3 /*break*/, 9];
874
- case 9: return [2 /*return*/];
888
+ return [3 /*break*/, 13];
889
+ case 13: return [2 /*return*/];
875
890
  }
876
891
  });
877
892
  }); })];
@@ -884,75 +899,99 @@ function DeleteFieldInOtherCollection(objectName, objectIDs, db, params) {
884
899
  db.collection('ObjectSchema').aggregate([{ $unwind: "$Fields" },
885
900
  { $match: { $or: [{ "Fields.LookupObject": objectName }, { "Fields.ExtraLookupObjects": { $elemMatch: { "from": objectName } } }] } },
886
901
  ], mongoQueryOpts).toArray(function (err, data) {
887
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
888
- if (data && data.length > 0) {
889
- for (var i = 0; i < data.length; i++) {
890
- var obj = data[i];
891
- var query = { ObjectName: obj.Name };
892
- if (obj.Fields.LookupObject == objectName) {
893
- var alias = obj.Fields.Name + constants_1.default.LookupAlias;
894
- query.match = (_a = {},
895
- _a[alias + '._id'] = { $in: objectIDs },
896
- _a);
897
- if (obj.Fields.UIDataType == 'multilookup' || obj.Fields.UIDataType == 'multiselect') {
898
- query.set = (_b = {},
899
- _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false,
900
- _b);
901
- query.arrayFilters = (_c = {},
902
- _c['e._id'] = { $in: objectIDs },
903
- _c);
904
- }
905
- else {
906
- /*On deletion of Pipeline or Event, Removing Pipeline/Event Id and LookupData from Activity*/
907
- if (((objectName == "Pipeline" && obj.Fields.Name == "PipelineID") || (objectName == "Events" && obj.Fields.Name == "EventID")) && obj.Name == "Activity") {
908
- query.set = (_d = {},
909
- _d[obj.Fields.Name] = null,
910
- _d[alias] = null,
911
- _d);
902
+ return __awaiter(this, void 0, void 0, function () {
903
+ var i, obj, query, alias, j, alias, project, UseMasterDatabase, i, query, dbConnection;
904
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
905
+ return __generator(this, function (_k) {
906
+ switch (_k.label) {
907
+ case 0:
908
+ if (!(data && data.length > 0)) return [3 /*break*/, 5];
909
+ i = 0;
910
+ _k.label = 1;
911
+ case 1:
912
+ if (!(i < data.length)) return [3 /*break*/, 4];
913
+ obj = data[i];
914
+ query = { ObjectName: obj.Name };
915
+ if (obj.Fields.LookupObject == objectName) {
916
+ alias = obj.Fields.Name + constants_1.default.LookupAlias;
917
+ query.match = (_a = {},
918
+ _a[alias + '._id'] = { $in: objectIDs },
919
+ _a);
920
+ if (obj.Fields.UIDataType == 'multilookup' || obj.Fields.UIDataType == 'multiselect') {
921
+ query.set = (_b = {},
922
+ _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false,
923
+ _b);
924
+ query.arrayFilters = (_c = {},
925
+ _c['e._id'] = { $in: objectIDs },
926
+ _c);
927
+ }
928
+ else {
929
+ /*On deletion of Pipeline or Event, Removing Pipeline/Event Id and LookupData from Activity*/
930
+ if (((objectName == "Pipeline" && obj.Fields.Name == "PipelineID") || (objectName == "Events" && obj.Fields.Name == "EventID")) && obj.Name == "Activity") {
931
+ query.set = (_d = {},
932
+ _d[obj.Fields.Name] = null,
933
+ _d[alias] = null,
934
+ _d);
935
+ }
936
+ else {
937
+ query.set = (_e = {},
938
+ _e[alias + '.IsActive'] = false,
939
+ _e);
940
+ }
941
+ }
912
942
  }
913
- else {
914
- query.set = (_e = {},
915
- _e[alias + '.IsActive'] = false,
916
- _e);
943
+ else if (obj.Fields.ExtraLookupObjects) {
944
+ for (j = 0; j < obj.Fields.ExtraLookupObjects.length; j++) {
945
+ if (obj.Fields.ExtraLookupObjects[j].from == objectName) {
946
+ alias = obj.Fields.Name + constants_1.default.LookupAlias + '.' + obj.Fields.ExtraLookupObjects[j].as;
947
+ query.match = (_f = {},
948
+ _f[alias + '._id'] = { $in: objectIDs },
949
+ _f);
950
+ if (obj.Fields.UIDataType == 'multilookup') {
951
+ query.set = (_g = {},
952
+ _g[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].' + obj.Fields.ExtraLookupObjects[j].as + '.IsActive'] = false,
953
+ _g);
954
+ query.arrayFilters = (_h = {},
955
+ _h['e.' + obj.Fields.ExtraLookupObjects[j].as + '._id'] = { $in: objectIDs },
956
+ _h);
957
+ }
958
+ else
959
+ query.set = (_j = {},
960
+ _j[alias + '.IsActive'] = false,
961
+ _j);
962
+ }
963
+ }
917
964
  }
918
- }
919
- }
920
- else if (obj.Fields.ExtraLookupObjects) {
921
- for (var j = 0; j < obj.Fields.ExtraLookupObjects.length; j++) {
922
- if (obj.Fields.ExtraLookupObjects[j].from == objectName) {
923
- var alias = obj.Fields.Name + constants_1.default.LookupAlias + '.' + obj.Fields.ExtraLookupObjects[j].as;
924
- query.match = (_f = {},
925
- _f[alias + '._id'] = { $in: objectIDs },
926
- _f);
927
- if (obj.Fields.UIDataType == 'multilookup') {
928
- query.set = (_g = {},
929
- _g[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].' + obj.Fields.ExtraLookupObjects[j].as + '.IsActive'] = false,
930
- _g);
931
- query.arrayFilters = (_h = {},
932
- _h['e.' + obj.Fields.ExtraLookupObjects[j].as + '._id'] = { $in: objectIDs },
933
- _h);
965
+ project = { '_id': 0, 'UseMasterDatabase': 1 };
966
+ return [4 /*yield*/, db.collection('Page').findOne({ 'ObjectName': obj.Name, 'UseMasterDatabase': true }, project)];
967
+ case 2:
968
+ UseMasterDatabase = _k.sent();
969
+ if (UseMasterDatabase) {
970
+ query['UseMasterDatabase'] = true;
971
+ }
972
+ if (query.set && query.match) {
973
+ querys_1.push(query);
974
+ }
975
+ _k.label = 3;
976
+ case 3:
977
+ i++;
978
+ return [3 /*break*/, 1];
979
+ case 4:
980
+ if (querys_1.length > 0) {
981
+ for (i = 0; i < querys_1.length; i++) {
982
+ query = querys_1[i];
983
+ dbConnection = (query.UseMasterDatabase) ? comMasterDb : db;
984
+ if (query.arrayFilters !== undefined)
985
+ dbConnection.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, __assign({ arrayFilters: [query.arrayFilters] }, mongoQueryOpts));
986
+ else
987
+ dbConnection.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, mongoQueryOpts);
934
988
  }
935
- else
936
- query.set = (_j = {},
937
- _j[alias + '.IsActive'] = false,
938
- _j);
939
989
  }
940
- }
941
- }
942
- if (query.set && query.match) {
943
- querys_1.push(query);
944
- }
945
- }
946
- if (querys_1.length > 0) {
947
- for (var i = 0; i < querys_1.length; i++) {
948
- var query = querys_1[i];
949
- if (query.arrayFilters !== undefined)
950
- db.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, __assign({ arrayFilters: [query.arrayFilters] }, mongoQueryOpts));
951
- else
952
- db.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, mongoQueryOpts);
990
+ _k.label = 5;
991
+ case 5: return [2 /*return*/];
953
992
  }
954
- }
955
- }
993
+ });
994
+ });
956
995
  });
957
996
  }
958
997
  return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.363",
3
+ "version": "1.0.364",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {