Skip to content

Commit

Permalink
Merge pull request #165 from borkarsaish65/script/kafkaissue
Browse files Browse the repository at this point in the history
modification to the script to validate the ids passed
  • Loading branch information
aks30 authored Jul 25, 2024
2 parents 53f165b + d7631c0 commit 3a8b44d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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

0 comments on commit 3a8b44d

Please sign in to comment.