diff --git a/backend/src/controllers/topicController.js b/backend/src/controllers/topicController.js index 89fdc14..c25fdde 100644 --- a/backend/src/controllers/topicController.js +++ b/backend/src/controllers/topicController.js @@ -1,17 +1,32 @@ const Topic = require('../models/topic') +const User = require('../models/user') const jwt = require("jsonwebtoken"); exports.getAllTopics = async (req, res) => { // console.log(req.email) -try{ - const topics = await Topic.find().select('title no videoUrl _id') - res.status(200).json(topics) -} -catch(err){ - res.status(500).json({error: err}) -} + try{ + const email = req.email + const user = await User.findOne({ email }) + + + + + const topics = await Topic.find().select('title no videoUrl _id') + + const newtopics = topics.map((item)=> { + const newOb = {...item._doc, isCompleted: (user.completed).includes(item.no)} + return newOb + } ) + + + + res.status(200).json(newtopics) + } + catch(err){ + res.status(500).json({error: err}) + } } diff --git a/backend/src/models/user.js b/backend/src/models/user.js index b4b0e89..f51c869 100644 --- a/backend/src/models/user.js +++ b/backend/src/models/user.js @@ -92,24 +92,7 @@ const User= mongoose.model("users",{ } } ], - completed:[ - { - topicId:{ - type: Number, - required: true - }, - isVideoFinished:{ - type: Boolean, - required: true, - default: false - }, - isQuizFinished:{ - type: Boolean, - required: true, - default: false - } - } - ] + completed:[String] }) module.exports = User \ No newline at end of file diff --git a/webapp/src/components/HeadingComponent.js b/webapp/src/components/HeadingComponent.js index b8e3820..d2919bd 100644 --- a/webapp/src/components/HeadingComponent.js +++ b/webapp/src/components/HeadingComponent.js @@ -20,7 +20,7 @@ function HeadingComponent({heading}) {