Skip to content

Commit

Permalink
Merge pull request #3346 from AtlasOfLivingAustralia/feature/issue3345
Browse files Browse the repository at this point in the history
Script to configure services for new forms #3345
  • Loading branch information
temi authored Oct 10, 2024
2 parents 8c452d7 + 9518ca2 commit b9a61bf
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load('../../../utils/audit.js');
const forms = ['Grants and Others Progress Report', 'Procurement Output Report'];
const nhtOutputReportForm = 'NHT Output Report';
let services = db.service.find();
while (services.hasNext()) {
let service = services.next();
let updated = false;
let sectionName = null;
for (let i=0; i<service.outputs.length; i++) {
let output = service.outputs[i];

if (output.formName == nhtOutputReportForm) {
sectionName = output.sectionName;
}
}

if (!sectionName) {
print("No section found for service: "+service.name);
continue;
}
for (let form in forms) {
let found = false;
for (let i=0; i<service.outputs.length; i++) {
let output = service.outputs[i];
if (output.formName == forms[form]) {
found = true;
}
}
if (!found) {
service.outputs.push({formName:forms[form], sectionName:sectionName});
updated = true;
}
}

if (updated) {
print("Updating service forms for service: "+service.name);
db.service.replaceOne({_id:service._id}, service);
audit(service, service.serviceId, 'au.org.ala.ecodata.Service', 'system');
}


}

0 comments on commit b9a61bf

Please sign in to comment.