blixify-server 0.2.23 → 0.3.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.
|
@@ -16,9 +16,10 @@ export declare class MongoWrapper {
|
|
|
16
16
|
tableId: string;
|
|
17
17
|
logId: string;
|
|
18
18
|
logWorkflow: any;
|
|
19
|
+
logCollectIds: string[];
|
|
19
20
|
debug: any;
|
|
20
21
|
modelChecker: (obj: any) => boolean;
|
|
21
|
-
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, logId?: string, logWorkflow?: (data: any) => Promise<any>, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
|
|
22
|
+
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, logId?: string, logWorkflow?: (data: any) => Promise<any>, logCollectIds?: string[], debug?: (reqBody: any, curBody: any, errMsg: any) => void);
|
|
22
23
|
parseModel: (data: any) => any;
|
|
23
24
|
handleLogging: (mongoId: any, type: "create" | "update" | "delete", req: any, value?: {
|
|
24
25
|
new?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAiJD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;I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tC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqGtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA0I5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAwCtC;IAEF,mBAAmB,CAAC,GAAG,EAAE,GAAG;IA8N5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBAgQlC;IAEF,IAAI,YAgFF;CACH"}
|
|
@@ -168,7 +168,7 @@ const handleParseQueryFilter = (queryList, prefix) => {
|
|
|
168
168
|
*
|
|
169
169
|
*/
|
|
170
170
|
class MongoWrapper {
|
|
171
|
-
constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, logId, logWorkflow, debug) {
|
|
171
|
+
constructor(mongoDB, collection, isProd, config, modelChecker, lib, tableId, logId, logWorkflow, logCollectIds, debug) {
|
|
172
172
|
this.mongoDB = "";
|
|
173
173
|
this.collection = "";
|
|
174
174
|
this.isProd = false;
|
|
@@ -183,6 +183,7 @@ class MongoWrapper {
|
|
|
183
183
|
};
|
|
184
184
|
this.tableId = "";
|
|
185
185
|
this.logId = "";
|
|
186
|
+
this.logCollectIds = [];
|
|
186
187
|
// eslint-disable-next-line
|
|
187
188
|
this.modelChecker = (obj) => {
|
|
188
189
|
return false;
|
|
@@ -228,6 +229,14 @@ class MongoWrapper {
|
|
|
228
229
|
userRole,
|
|
229
230
|
organisationId,
|
|
230
231
|
};
|
|
232
|
+
if ((type === "create" || type === "update") &&
|
|
233
|
+
this.logCollectIds.length > 0) {
|
|
234
|
+
this.logCollectIds.forEach((collectId) => {
|
|
235
|
+
if (dataDoc[collectId] !== undefined) {
|
|
236
|
+
logItem[collectId] = dataDoc[collectId];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
231
240
|
const mongoLogCollection = this.mongoDB
|
|
232
241
|
.db(this.tableId)
|
|
233
242
|
.collection(this.logId);
|
|
@@ -1055,6 +1064,7 @@ class MongoWrapper {
|
|
|
1055
1064
|
* limit - number (Optional)
|
|
1056
1065
|
* sort - Array Sort or Sort interface (Optional)
|
|
1057
1066
|
* stopLimit - boolean to retreive all data (Optional)
|
|
1067
|
+
* uniqueLabel - string to ensure uniqueness of a field across returned documents (Optional)
|
|
1058
1068
|
*/
|
|
1059
1069
|
router.post("/list", (req, res) => {
|
|
1060
1070
|
this.initList(req, res);
|
|
@@ -1071,23 +1081,25 @@ class MongoWrapper {
|
|
|
1071
1081
|
this.tableId = tableId ? `${tableId}-${tableSuffix}` : tableSuffix;
|
|
1072
1082
|
this.logId = logId !== null && logId !== void 0 ? logId : "";
|
|
1073
1083
|
this.logWorkflow = logWorkflow;
|
|
1084
|
+
this.logCollectIds = logCollectIds !== null && logCollectIds !== void 0 ? logCollectIds : [];
|
|
1074
1085
|
this.debug = debug;
|
|
1075
1086
|
}
|
|
1076
1087
|
handleBuildPipeline(req) {
|
|
1077
1088
|
const pipelineList = [];
|
|
1078
1089
|
const addedForeignLookups = new Map();
|
|
1079
|
-
const { query, sort, cursor, limit, stopLimit, pipeline } = req.body;
|
|
1090
|
+
const { query, sort, cursor, limit, stopLimit, pipeline, uniqueLabel } = req.body;
|
|
1080
1091
|
try {
|
|
1081
1092
|
if (Array.isArray(pipeline) && pipeline.length > 0) {
|
|
1082
1093
|
pipeline.forEach((link) => {
|
|
1083
1094
|
const { condition, referenceSpaceLabel, spaceReferenceId, spaceReferenceAs, sort: referenceSort, } = link;
|
|
1084
1095
|
if (spaceReferenceId) {
|
|
1096
|
+
const defaultReferenceAs = spaceReferenceAs || "linkedData";
|
|
1085
1097
|
const lookupStage = {
|
|
1086
1098
|
$lookup: {
|
|
1087
1099
|
from: spaceReferenceId,
|
|
1088
1100
|
let: {},
|
|
1089
1101
|
pipeline: [],
|
|
1090
|
-
as:
|
|
1102
|
+
as: defaultReferenceAs,
|
|
1091
1103
|
},
|
|
1092
1104
|
};
|
|
1093
1105
|
if (condition && condition.length > 0) {
|
|
@@ -1147,20 +1159,20 @@ class MongoWrapper {
|
|
|
1147
1159
|
if (referenceSort && referenceSort.sortId) {
|
|
1148
1160
|
pipelineList.push({
|
|
1149
1161
|
$sort: {
|
|
1150
|
-
[`${
|
|
1162
|
+
[`${defaultReferenceAs}.${referenceSort.sortId}`]: referenceSort.type === "asc" ? 1 : -1,
|
|
1151
1163
|
},
|
|
1152
1164
|
});
|
|
1153
1165
|
}
|
|
1154
1166
|
pipelineList.push({
|
|
1155
1167
|
$unwind: {
|
|
1156
|
-
path: `$${
|
|
1168
|
+
path: `$${defaultReferenceAs}`,
|
|
1157
1169
|
preserveNullAndEmptyArrays: true,
|
|
1158
1170
|
},
|
|
1159
1171
|
});
|
|
1160
1172
|
if (referenceSpaceLabel && referenceSpaceLabel.length > 0) {
|
|
1161
1173
|
const addFieldsStage = { $addFields: {} };
|
|
1162
1174
|
referenceSpaceLabel.forEach((field) => {
|
|
1163
|
-
addFieldsStage.$addFields[field] = `$${
|
|
1175
|
+
addFieldsStage.$addFields[`${defaultReferenceAs}_${field}`] = `$${defaultReferenceAs}.${field}`;
|
|
1164
1176
|
});
|
|
1165
1177
|
pipelineList.push(addFieldsStage);
|
|
1166
1178
|
}
|
|
@@ -1171,7 +1183,9 @@ class MongoWrapper {
|
|
|
1171
1183
|
},
|
|
1172
1184
|
};
|
|
1173
1185
|
referenceSpaceLabel === null || referenceSpaceLabel === void 0 ? void 0 : referenceSpaceLabel.forEach((field) => {
|
|
1174
|
-
groupStage.$group[
|
|
1186
|
+
groupStage.$group[`${defaultReferenceAs}_${field}`] = {
|
|
1187
|
+
$push: `$${defaultReferenceAs}_${field}`,
|
|
1188
|
+
};
|
|
1175
1189
|
});
|
|
1176
1190
|
pipelineList.push(groupStage);
|
|
1177
1191
|
// Merge back and remove 'originalData' and 'spaceReferenceAs'
|
|
@@ -1227,6 +1241,17 @@ class MongoWrapper {
|
|
|
1227
1241
|
pipelineList.push(sortStage);
|
|
1228
1242
|
}
|
|
1229
1243
|
}
|
|
1244
|
+
if (uniqueLabel) {
|
|
1245
|
+
pipelineList.push({
|
|
1246
|
+
$group: {
|
|
1247
|
+
_id: `$${uniqueLabel}`,
|
|
1248
|
+
doc: { $first: "$$ROOT" },
|
|
1249
|
+
},
|
|
1250
|
+
});
|
|
1251
|
+
pipelineList.push({
|
|
1252
|
+
$replaceRoot: { newRoot: "$doc" },
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1230
1255
|
if (cursor) {
|
|
1231
1256
|
pipelineList.push({ $skip: Number.parseInt(cursor) });
|
|
1232
1257
|
}
|
package/dist/model/Log.d.ts
CHANGED
package/dist/model/Log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Log.d.ts","sourceRoot":"","sources":["../../src/model/Log.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GACT,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,SAAS,GACT,MAAM,GACN,QAAQ,GACR,SAAS,GACT,OAAO,GACP,MAAM,GACN,eAAe,GACf,cAAc,GACd,WAAW,GACX,QAAQ,GACR,SAAS,GACT,cAAc,GACd,MAAM,GACN,eAAe,GACf,YAAY,GACZ,UAAU,GACV,UAAU,CAAC;AAEf,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,QAAQ,CAAC;CACvB;AACD,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,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