From 17f29cf7c8fc47ae4a890d8f61f7c7f368a83e0b Mon Sep 17 00:00:00 2001 From: Gabriel Dong Date: Sat, 9 Sep 2023 15:03:49 -0500 Subject: [PATCH] initial cli commit --- scripts/cli-util/get-hacker.ts | 57 +++++++++++++++ scripts/cli-util/modify-hacker.ts | 102 +++++++++++++++++++++++++++ scripts/dev-cli.ts | 113 +++++++++++++++--------------- 3 files changed, 216 insertions(+), 56 deletions(-) create mode 100644 scripts/cli-util/get-hacker.ts create mode 100644 scripts/cli-util/modify-hacker.ts diff --git a/scripts/cli-util/get-hacker.ts b/scripts/cli-util/get-hacker.ts new file mode 100644 index 00000000..e65da658 --- /dev/null +++ b/scripts/cli-util/get-hacker.ts @@ -0,0 +1,57 @@ +import { input, select } from '@inquirer/prompts'; +import { UserData } from '../../types/database'; +import useSWR from 'swr'; +import dbConnect from '../../middleware/database'; + +export const handleGetHacker = async () => { + const hackerEmail = await input({ + message: 'Enter hacker email', + }); + + const subAction1 = await select({ + message: 'Select an action to perform', + choices: [ + { + name: 'Get events', + value: 'get-events', + }, + { + name: 'Get team info', + value: 'get-team', + }, + { + name: 'Get application', + value: 'get-application', + }, + { + name: 'Get document', + value: 'get-document', + }, + ], + }); + + switch (subAction1) { + case 'get-events': + await getEvents(); + break; + case 'get-team': + await getTeam(); + break; + case 'get-application': + await getApplication(); + break; + case 'get-document': + await getDocument(); + break; + default: + console.log('Invalid action'); + } +}; + +const getEvents = async () => {}; + +const getTeam = async () => {}; + +const getApplication = async () => {}; + +const getDocument = async () => {}; diff --git a/scripts/cli-util/modify-hacker.ts b/scripts/cli-util/modify-hacker.ts new file mode 100644 index 00000000..31cdd7f5 --- /dev/null +++ b/scripts/cli-util/modify-hacker.ts @@ -0,0 +1,102 @@ +import { input, select } from '@inquirer/prompts'; +import dbConnect from '../../middleware/database'; + +// TODO: zi +/** + * Quickly change the application status of hacker. + * A hacker has multiple application statuses. + */ +export const handleModifyHacker = async () => { + // get hacker email + const hackerEmail = await input({ + message: 'Enter hacker email', + }); + + // get sub-action + const subAction1 = await select({ + message: 'Select sub-action to perform', + choices: [ + { + name: 'Change application status', + value: 'change-status', + }, + { + name: 'Delete application', + value: 'delete-application', + }, + { + name: 'Join a team', + value: 'join-team', + }, + { + name: 'Leave team', + value: 'leave-team', + }, + { + name: 'NFC check-in', + value: 'nfc-check-in', + }, + ], + }); + + // perf + switch (subAction1) { + case 'change-status': + break; + case 'delete-application': + break; + case 'join-team': + break; + case 'leave-team': + break; + case 'nfc-check-in': + break; + } +}; + +const changeStatus = async () => { + const newStatus = await select({ + message: 'Select new status', + choices: [ + { + name: 'Change application status to CREATED', + value: 'created', + }, + { + name: 'Change application status to DECLINED', + value: 'declined', + }, + { + name: 'Change application status to SUBMITTED', + value: 'submitted', + }, + { + name: 'Change application status to ACCEPTED', + value: 'accepted', + }, + { + name: 'Change application status to CONFIRMED', + value: 'confirmed', + }, + { + name: 'Change application status to REJECTED', + value: 'rejected', + }, + { + name: 'Change application status to CHECKED_IN', + value: 'checked-in', + }, + ], + }); + + // + await dbConnect(); +}; + +const deleteApplication = async () => {}; + +const joinTeam = async () => {}; + +const leaveTeam = async () => {}; + +const nfcCheckIn = async () => {}; diff --git a/scripts/dev-cli.ts b/scripts/dev-cli.ts index f54e2fa2..81a97162 100644 --- a/scripts/dev-cli.ts +++ b/scripts/dev-cli.ts @@ -1,6 +1,9 @@ import { input, select } from '@inquirer/prompts'; +import dbConnect from '../middleware/database'; import * as dotenv from 'dotenv'; import application from '../models/application'; +import { handleModifyHacker } from './cli-util/modify-hacker'; +import { handleGetHacker } from './cli-util/get-hacker'; dotenv.config(); /** @@ -18,19 +21,70 @@ const executeCLI = async () => { ], }); + // TODO: + // list actions we as devs will need to do and can be simplified with this CLI tool + // [ ] populate collections with dummy data + // [ ] clear collection (danger) + // [G] get a document from a colleciton (i.e., hacker document using email) + // [ ] hacker document using email + // [ ] team document using team or hacker email or team invite code + // [Z] automatically allow a hacker to check in to an event (via nfc) + // Select action const action = await select({ message: 'Select action to perform', choices: [ + { + name: "Get a hacker's document", + value: 'get-hacker', + // sub-action: + // 1. see their events + // 2. see their team info + // 3. see their application + // 4. get entire JSON of their document + }, + { + name: 'Get a team document', + value: 'get-team', + // sub-action: + // 1. see their schedule + // 2. see their members + // 3. get entire JSON of their document + }, { name: "Modify a hacker's document", value: 'modify-hacker', + // sub-action: + // 1. change application status + // 2. delete application + // 3. join/leave team + // 4. check in + }, + { + name: 'Modify a team', + value: 'modify-team', + // sub-action: + // 1. change team name + // 2. change team members? + // 3. change team invite code? + // 4. change devpost link? + }, + { + name: 'Clear a collection (dangerous)', + value: 'clear-collection', + }, + { + name: 'Populate a collection', + value: 'populate-collection', }, ], }); // Perform action switch (action) { + case 'get-hacker': + await handleGetHacker(); + break; case 'modify-hacker': await handleModifyHacker(); break; @@ -39,62 +93,9 @@ const executeCLI = async () => { } }; -/** - * Quickly change the application status of hacker. - * A hacker has multiple application statuses. - */ -const handleModifyHacker = async () => { - const hackerEmail = await input({ - message: 'Enter hacker email', - }); - - const subAction1 = await select({ - message: 'Select sub-action to perform', - choices: [ - { - name: 'Change application status to CREATED', - value: 'created', - }, - { - name: 'Change application status to DECLINED', - value: 'declined', - }, - { - name: 'Change application status to SUBMITTED', - value: 'submitted', - }, - { - name: 'Change application status to ACCEPTED', - value: 'accepted', - }, - { - name: 'Change application status to CONFIRMED', - value: 'confirmed', - }, - { - name: 'Change application status to REJECTED', - value: 'rejected', - }, - { - name: 'Change application status to CHECKED_IN', - value: 'checked-in', - }, - ], - }); - - const subAction2 = await select({ - message: "Do you want to delete the hacker's application?", - choices: [ - { - name: 'Yes', - value: 'yes', - }, - { - name: 'No', - value: 'no', - }, - ], - }); +// handle api error(a function that's called when API calls return 404) +const handleError = () => { + console.log('Error: You need to have the witness running'); }; // Execute the CLI tool