@researchdatabox/sails-hook-redbox-storage-mongo 1.5.0 → 1.5.2
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.
|
@@ -12,7 +12,7 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
|
|
|
12
12
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
13
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
14
|
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
-
return i =
|
|
15
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
16
|
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
17
|
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
18
|
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
@@ -23,7 +23,8 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.Services = void 0;
|
|
26
|
-
const
|
|
26
|
+
const rxjs_1 = require("rxjs");
|
|
27
|
+
const rxjs_2 = require("rxjs");
|
|
27
28
|
const uuid_1 = require("uuid");
|
|
28
29
|
const luxon_1 = require("luxon");
|
|
29
30
|
const mongodb = require("mongodb");
|
|
@@ -371,7 +372,7 @@ var Services;
|
|
|
371
372
|
});
|
|
372
373
|
}
|
|
373
374
|
getDeletedRecords(workflowState_1) {
|
|
374
|
-
return __awaiter(this, arguments, void 0, function* (workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode = 'regex') {
|
|
375
|
+
return __awaiter(this, arguments, void 0, function* (workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode = 'regex', secondarySort = undefined) {
|
|
375
376
|
let query = {
|
|
376
377
|
"deletedRecordMetadata.metaMetadata.brandId": brand.id
|
|
377
378
|
};
|
|
@@ -395,6 +396,9 @@ var Services;
|
|
|
395
396
|
options['sort'][`${sort.substring(0, sort.indexOf(':'))}`] = _.toNumber(sort.substring(sort.indexOf(':') + 1));
|
|
396
397
|
}
|
|
397
398
|
}
|
|
399
|
+
if (!_.isEmpty(secondarySort)) {
|
|
400
|
+
options['sort'][`${secondarySort.substring(0, secondarySort.indexOf(':'))}`] = _.toNumber(secondarySort.substring(secondarySort.indexOf(':') + 1));
|
|
401
|
+
}
|
|
398
402
|
let roleNames = this.getRoleNames(roles, brand);
|
|
399
403
|
let andArray = [];
|
|
400
404
|
let permissions = {
|
|
@@ -666,10 +670,11 @@ var Services;
|
|
|
666
670
|
}
|
|
667
671
|
updateDatastream(oid, record, newMetadata, fileRoot, fileIdsAdded) {
|
|
668
672
|
return FormsService.getFormByName(record.metaMetadata.form, true)
|
|
669
|
-
.
|
|
673
|
+
.pipe((0, rxjs_2.mergeMap)(form => {
|
|
674
|
+
const typedForm = form;
|
|
670
675
|
const reqs = [];
|
|
671
|
-
record.metaMetadata.attachmentFields =
|
|
672
|
-
_.each(
|
|
676
|
+
record.metaMetadata.attachmentFields = typedForm.attachmentFields;
|
|
677
|
+
_.each(typedForm.attachmentFields, (attField) => __awaiter(this, void 0, void 0, function* () {
|
|
673
678
|
const oldAttachments = record.metadata[attField];
|
|
674
679
|
const newAttachments = newMetadata[attField];
|
|
675
680
|
const removeIds = [];
|
|
@@ -692,10 +697,10 @@ var Services;
|
|
|
692
697
|
reqs.push(this.addAndRemoveDatastreams(oid, fileIdsAdded, removeIds));
|
|
693
698
|
}));
|
|
694
699
|
if (_.isEmpty(reqs)) {
|
|
695
|
-
reqs.push(
|
|
700
|
+
reqs.push((0, rxjs_1.of)({ "request": "dummy" }));
|
|
696
701
|
}
|
|
697
|
-
return
|
|
698
|
-
});
|
|
702
|
+
return (0, rxjs_1.of)(reqs);
|
|
703
|
+
}));
|
|
699
704
|
}
|
|
700
705
|
removeDatastream(oid, datastream) {
|
|
701
706
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@researchdatabox/sails-hook-redbox-storage-mongo",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "A MongoDB storage plugin for ReDBox.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"sails": {
|
|
@@ -33,31 +33,30 @@
|
|
|
33
33
|
"author": "QCIF Engineering dev@redboxresearchdata.com.au",
|
|
34
34
|
"license": "GPL-3.0",
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@researchdatabox/redbox-core-types": "1.
|
|
36
|
+
"@researchdatabox/redbox-core-types": "^1.5.0",
|
|
37
37
|
"@types/chai": "5.2.2",
|
|
38
38
|
"@types/lodash": "4.17.17",
|
|
39
39
|
"@types/mocha": "10.0.10",
|
|
40
40
|
"@types/node": "20.17.51",
|
|
41
41
|
"chai": "5.2.0",
|
|
42
42
|
"fs": "0.0.1-security",
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
"luxon": "^3.7.1",
|
|
44
|
+
"mocha": "11.7.1",
|
|
45
|
+
"mocha-junit-reporter": "2.2.1",
|
|
46
46
|
"mongodb": "6.16.0",
|
|
47
|
-
"rxjs": "6.6.7",
|
|
48
|
-
"rxjs-compat": "6.6.7",
|
|
49
47
|
"sails": "1.5.14",
|
|
50
48
|
"stream": "0.0.3",
|
|
51
|
-
"typescript": "5.
|
|
49
|
+
"typescript": "5.9.2",
|
|
52
50
|
"util": "0.12.5"
|
|
53
51
|
},
|
|
54
52
|
"dependencies": {
|
|
55
53
|
"json2csv": "^5.0.3",
|
|
56
54
|
"lodash": "^4.17.21",
|
|
57
|
-
"uuid": "
|
|
55
|
+
"uuid": "11.1.0"
|
|
58
56
|
},
|
|
59
57
|
"peerDependencies": {
|
|
60
|
-
"luxon": ">=3.0.0"
|
|
58
|
+
"luxon": ">=3.0.0",
|
|
59
|
+
"rxjs": ">=7.0.0"
|
|
61
60
|
},
|
|
62
61
|
"publishConfig": {
|
|
63
62
|
"access": "public"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from 'rxjs/Rx';
|
|
1
|
+
import { Observable, of } from 'rxjs';
|
|
2
|
+
import { mergeMap } from 'rxjs';
|
|
4
3
|
|
|
5
4
|
import { Sails, Model } from "sails";
|
|
6
5
|
import { v1 as uuidv1 } from 'uuid';
|
|
@@ -409,7 +408,7 @@ export module Services {
|
|
|
409
408
|
return record;
|
|
410
409
|
}
|
|
411
410
|
|
|
412
|
-
public async getDeletedRecords(workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode:string = 'regex') {
|
|
411
|
+
public async getDeletedRecords(workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode:string = 'regex', secondarySort = undefined) {
|
|
413
412
|
|
|
414
413
|
|
|
415
414
|
// BrandId ...
|
|
@@ -438,6 +437,11 @@ export module Services {
|
|
|
438
437
|
options['sort'][`${sort.substring(0, sort.indexOf(':'))}`] = _.toNumber(sort.substring(sort.indexOf(':') + 1));
|
|
439
438
|
}
|
|
440
439
|
}
|
|
440
|
+
|
|
441
|
+
if(!_.isEmpty(secondarySort)) {
|
|
442
|
+
options['sort'][`${secondarySort.substring(0, secondarySort.indexOf(':'))}`] = _.toNumber(secondarySort.substring(secondarySort.indexOf(':') + 1));
|
|
443
|
+
}
|
|
444
|
+
|
|
441
445
|
// Authorization ...
|
|
442
446
|
let roleNames = this.getRoleNames(roles, brand);
|
|
443
447
|
let andArray = [];
|
|
@@ -736,38 +740,41 @@ export module Services {
|
|
|
736
740
|
public updateDatastream(oid: string, record, newMetadata, fileRoot, fileIdsAdded): any {
|
|
737
741
|
// loop thru the attachment fields and determine if we need to add or remove
|
|
738
742
|
return FormsService.getFormByName(record.metaMetadata.form, true)
|
|
739
|
-
.
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
_.
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
_.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
743
|
+
.pipe(
|
|
744
|
+
mergeMap(form => {
|
|
745
|
+
const typedForm = form as { attachmentFields: string[] };
|
|
746
|
+
const reqs = [];
|
|
747
|
+
record.metaMetadata.attachmentFields = typedForm.attachmentFields;
|
|
748
|
+
_.each(typedForm.attachmentFields, async (attField) => {
|
|
749
|
+
const oldAttachments = record.metadata[attField];
|
|
750
|
+
const newAttachments = newMetadata[attField];
|
|
751
|
+
const removeIds = [];
|
|
752
|
+
// process removals
|
|
753
|
+
if (!_.isUndefined(oldAttachments) && !_.isNull(oldAttachments) && !_.isNull(newAttachments)) {
|
|
754
|
+
const toRemove = _.differenceBy(oldAttachments, newAttachments, 'fileId');
|
|
755
|
+
_.each(toRemove, (removeAtt) => {
|
|
756
|
+
if (removeAtt.type == 'attachment') {
|
|
757
|
+
removeIds.push(new Datastream(removeAtt));
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
// process additions
|
|
762
|
+
if (!_.isUndefined(newAttachments) && !_.isNull(newAttachments)) {
|
|
763
|
+
const toAdd = _.differenceBy(newAttachments, oldAttachments, 'fileId');
|
|
764
|
+
_.each(toAdd, (addAtt) => {
|
|
765
|
+
if (addAtt.type == 'attachment') {
|
|
766
|
+
fileIdsAdded.push(new Datastream(addAtt));
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
reqs.push(this.addAndRemoveDatastreams(oid, fileIdsAdded, removeIds));
|
|
771
|
+
});
|
|
772
|
+
if (_.isEmpty(reqs)) {
|
|
773
|
+
reqs.push(of({ "request": "dummy" }));
|
|
763
774
|
}
|
|
764
|
-
reqs
|
|
765
|
-
})
|
|
766
|
-
|
|
767
|
-
reqs.push(Observable.of({ "request": "dummy" }));
|
|
768
|
-
}
|
|
769
|
-
return Observable.of(reqs);
|
|
770
|
-
});
|
|
775
|
+
return of(reqs);
|
|
776
|
+
})
|
|
777
|
+
);
|
|
771
778
|
}
|
|
772
779
|
|
|
773
780
|
public async removeDatastream(oid, datastream: Datastream) {
|