-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a migration to fix the data collection details of finalised forms
- Loading branch information
l-gorman
committed
Jul 12, 2022
1 parent
dd0bc9c
commit 89fdb3d
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
|
||
// For the correct environment run with prefix | ||
// NODE_ENV=<dev|prod|test> | ||
// e.g. | ||
// NODE_ENV=dev node migrations/update-finalised-form-details-12-07-2022.js | ||
const GetConfigDetailsAndConnect = require('./setup.js') | ||
const mongoose = require('mongoose') | ||
|
||
const Form = require('../models/Form') | ||
|
||
// RunScript('./migrations/setup.js', function (err) { | ||
// if (err) throw err; | ||
// console.log('Finished Running Setup'); | ||
// }); | ||
|
||
const db = GetConfigDetailsAndConnect() | ||
|
||
|
||
async function run(db) { | ||
|
||
|
||
|
||
// If form is currently marked as draft true | ||
// Need to set 'live' to false | ||
|
||
const finalisedForms = await Form.find({live:true}) | ||
|
||
|
||
finalisedForms.forEach(async (form)=>{ | ||
|
||
|
||
const UpdatedFinalForms = await Form.updateOne( | ||
{name: form.name, project: form.project}, | ||
{ $set: { "collectionDetails.general.server_url": form.collectionDetails.general.server_url + "/forms/" + form.name }, | ||
draftVersion:null} | ||
) | ||
|
||
}) | ||
|
||
|
||
const forms = await Form.find() | ||
console.log(forms) | ||
|
||
|
||
db.close() | ||
|
||
|
||
|
||
return | ||
} | ||
|
||
run(db) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|