@noemaresearch/ctf-cli
Version:
A CLI tool for navigating and playing cybersecurity challenges
47 lines (41 loc) • 1.34 kB
text/typescript
import boxen from 'boxen';
import chalk from 'chalk';
import { Feedback } from '../models/feedback';
import { promptWithErrorHandling } from '../helpers/prompts';
import { updateUserAutoFeedbackFlag } from './user.service';
import { httpsCallable } from 'firebase/functions';
import { functions } from '../firebase';
export async function promptForFeedback(feedback: Feedback): Promise<void> {
try {
const addFeedbackFunc = httpsCallable<Feedback, { success: boolean }>(
functions,
'addFeedback'
)
await addFeedbackFunc(feedback)
console.log();
console.log(
boxen(
chalk.green(chalk.bold('Feedback submitted successfully.')),
{
padding: 1,
borderColor: 'green',
borderStyle: 'round',
}
)
);
if (feedback.challenge_id || feedback.stage_id) {
let hasAutoFeedback = false;
const userChoice = await promptWithErrorHandling({
message: 'Do you want to receive automatic feedback for future stages or challenges?',
choices: [
{ name: 'Yes', value: 'yes' },
{ name: 'No', value: 'no' }
]
});
hasAutoFeedback = userChoice === 'yes';
await updateUserAutoFeedbackFlag(hasAutoFeedback)
}
} catch (error) {
throw new Error('Failed to submit feedback');
}
}