-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4b1375e
Showing
19 changed files
with
5,591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Todo app | ||
|
||
This project contains a simple todo application | ||
|
||
It has following features- | ||
Anyone can create a todo | ||
Anyone can see their existing todos | ||
Anyone can mark a todo as done | ||
|
||
// initialize a node project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const mongoose = require("mongoose"); | ||
const { boolean } = require("zod"); | ||
|
||
mongoose.connect("mongodb://localhost:27017/Todo-app"); | ||
//changer this to your mongoDb link to get connected to your database | ||
|
||
const todoSchema = mongoose.Schema({ | ||
title : String, | ||
description : String, | ||
completed : Boolean, | ||
}) | ||
|
||
const todo = mongoose.model('todos',todoSchema); | ||
|
||
module.exports={ | ||
todo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const express = require("express"); | ||
const {createTodo,updateTodo} = require("./types"); | ||
const app = express(); | ||
const cors = require('cors'); | ||
const {todo} = require("./db") | ||
|
||
app.use(express.json()); | ||
app.use(cors()); | ||
app.post("/todo", async function(req,res){ | ||
const createPayload = req.body; | ||
const parsedPayload = createTodo.safeParse(createPayload); | ||
if(!parsedPayload.success){ | ||
res.status(411).json({ | ||
msg : "You sent the wrong inputs", | ||
}) | ||
return; | ||
} | ||
await todo.create ({ | ||
title : createPayload.title, | ||
description : createPayload.description, | ||
completed : false | ||
}) | ||
res.json({ | ||
msg : "Todo created" | ||
}) | ||
}) | ||
app.get("/todo",async function(req,res){ | ||
const todos =await todo.find({}); | ||
|
||
res.json({ | ||
todos | ||
}) | ||
}) | ||
app.put("/completed",async function(req,res){ | ||
const updatePayload = req.body; | ||
const parsedPayload = createTodo.safeParse(updatePayloadPayload); | ||
if(!parsedPayload.success){ | ||
res.status(411).json({ | ||
msg : "You sent the wrong inputs", | ||
}) | ||
return; | ||
} | ||
await todo.update({ | ||
_id : req.body._id | ||
},{ | ||
completed : true | ||
}) | ||
res.json({ | ||
msg : "To marked as completed" | ||
}) | ||
}) | ||
|
||
app.listen(3000); |
Oops, something went wrong.