Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modification to the script to validate the ids passed #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/survey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Run the script to push completed surveySubmission records to kafka.

Multiple IDs support:

You can also provide multiple IDs by separating them with commas.
Example: node pushcompletedsubmissions.js id1,id2,id3
You can also provide multiple IDs by separating them with commas and wrapped in single quotes.
Example: node pushcompletedsubmissions.js 'id1,id2,id3'

#### Validation

Expand Down
23 changes: 21 additions & 2 deletions scripts/survey/pushcompletedsubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* created-date : 18-JULY-2024
* Description : Migration script to push completed survey submissions to kafka
*/

const mongoose = require('mongoose');
const path = require("path");
let rootPath = path.join(__dirname, '../../')
require('dotenv').config({ path: rootPath+'/.env' })
Expand All @@ -21,9 +21,28 @@ const args = process.argv.slice(2);
const surveySubmissionsHelper = require(MODULES_BASE_PATH + "/surveySubmissions/helper");
const fs = require('fs');
const utils = require('../../generics/helpers/utils')

let IDString = args[0];

let IDArray = IDString.split(',');
console.log('IDString:',IDString)

if(!IDString || IDString.length <= 0){
throw new Error('No Ids is passed in the terminal.');
}

let IDArray = IDString.split(',').map(id => id.trim()).filter(id => id.length > 0);;

console.log('processing...',IDArray);

if(IDArray.length <= 0){
throw new Error('No Id/Ids found');
}

IDArray.forEach((id)=>{
if(!mongoose.Types.ObjectId.isValid(id)){
throw new Error(id+' is not a valid mongoID');
}
})

let successArray = [];
(async () => {
Expand Down