Skip to content

Commit

Permalink
feat: get teams
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrield2731 committed Sep 15, 2023
1 parent f9d80b7 commit d3a11d2
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/cli-util/get-hacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
82 changes: 82 additions & 0 deletions scripts/cli-util/get-team.ts
Original file line number Diff line number Diff line change
@@ -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();
};
4 changes: 4 additions & 0 deletions scripts/dev-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d3a11d2

Please sign in to comment.