Skip to content

Commit

Permalink
add: add back validation functions and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
YUUU23 committed Aug 14, 2024
1 parent 076038d commit 9b947b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
21 changes: 10 additions & 11 deletions cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -285,39 +285,38 @@ async function deploymentPrompt() {
return response;
}

/** Prompt the user to enter the ID of a study */
async function studyIDPrompt() {
const invalidMessage = "Please enter a valid study from your Firestore database";
return await input({
message: "Select a study:",
validate: async (input) => {
if (!input) return invalidMessage;
if (ACTION === "register") {
STUDY_ID = input;
return true;
}
switch (DEPLOYMENT) {
case "firebase":
return validateStudyFirebase(input);
const studyCollection = await validateStudyFirebase(input);
return !studyCollection ? invalidMessage : true;
default:
throw INVALID_DEPLOYMENT_ERROR;
}
},
});
}

/** Prompt the user to enter the ID of a participant on the STUDY_ID study */
async function participantIDPrompt() {
const invalidMessage = `Please enter a valid participant on the study "${STUDY_ID}"`;
return await input({
message: ACTION === "register" ? "Enter a new participant:" : "Select a participant:",
message: "Select a participant:",
validate: async (input) => {
const invalid = "Please enter a valid participant from your Firestore database";
if (!input) return invalid;
else if (input === "*") return true;
if (ACTION === "register") {
PARTICIPANT_ID = input;
return true;
}

switch (DEPLOYMENT) {
case "firebase":
return validateParticipantFirebase(input);
const participantCollection = await validateParticipantFirebase(input);
return !participantCollection ? invalidMessage : true;
default:
throw INVALID_DEPLOYMENT_ERROR;
}
Expand Down
39 changes: 23 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@jspsych/plugin-instructions": "^1.1.3",
"@jspsych/plugin-preload": "^1.1.2",
"@jspsych/plugin-survey": "^1.0.1",
"commander": "^12.1.0",
"electron-log": "^5.0.0",
"electron-squirrel-startup": "^1.0.0",
"firebase": "^10.11.0",
Expand Down

0 comments on commit 9b947b1

Please sign in to comment.