Skip to content

Commit

Permalink
Setup questionDB
Browse files Browse the repository at this point in the history
  • Loading branch information
dedsecrattle committed Sep 22, 2024
1 parent bf94db0 commit b27104e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions backend/question-service/src/models/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ interface IQuestion extends Document {
questionId: string;
title: string;
description: string;
category: string;
categories: string[];
complexity: "Easy" | "Medium" | "Hard";
link: string;
}

const questionSchema = new Schema<IQuestion>({
questionId: { type: String, required: true, unique: true },
title: { type: String, required: true },
description: { type: String, required: true },
category: { type: String, required: true },
categories: { type: [String], required: true },
complexity: {
type: String,
enum: ["Easy", "Medium", "Hard"],
required: true,
},
link: { type: String, required: true },
});

const Question = model<IQuestion>("Question", questionSchema);
Expand Down
6 changes: 4 additions & 2 deletions backend/question-service/src/routes/questionRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ const router: Router = Router();

// Create a new question (POST)
router.post("/", async (req: Request, res: Response) => {
const { questionId, title, description, category, complexity } = req.body;
const { questionId, title, description, categories, complexity, link } =
req.body;

try {
const newQuestion = new Question({
questionId,
title,
description,
category,
categories,
complexity,
link,
});
const savedQuestion = await newQuestion.save();
res.status(201).json(savedQuestion);
Expand Down
1 change: 1 addition & 0 deletions backend/question-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ app.use(bodyParser.json());
// Routes
app.use("/api/questions", questionRoutes);

console.log(process.env.MONGODB_URI);
// Start the server
app.listen(PORT, () => {
connectToDB(
Expand Down

0 comments on commit b27104e

Please sign in to comment.