Skip to content

Commit

Permalink
feat: get-hacker cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrield2731 committed Sep 14, 2023
1 parent 152d3e7 commit f9d80b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
47 changes: 38 additions & 9 deletions scripts/cli-util/get-hacker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { input, select } from '@inquirer/prompts';
import dbConnect from '../../middleware/database';
import User from '../../models/user';
import Event from '../../models/event';
import team from '../../models/team';
import { promptAction } from '../dev-cli';
import { UserData, TeamData } from '../../types/database';
import { UserData, TeamData, EventData } from '../../types/database';

export const handleGetHacker = async () => {
const hackerEmail = await input({
Expand All @@ -28,8 +29,8 @@ export const handleGetHacker = async () => {
value: 'get-team',
},
{
name: 'Get application',
value: 'get-application',
name: 'Get application status',
value: 'get-application-status',
},
{
name: 'Get document',
Expand All @@ -43,30 +44,58 @@ export const handleGetHacker = async () => {

switch (subAction1) {
case 'get-events':
await getEvents();
await getEvents(user);
break;
case 'get-team':
await getTeam(user);
break;
case 'get-application':
await getApplication();
case 'get-application-status':
await getApplicationStatus(user);
break;
case 'get-document':
console.log(user);
await getDocument(user);
break;
default:
console.log('Invalid action');
}
};

const getEvents = async () => {};
const getEvents = async (user: UserData) => {
const events = user.eventsAttended;
const size = events.length;

if (size === 0) console.log('No events attended yet! :(');

for (const eventId of events) {
const event: EventData = JSON.parse(JSON.stringify(await Event.findOne({ _id: eventId })));
console.log(event.name);
}

console.log('');
return promptAction();
};

const getTeam = async (user: UserData) => {
const teamId = user.team;
const hackerTeam = JSON.parse(JSON.stringify(await team.findOne({ _id: teamId })));
console.log('Team Document');
console.log(hackerTeam);

console.log('');
return promptAction();
};

const getApplication = async () => {};
const getApplicationStatus = async (user: UserData) => {
console.log(`Application status: ${user.applicationStatus}`);

console.log('');
return promptAction();
};

const getDocument = async (user: UserData) => {
console.log('User Document:');
console.log(user);

console.log('');
return promptAction();
};
1 change: 1 addition & 0 deletions types/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface UserData {
team?: mongoose.Schema.Types.ObjectId;
application?: mongoose.Schema.Types.ObjectId;
applicationStatus: ApplicationStatus;
eventsAttended: mongoose.Schema.Types.ObjectId[];
}

export interface PreAddData {
Expand Down

0 comments on commit f9d80b7

Please sign in to comment.