Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive Dev CLI #361

Merged
merged 18 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@ant-design/icons": "^4.7.0",
"@aws-sdk/client-s3": "^3.178.0",
"@aws-sdk/client-ses": "^3.180.0",
"@inquirer/prompts": "^3.0.4",
"@next-auth/mongodb-adapter": "^1.0.4",
"@types/escape-html": "^1.0.2",
"@types/formidable": "^2.0.5",
Expand Down
110 changes: 110 additions & 0 deletions scripts/cli-util/get-hacker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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, EventData, TeamData } from '../../types/database';

export const handleGetHacker = async () => {
const hackerEmail = await input({
message: 'Enter hacker email',
});

const user: UserData | null = 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 attended',
value: 'get-events',
},
{
name: 'Get team info',
value: 'get-team',
},
{
name: 'Get application status',
value: 'get-application-status',
},
{
name: 'Get document',
value: 'get-document',
},
],
});

// connect to db
await dbConnect();

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

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 | null = await Event.findOne({ _id: eventId });
if (!event) {
console.log('Event not found');
return promptAction();
} else {
console.log(`Event name: ${event.name}`);
}
}

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

const getTeam = async (user: UserData) => {
const teamId = user.team;
const hackerTeam: TeamData | null = await Team.findOne({ _id: teamId });
if (!hackerTeam) {
console.log('Team not found');
return promptAction();
} else {
console.log(`Team name: ${hackerTeam.name}`);
}

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

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();
};
86 changes: 86 additions & 0 deletions scripts/cli-util/get-team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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 = 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 | null = await User.findOne({ _id: memberId });
if (!member) {
console.log(`Member ${count++}:`);
console.log('Member not found');
} else {
console.log(`Member ${count++}:`);
console.log(`Name: ${member.name}`);
console.log(`Email: ${member.email}`);
}
}

return promptAction();
};

const getDocument = async (team: TeamData) => {
console.log('Team Document:');
console.log(team);

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