Skip to content

Commit b9a61bf

Browse files
authored
Merge pull request #3346 from AtlasOfLivingAustralia/feature/issue3345
Script to configure services for new forms #3345
2 parents 8c452d7 + 9518ca2 commit b9a61bf

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
load('../../../utils/audit.js');
2+
const forms = ['Grants and Others Progress Report', 'Procurement Output Report'];
3+
const nhtOutputReportForm = 'NHT Output Report';
4+
let services = db.service.find();
5+
while (services.hasNext()) {
6+
let service = services.next();
7+
let updated = false;
8+
let sectionName = null;
9+
for (let i=0; i<service.outputs.length; i++) {
10+
let output = service.outputs[i];
11+
12+
if (output.formName == nhtOutputReportForm) {
13+
sectionName = output.sectionName;
14+
}
15+
}
16+
17+
if (!sectionName) {
18+
print("No section found for service: "+service.name);
19+
continue;
20+
}
21+
for (let form in forms) {
22+
let found = false;
23+
for (let i=0; i<service.outputs.length; i++) {
24+
let output = service.outputs[i];
25+
if (output.formName == forms[form]) {
26+
found = true;
27+
}
28+
}
29+
if (!found) {
30+
service.outputs.push({formName:forms[form], sectionName:sectionName});
31+
updated = true;
32+
}
33+
}
34+
35+
if (updated) {
36+
print("Updating service forms for service: "+service.name);
37+
db.service.replaceOne({_id:service._id}, service);
38+
audit(service, service.serviceId, 'au.org.ala.ecodata.Service', 'system');
39+
}
40+
41+
42+
}

0 commit comments

Comments
 (0)