diff --git a/scripts/cli-util/get-hacker.ts b/scripts/cli-util/get-hacker.ts index c80c6f69..52169936 100644 --- a/scripts/cli-util/get-hacker.ts +++ b/scripts/cli-util/get-hacker.ts @@ -4,7 +4,7 @@ import User from '../../models/user'; import Event from '../../models/event'; import team from '../../models/team'; import { promptAction } from '../dev-cli'; -import { UserData, TeamData, EventData } from '../../types/database'; +import { UserData, EventData } from '../../types/database'; export const handleGetHacker = async () => { const hackerEmail = await input({ diff --git a/scripts/cli-util/get-team.ts b/scripts/cli-util/get-team.ts new file mode 100644 index 00000000..f4a7a4c6 --- /dev/null +++ b/scripts/cli-util/get-team.ts @@ -0,0 +1,82 @@ +import { input, select } from '@inquirer/prompts'; +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 handleGetTeam = async () => { + const teamName = await input({ + message: 'Enter team name', + }); + + const team: TeamData | null = JSON.parse(JSON.stringify(await Team.findOne({ name: teamName }))); + if (!team) { + console.log('team not found'); + return promptAction(); + } + + const subAction1 = await select({ + message: 'Select an action to perform', + choices: [ + { + name: 'Get schedule', + value: 'get-schedule', + }, + { + name: 'Get members', + value: 'get-members', + }, + { + name: 'Get document', + value: 'get-document', + }, + ], + }); + + // connect to db + await dbConnect(); + + switch (subAction1) { + case 'get-schedule': + await getSchedule(team); + break; + case 'get-members': + await getMembers(team); + break; + case 'get-document': + await getDocument(team); + break; + default: + console.log('Invalid action'); + } +}; + +const getSchedule = async (team: TeamData) => { + console.log('IN PROGRESS'); + console.log(''); + return promptAction(); +}; + +const getMembers = async (team: TeamData) => { + const memberIds = team.members; + + let count = 1; + for (const memberId of memberIds) { + const member: UserData = JSON.parse(JSON.stringify(await User.findOne({ _id: memberId }))); + console.log(`Member ${count++}:`); + console.log(`Name: ${member.name}`); + console.log(`Email: ${member.email}`); + } + + console.log(''); + return promptAction(); +}; + +const getDocument = async (team: TeamData) => { + console.log('Team Document:'); + console.log(team); + + console.log(''); + return promptAction(); +}; diff --git a/scripts/dev-cli.ts b/scripts/dev-cli.ts index 9b851a8d..5109e0d4 100644 --- a/scripts/dev-cli.ts +++ b/scripts/dev-cli.ts @@ -3,6 +3,7 @@ import dbConnect from '../middleware/database'; import * as dotenv from 'dotenv'; import { handleModifyHacker } from './cli-util/modify-hacker'; import { handleGetHacker } from './cli-util/get-hacker'; +import { handleGetTeam } from './cli-util/get-team'; dotenv.config(); /** @@ -111,6 +112,9 @@ export const promptAction = async () => { case 'get-hacker': await handleGetHacker(); break; + case 'get-team': + await handleGetTeam(); + break; case 'modify-hacker': await handleModifyHacker(); break;