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

made public feature #36

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
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"editor.fontSize": 38,
"terminal.integrated.fontSize": 60
}
// {
// "editor.fontSize": 38,
// "terminal.integrated.fontSize": 60
// }
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:demo@cluster0.nfzrd.mongodb.net/todolist?retryWrites=true&w=majority
DB_STRING = mongodb+srv://ajaymishra5277919886:f4Vftke9Tr1yqs8M@cluster0.i0xfedh.mongodb.net/?retryWrites=true&w=majority
9 changes: 7 additions & 2 deletions controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module.exports = {
getIndex: (req,res)=>{
getIndex: (req, res) => {
res.render('index.ejs')
}
},
getQuote: ((req, res) => {
res.json({
prop: 'value'
})
})
}
62 changes: 39 additions & 23 deletions controllers/todos.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,70 @@
const Todo = require('../models/Todo')

const Public = require('../models/public')
module.exports = {
getTodos: async (req,res)=>{
try{
getTodos: async (req, res) => {
try {
const todoItems = await Todo.find()
const itemsLeft = await Todo.countDocuments({completed: false})
res.render('todos.ejs', {todos: todoItems, left: itemsLeft})
}catch(err){
const itemsLeft = await Todo.countDocuments({ completed: false })
res.render('todos.ejs', { todos: todoItems, left: itemsLeft })
} catch (err) {
console.log(err)
}
},
createTodo: async (req, res)=>{
try{
await Todo.create({todo: req.body.todoItem, completed: false})
createTodo: async (req, res) => {
try {
await Todo.create({ todo: req.body.todoItem, completed: false })
console.log('Todo has been added!')
res.redirect('/todos')
}catch(err){
} catch (err) {
console.log(err)
}
},
markComplete: async (req, res)=>{
try{
await Todo.findOneAndUpdate({_id:req.body.todoIdFromJSFile},{
markComplete: async (req, res) => {
try {
await Todo.findOneAndUpdate({ _id: req.body.todoIdFromJSFile }, {
completed: true
})
console.log('Marked Complete')
res.json('Marked Complete')
}catch(err){
} catch (err) {
console.log(err)
}
},
markIncomplete: async (req, res)=>{
try{
await Todo.findOneAndUpdate({_id:req.body.todoIdFromJSFile},{
markIncomplete: async (req, res) => {
try {
await Todo.findOneAndUpdate({ _id: req.body.todoIdFromJSFile }, {
completed: false
})
console.log('Marked Incomplete')
res.json('Marked Incomplete')
}catch(err){
} catch (err) {
console.log(err)
}
},
deleteTodo: async (req, res)=>{
deleteTodo: async (req, res) => {
console.log(req.body.todoIdFromJSFile)
try{
await Todo.findOneAndDelete({_id:req.body.todoIdFromJSFile})
try {
await Todo.findOneAndDelete({ _id: req.body.todoIdFromJSFile })
console.log('Deleted Todo')
res.json('Deleted It')
}catch(err){
} catch (err) {
console.log(err)
}
},
makePublicTodo: async (req, res) => {
console.log(req.body)
try {
await Todo.findByIdAndUpdate(req.body.todoIdFromJSFile,
{ public: true })
res.json('marked public')
}
catch (err) {
console.log(err)
}
},
getPublicTodos: async (req, res) => {
const todoItems = await Todo.find()
res.render('public.ejs', { todos: todoItems })
}
}

}
4 changes: 4 additions & 0 deletions models/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const TodoSchema = new mongoose.Schema({
completed: {
type: Boolean,
required: true,
},
public: {
type: Boolean,
default: false
}
})

Expand Down
7 changes: 7 additions & 0 deletions models/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const publicSchema = new Schema({
todo: { type: String }
})

module.exports = mongoose.model('Public', publicSchema)
Loading