Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slight changes #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PORT = 2121
DB_STRING = mongodb+srv://demo:[email protected].mongodb.net/todos?retryWrites=true&w=majority
DB_STRING = mongodb+srv://codewithjazzy:[email protected].mongodb.net/test?retryWrites=true&w=majority
8 changes: 5 additions & 3 deletions controllers/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module.exports = {
console.log(req.user)
try{
const todoItems = await Todo.find({userId:req.user.id})
const itemsLeft = await Todo.countDocuments({userId:req.user.id,completed: false})
const itemsLeft = await Todo.countDocuments({userId:req.user.id,completed: false,deleted: false})
res.render('todos.ejs', {todos: todoItems, left: itemsLeft, user: req.user})
}catch(err){
console.log(err)
}
},
createTodo: async (req, res)=>{
try{
await Todo.create({todo: req.body.todoItem, completed: false, userId: req.user.id})
await Todo.create({todo: req.body.todoItem, completed: false, deleted: false, userId: req.user.id})
console.log('Todo has been added!')
res.redirect('/todos')
}catch(err){
Expand Down Expand Up @@ -45,7 +45,9 @@ module.exports = {
deleteTodo: async (req, res)=>{
console.log(req.body.todoIdFromJSFile)
try{
await Todo.findOneAndDelete({_id:req.body.todoIdFromJSFile})
await Todo.findOneAndUpdate({_id:req.body.todoIdFromJSFile},{
deleted: true
})
console.log('Deleted Todo')
res.json('Deleted It')
}catch(err){
Expand Down
4 changes: 4 additions & 0 deletions models/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const TodoSchema = new mongoose.Schema({
type: Boolean,
required: true,
},
deleted: {
type: Boolean,
required: true,
},
userId: {
type: String,
required: true
Expand Down
Loading