Skip to content

Commit

Permalink
added tags to question
Browse files Browse the repository at this point in the history
  • Loading branch information
effy971 committed Nov 10, 2020
1 parent 16f8f34 commit b61e43c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
13 changes: 13 additions & 0 deletions frontend/src/Components/Question/AskQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ const AskQuestion = () => {
id="noise"
className="widgEditor"
></textarea>
<h4>Tags</h4>
<label for="oalevel">O Level / Alevel</label>
<input name="oalevel" type="text"></input>
<label for="subject">Subject</label>
<input name="subject"></input>
<label for="year">Year</label>
<input name="year"></input>
<label for="paperNumber">Paper Number</label>
<input name="paperNumber"></input>
<label for="month">June / October</label>
<input name="month"></input>
<label for="questionNumber">Question Number</label>
<input name="questionNumber"></input> <br />
<button type="submit" name="submit">
Submit Question
</button>
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ app.post("/login", async (req, res) => {
});

app.post("/askquestion", async (req, res) => {
const tags = {
oAlevel: req.body.oalevel,
subject: req.body.subject,
year: req.body.year,
paperNumber: req.body.paperNumber,
month: req.body.month,
questionNumber: req.body.questionNumber,
};
const result = await insertQuestion(
req.body.title,
req.body.area,
req.body.detail
req.body.detail,
tags
);
result
? res.send("question posted success")
Expand Down
16 changes: 14 additions & 2 deletions insertquestion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { MongoClient } = require("mongodb");

module.exports = async function (title, area, detail) {
module.exports = async function (title, area, detail, tags) {
const uri = process.env.DB_CREDENTIALS;

const client = new MongoClient(uri);
Expand All @@ -13,7 +13,19 @@ module.exports = async function (title, area, detail) {

// create js obj received by /register

const doc = { title: title, area: area, detail: detail };
const doc = {
title: title,
area: area,
detail: detail,
tags: {
oAlevel: tags.oAlevel,
subject: tags.subject,
year: tags.year,
paperNumber: tags.paperNumber,
month: tags.month,
questionNumber: tags.questionNumber,
},
};
const result = await collection.insertOne(doc);

console.log(`${result.insertedCount} documents were inserted into db`);
Expand Down

0 comments on commit b61e43c

Please sign in to comment.