mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-09 06:04:17 -05:00
refactor(api): organise tooling (#59931)
This commit is contained in:
committed by
GitHub
parent
3c822da243
commit
ae387fbd5c
@@ -1,52 +0,0 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { MONGOHQ_URL } from '../../utils/env';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const ENV_EXAM_ID = args[0];
|
||||
|
||||
if (!ENV_EXAM_ID) {
|
||||
throw Error('First argument must be the EnvExam _id');
|
||||
}
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: MONGOHQ_URL
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function main() {
|
||||
console.info('Connecting to cluster...');
|
||||
await prisma.$connect();
|
||||
console.info('Connected.');
|
||||
|
||||
try {
|
||||
await prisma.envExam.update({
|
||||
where: {
|
||||
id: ENV_EXAM_ID
|
||||
},
|
||||
data: {
|
||||
deprecated: true
|
||||
}
|
||||
});
|
||||
console.info(`Exam "${ENV_EXAM_ID}" deprecated...`);
|
||||
const res = await prisma.envGeneratedExam.updateMany({
|
||||
where: {
|
||||
examId: ENV_EXAM_ID
|
||||
},
|
||||
data: {
|
||||
deprecated: true
|
||||
}
|
||||
});
|
||||
|
||||
console.info(`${res.count} generated exams deprecated...`);
|
||||
} catch (e) {
|
||||
console.error('Unable to deprecate exam due to:');
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
console.info(`Finished deprecating exam.`);
|
||||
}
|
||||
|
||||
void main();
|
||||
@@ -1,61 +0,0 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { generateExam } from '../utils/exam';
|
||||
import { MONGOHQ_URL } from '../../utils/env';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const ENV_EXAM_ID = args[0];
|
||||
const NUMBER_OF_EXAMS_TO_GENERATE = Number(args[1]);
|
||||
|
||||
if (!ENV_EXAM_ID) {
|
||||
throw Error('First argument must be the EnvExam _id');
|
||||
}
|
||||
if (!NUMBER_OF_EXAMS_TO_GENERATE) {
|
||||
throw Error('Second argument must be an unsigned integer');
|
||||
}
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: MONGOHQ_URL
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/// TODO:
|
||||
/// 1. Deprecate all previous generated exams for a given exam id?
|
||||
async function main() {
|
||||
console.info('Connecting to cluster...');
|
||||
await prisma.$connect();
|
||||
console.info('Connected.');
|
||||
|
||||
const exam = await prisma.envExam.findUnique({
|
||||
where: {
|
||||
id: ENV_EXAM_ID
|
||||
}
|
||||
});
|
||||
|
||||
if (!exam) {
|
||||
throw Error(`No exam with id "${ENV_EXAM_ID}" found.`);
|
||||
}
|
||||
|
||||
let numberOfExamsGenerated = 0;
|
||||
|
||||
console.info(
|
||||
`Exam with _id ${ENV_EXAM_ID} found. Generating ${NUMBER_OF_EXAMS_TO_GENERATE} exams...`
|
||||
);
|
||||
while (numberOfExamsGenerated < NUMBER_OF_EXAMS_TO_GENERATE) {
|
||||
try {
|
||||
const generatedExam = generateExam(exam);
|
||||
await prisma.envGeneratedExam.create({
|
||||
data: generatedExam
|
||||
});
|
||||
numberOfExamsGenerated++;
|
||||
console.info(`Generated ${numberOfExamsGenerated} exams`);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
console.log(`Finished generating exams.`);
|
||||
}
|
||||
|
||||
void main();
|
||||
@@ -1,43 +0,0 @@
|
||||
import { readFile } from 'fs/promises';
|
||||
import { EnvExam, PrismaClient } from '@prisma/client';
|
||||
import { MONGOHQ_URL } from '../../utils/env';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const EXAM_JSON_PATH = args[0];
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: MONGOHQ_URL
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function main() {
|
||||
console.info('Connecting to cluster...');
|
||||
await prisma.$connect();
|
||||
console.info('Connected.');
|
||||
|
||||
if (!EXAM_JSON_PATH) {
|
||||
throw Error('First argument must be the file path to the exam');
|
||||
}
|
||||
|
||||
const exam_str = await readFile(EXAM_JSON_PATH, 'utf-8');
|
||||
|
||||
const exam = JSON.parse(exam_str) as EnvExam;
|
||||
|
||||
try {
|
||||
const res = await prisma.envExam.create({
|
||||
data: exam
|
||||
});
|
||||
|
||||
console.info(
|
||||
`Exam "${res.config.name}" has been assigned id: "${res.id}".`
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('Unable to insert exam due to:');
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void main();
|
||||
@@ -1,24 +0,0 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import * as mocks from '../../../__mocks__/env-exam';
|
||||
import { MONGOHQ_URL } from '../../utils/env';
|
||||
|
||||
const prisma = new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: MONGOHQ_URL
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function main() {
|
||||
await prisma.$connect();
|
||||
|
||||
await prisma.envExamAttempt.deleteMany({});
|
||||
await prisma.envGeneratedExam.deleteMany({});
|
||||
await prisma.envExam.deleteMany({});
|
||||
|
||||
await prisma.envExam.create({ data: mocks.exam });
|
||||
await prisma.envGeneratedExam.create({ data: mocks.generatedExam });
|
||||
}
|
||||
|
||||
void main();
|
||||
Reference in New Issue
Block a user