diff --git a/scripts/survey/README.md b/scripts/survey/README.md index 75ec2f8e..fa277cfa 100644 --- a/scripts/survey/README.md +++ b/scripts/survey/README.md @@ -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 diff --git a/scripts/survey/pushcompletedsubmissions.js b/scripts/survey/pushcompletedsubmissions.js index c34ff7f9..0b34fa9b 100644 --- a/scripts/survey/pushcompletedsubmissions.js +++ b/scripts/survey/pushcompletedsubmissions.js @@ -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' }) @@ -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 () => {