Skip to content

Commit

Permalink
initial cli commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrield2731 committed Sep 9, 2023
1 parent 93dc724 commit 17f29cf
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 56 deletions.
57 changes: 57 additions & 0 deletions scripts/cli-util/get-hacker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { input, select } from '@inquirer/prompts';
import { UserData } from '../../types/database';
import useSWR from 'swr';
import dbConnect from '../../middleware/database';

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

const subAction1 = await select({
message: 'Select an action to perform',
choices: [
{
name: 'Get events',
value: 'get-events',
},
{
name: 'Get team info',
value: 'get-team',
},
{
name: 'Get application',
value: 'get-application',
},
{
name: 'Get document',
value: 'get-document',
},
],
});

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

const getEvents = async () => {};

const getTeam = async () => {};

const getApplication = async () => {};

const getDocument = async () => {};
102 changes: 102 additions & 0 deletions scripts/cli-util/modify-hacker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { input, select } from '@inquirer/prompts';
import dbConnect from '../../middleware/database';

// TODO: zi
/**
* Quickly change the application status of hacker.
* A hacker has multiple application statuses.
*/
export const handleModifyHacker = async () => {
// get hacker email
const hackerEmail = await input({
message: 'Enter hacker email',
});

// get sub-action
const subAction1 = await select({
message: 'Select sub-action to perform',
choices: [
{
name: 'Change application status',
value: 'change-status',
},
{
name: 'Delete application',
value: 'delete-application',
},
{
name: 'Join a team',
value: 'join-team',
},
{
name: 'Leave team',
value: 'leave-team',
},
{
name: 'NFC check-in',
value: 'nfc-check-in',
},
],
});

// perf
switch (subAction1) {
case 'change-status':
break;
case 'delete-application':
break;
case 'join-team':
break;
case 'leave-team':
break;
case 'nfc-check-in':
break;
}
};

const changeStatus = async () => {
const newStatus = await select({
message: 'Select new status',
choices: [
{
name: 'Change application status to CREATED',
value: 'created',
},
{
name: 'Change application status to DECLINED',
value: 'declined',
},
{
name: 'Change application status to SUBMITTED',
value: 'submitted',
},
{
name: 'Change application status to ACCEPTED',
value: 'accepted',
},
{
name: 'Change application status to CONFIRMED',
value: 'confirmed',
},
{
name: 'Change application status to REJECTED',
value: 'rejected',
},
{
name: 'Change application status to CHECKED_IN',
value: 'checked-in',
},
],
});

//
await dbConnect();
};

const deleteApplication = async () => {};

const joinTeam = async () => {};

const leaveTeam = async () => {};

const nfcCheckIn = async () => {};
113 changes: 57 additions & 56 deletions scripts/dev-cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { input, select } from '@inquirer/prompts';
import dbConnect from '../middleware/database';
import * as dotenv from 'dotenv';
import application from '../models/application';
import { handleModifyHacker } from './cli-util/modify-hacker';
import { handleGetHacker } from './cli-util/get-hacker';
dotenv.config();

/**
Expand All @@ -18,19 +21,70 @@ const executeCLI = async () => {
],
});

// TODO:
// list actions we as devs will need to do and can be simplified with this CLI tool
// [ ] populate collections with dummy data
// [ ] clear collection (danger)
// [G] get a document from a colleciton (i.e., hacker document using email)
// [ ] hacker document using email
// [ ] team document using team or hacker email or team invite code
// [Z] automatically allow a hacker to check in to an event (via nfc)

// Select action
const action = await select({
message: 'Select action to perform',
choices: [
{
name: "Get a hacker's document",
value: 'get-hacker',
// sub-action:
// 1. see their events
// 2. see their team info
// 3. see their application
// 4. get entire JSON of their document
},
{
name: 'Get a team document',
value: 'get-team',
// sub-action:
// 1. see their schedule
// 2. see their members
// 3. get entire JSON of their document
},
{
name: "Modify a hacker's document",
value: 'modify-hacker',
// sub-action:
// 1. change application status
// 2. delete application
// 3. join/leave team
// 4. check in
},
{
name: 'Modify a team',
value: 'modify-team',
// sub-action:
// 1. change team name
// 2. change team members?
// 3. change team invite code?
// 4. change devpost link?
},
{
name: 'Clear a collection (dangerous)',
value: 'clear-collection',
},
{
name: 'Populate a collection',
value: 'populate-collection',
},
],
});

// Perform action
switch (action) {
case 'get-hacker':
await handleGetHacker();
break;
case 'modify-hacker':
await handleModifyHacker();
break;
Expand All @@ -39,62 +93,9 @@ const executeCLI = async () => {
}
};

/**
* Quickly change the application status of hacker.
* A hacker has multiple application statuses.
*/
const handleModifyHacker = async () => {
const hackerEmail = await input({
message: 'Enter hacker email',
});

const subAction1 = await select({
message: 'Select sub-action to perform',
choices: [
{
name: 'Change application status to CREATED',
value: 'created',
},
{
name: 'Change application status to DECLINED',
value: 'declined',
},
{
name: 'Change application status to SUBMITTED',
value: 'submitted',
},
{
name: 'Change application status to ACCEPTED',
value: 'accepted',
},
{
name: 'Change application status to CONFIRMED',
value: 'confirmed',
},
{
name: 'Change application status to REJECTED',
value: 'rejected',
},
{
name: 'Change application status to CHECKED_IN',
value: 'checked-in',
},
],
});

const subAction2 = await select({
message: "Do you want to delete the hacker's application?",
choices: [
{
name: 'Yes',
value: 'yes',
},
{
name: 'No',
value: 'no',
},
],
});
// handle api error(a function that's called when API calls return 404)
const handleError = () => {
console.log('Error: You need to have the witness running');
};

// Execute the CLI tool
Expand Down

0 comments on commit 17f29cf

Please sign in to comment.