Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
saikrishnacreat authored Apr 15, 2024
0 parents commit 4b1375e
Show file tree
Hide file tree
Showing 19 changed files with 5,591 additions and 0 deletions.
10 changes: 10 additions & 0 deletions todo-react/README.md
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
17 changes: 17 additions & 0 deletions todo-react/backend/db.js
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
}
53 changes: 53 additions & 0 deletions todo-react/backend/index.js
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);
Loading

0 comments on commit 4b1375e

Please sign in to comment.