Skip to content

Commit

Permalink
topics fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Luxshan2000 committed Oct 16, 2023
1 parent d417cfe commit ba28feb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
29 changes: 22 additions & 7 deletions backend/src/controllers/topicController.js
Original file line number Diff line number Diff line change
@@ -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})
}
}


Expand Down
19 changes: 1 addition & 18 deletions backend/src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions webapp/src/components/HeadingComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function HeadingComponent({heading}) {
<h5 className=' col-11 CourseHeading'>
{heading.no + ". "+ heading.title}
<span className='instructionFamily badge ms-1 p-2 text-dark bg-success-subtle'>
Completed!
{heading.isCompleted ? "Completed!" : ""}
</span>
</h5>
{!toggle? <i class=" col-1 bi p-1 bi-chevron-down"></i>:<i class=" col-1 bi p-1 bi-chevron-up"></i>}
Expand All @@ -39,9 +39,9 @@ function HeadingComponent({heading}) {
{heading.videoUrl? `${heading.no}.1 Interactive Video and notes` :"" }
</Link>
</h5>
<span className='instructionFamily badge m-1 p-2 text-dark bg-success-subtle'>
{/* <span className='instructionFamily badge m-1 p-2 text-dark bg-success-subtle'>
Done: Complete the activity
</span>
</span> */}
</div>
<div>
<hr/>
Expand All @@ -55,11 +55,12 @@ function HeadingComponent({heading}) {
{`${heading.no}.2 Quiz`}
</Link>
</h5>
<span className='instructionFamily badge m-1 p-2 text-dark bg-danger-subtle'>
To do: Complete the activity
<hr className=' text-success'/>
<span className={`instructionFamily badge m-1 p-2 text-dark ${ heading.isCompleted ?"bg-success-subtle" :"bg-danger-subtle"}`}>
{ !heading.isCompleted ? "To do: Complete the activity" : "Done: Completed"}
</span>
<span className='instructionFamily badge m-1 p-2 text-dark bg-warning-subtle'>
To unlock: Upgrade to premium
To unlock quizzes: Premium upgrade is required
</span>
</div>

Expand Down

0 comments on commit ba28feb

Please sign in to comment.