Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
effy971 committed Nov 11, 2020
1 parent f677135 commit fcff031
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
18 changes: 14 additions & 4 deletions adminquestion.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 @@ -11,9 +11,19 @@ module.exports = async function (title, area, detail) {
const database = client.db("4learn");
const collection = database.collection("Admin");

// 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
2 changes: 2 additions & 0 deletions frontend/src/Components/Admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Admin = () => {

await resultObj.forEach((element) => {
tempResult.push(element);
console.log(tempResult);
});
// setTitle(tempTitle);
// setArea(tempArea);
Expand All @@ -48,6 +49,7 @@ const Admin = () => {
area={element.area}
detail={element.detail}
id={element._id}
tags={element.tags}
/>
))
)}
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/Components/Admin/AdminQuestion.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import React from "react";
import parse from "html-react-parser";
const AdminQuestion = (props) => {
console.log(props.tags.oAlevel);
const handleClickAccept = () => {
fetch("/askquestion", {
method: "POST",
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: props.id,
title: props.title,
area: props.area,
detail: props.detail,
oAlevel: props.tags.oAlevel,
subject: props.tags.subject,
year: props.tags.year,
paperNumber: props.tags.paperNumber,
month: props.tags.month,
questionNumber: props.tags.questionNumber,
}),
});
};
Expand All @@ -32,6 +40,7 @@ const AdminQuestion = (props) => {
<h4>Title: {props.title}</h4>

<p>{parse(props.detail)}</p>
<p>{props.tags.subject}</p>
<button onClick={handleClickAccept}>Accept</button>
<button onClick={handleClickReject}>Reject</button>
</div>
Expand Down
19 changes: 16 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ app.post("/login", async (req, res) => {
}
});

app.post("/askquestion", async (req, res) => {
app.put("/askquestion", async (req, res) => {
const tags = {
oAlevel: req.body.oalevel,
oAlevel: req.body.oAlevel,
subject: req.body.subject,
year: req.body.year,
paperNumber: req.body.paperNumber,
Expand All @@ -137,6 +137,7 @@ app.post("/askquestion", async (req, res) => {
req.body.detail,
tags
);
const deleteResult = await adminDeletequestion(req.body.id);
result
? res.send("question posted success")
: res.send("there was an error while posting");
Expand All @@ -150,11 +151,23 @@ app.get("/adminviewquestion", async (req, res) => {
});

app.post("/adminquestion", 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,
};
console.log(req.body.id);
console.log("adsd");
const result = await adminQuestion(
req.body.title,
req.body.area,
req.body.detail
req.body.detail,
tags
);

result
? res.send("question posted success")
: res.send("there was an error while posting");
Expand Down

0 comments on commit fcff031

Please sign in to comment.