diff --git a/scripts/cli-util/get-hacker.ts b/scripts/cli-util/get-hacker.ts index e65da658..a6c67c4d 100644 --- a/scripts/cli-util/get-hacker.ts +++ b/scripts/cli-util/get-hacker.ts @@ -1,18 +1,26 @@ import { input, select } from '@inquirer/prompts'; -import { UserData } from '../../types/database'; -import useSWR from 'swr'; import dbConnect from '../../middleware/database'; +import User from '../../models/user'; +import team from '../../models/team'; +import { promptAction } from '../dev-cli'; +import { UserData, TeamData } from '../../types/database'; export const handleGetHacker = async () => { const hackerEmail = await input({ message: 'Enter hacker email', }); + const user: UserData | null = JSON.parse(JSON.stringify(await User.findOne({ email: hackerEmail }))); + if (!user) { + console.log('Hacker not found'); + return promptAction(); + } + const subAction1 = await select({ message: 'Select an action to perform', choices: [ { - name: 'Get events', + name: 'Get events attended', value: 'get-events', }, { @@ -30,18 +38,21 @@ export const handleGetHacker = async () => { ], }); + // connect to db + await dbConnect(); + switch (subAction1) { case 'get-events': await getEvents(); break; case 'get-team': - await getTeam(); + await getTeam(user); break; case 'get-application': await getApplication(); break; case 'get-document': - await getDocument(); + console.log(user); break; default: console.log('Invalid action'); @@ -50,8 +61,12 @@ export const handleGetHacker = async () => { const getEvents = async () => {}; -const getTeam = async () => {}; +const getTeam = async (user: UserData) => { + const teamId = user.team; + const hackerTeam = JSON.parse(JSON.stringify(await team.findOne({ _id: teamId }))); + console.log(hackerTeam); -const getApplication = async () => {}; + return promptAction(); +}; -const getDocument = async () => {}; +const getApplication = async () => {}; diff --git a/scripts/cli-util/modify-hacker.ts b/scripts/cli-util/modify-hacker.ts index 31cdd7f5..ed3200d7 100644 --- a/scripts/cli-util/modify-hacker.ts +++ b/scripts/cli-util/modify-hacker.ts @@ -1,5 +1,7 @@ import { input, select } from '@inquirer/prompts'; -import dbConnect from '../../middleware/database'; +import User from '../../models/user'; +import { promptAction } from '../dev-cli'; +import { ApplicationStatus, UserData } from '../../types/database'; // TODO: zi /** @@ -12,8 +14,17 @@ export const handleModifyHacker = async () => { message: 'Enter hacker email', }); + // query for hacker document + const hacker: UserData | null = await User.findOne({ email: hackerEmail }); + + // if hacker not found, re-prompt + if (!hacker) { + console.log('Oops, Hacker not found! Please try again.'); + return promptAction(); + } + // get sub-action - const subAction1 = await select({ + const subAction = await select({ message: 'Select sub-action to perform', choices: [ { @@ -39,9 +50,10 @@ export const handleModifyHacker = async () => { ], }); - // perf - switch (subAction1) { + // perform sub-action + switch (subAction) { case 'change-status': + await changeStatus(hacker); break; case 'delete-application': break; @@ -54,7 +66,11 @@ export const handleModifyHacker = async () => { } }; -const changeStatus = async () => { +const changeStatus = async (hacker: UserData) => { + const oldStatus: ApplicationStatus = hacker.applicationStatus; + + // console.log(`Current status: ${Object.values(ApplicationStatus)[oldStatus]}`); + const newStatus = await select({ message: 'Select new status', choices: [ @@ -89,8 +105,7 @@ const changeStatus = async () => { ], }); - // - await dbConnect(); + // TODO: }; const deleteApplication = async () => {}; diff --git a/scripts/dev-cli.ts b/scripts/dev-cli.ts index 81a97162..27aba9e1 100644 --- a/scripts/dev-cli.ts +++ b/scripts/dev-cli.ts @@ -21,6 +21,17 @@ const executeCLI = async () => { ], }); + // connect to db + await dbConnect(process.env.DATABASE_URL); + + // prompt action + await promptAction(); + + // exit + process.exit(0); +}; + +export const promptAction = async () => { // TODO: // list actions we as devs will need to do and can be simplified with this CLI tool // [ ] populate collections with dummy data