From da6a8cb50e9c0f66c06e52de13b3aeb0b15f9d16 Mon Sep 17 00:00:00 2001 From: kennsippell Date: Thu, 12 Dec 2024 02:11:56 -0800 Subject: [PATCH] Review feedback --- src/fn/upload-docs.js | 11 ++--------- src/lib/user-prompt.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fn/upload-docs.js b/src/fn/upload-docs.js index dc086827e..968dcfead 100644 --- a/src/fn/upload-docs.js +++ b/src/fn/upload-docs.js @@ -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); @@ -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 => { @@ -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); } diff --git a/src/lib/user-prompt.js b/src/lib/user-prompt.js index 71bd2c210..d1389457a 100644 --- a/src/lib/user-prompt.js +++ b/src/lib/user-prompt.js @@ -1,5 +1,6 @@ const environment = require('./environment'); const readline = require('readline-sync'); +const { warn } = require('./log'); /** @@ -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, };