Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Dec 12, 2024
1 parent bd9bf60 commit da6a8cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 2 additions & 9 deletions src/fn/upload-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function execute() {
throw new Error(`upload-docs: ${errors.join('\n')}`);
}

warnAndPrompt(`This operation will permanently write ${totalCount} docs. Are you sure you want to continue?`);
userPrompt.warnPromptAbort(`This operation will permanently write ${totalCount} docs. Are you sure you want to continue?`);

const deletedDocIds = analysis.map(result => result.delete).filter(Boolean);
await handleUsersAtDeletedFacilities(deletedDocIds);
Expand Down Expand Up @@ -100,13 +100,6 @@ async function execute() {
return processNextBatch(filenamesToUpload, INITIAL_BATCH_SIZE);
}

function warnAndPrompt(warningMessage) {
warn(warningMessage);
if (!userPrompt.keyInYN()) {
throw new Error('User aborted execution.');
}
}

function analyseFiles(filePaths) {
return filePaths
.map(filePath => {
Expand Down Expand Up @@ -134,7 +127,7 @@ async function handleUsersAtDeletedFacilities(deletedDocIds) {
return;
}

warnAndPrompt(`This operation will update permissions for ${affectedUsers.length} user accounts: ${usernames}. Are you sure you want to continue?`);
userPrompt.warnPromptAbort(`This operation will update ${affectedUsers.length} user accounts: ${usernames} and cannot be undone. Are you sure you want to continue?`);
await updateAffectedUsers(affectedUsers);
}

Expand Down
11 changes: 10 additions & 1 deletion src/lib/user-prompt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const environment = require('./environment');
const readline = require('readline-sync');
const { warn } = require('./log');


/**
Expand Down Expand Up @@ -33,8 +34,16 @@ function keyInSelect(items, question, options = {}) {
return readline.keyInSelect(items, question, options);
}

function warnPromptAbort(warningMessage) {
warn(warningMessage);
if (!keyInYN()) {
throw new Error('User aborted execution.');
}
}

module.exports = {
keyInYN,
question,
keyInSelect
keyInSelect,
warnPromptAbort,
};

0 comments on commit da6a8cb

Please sign in to comment.