Proof of concept of a kanban style application.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.6 KiB
Raw

const express=require("express");
const { findAllTask, findTaskById, addTask, updateTask, deleteTask } = require("../controller/TaskController");
const router=express.Router();
const Model=require('../model/Task');
router.get("/", (req, res) =>{
findAllTask().then((value)=>{
res.status(200).send(value);
}).catch((reason)=>{
res.status(500).send(reason);
});
});
router.get("/:id", (req, res) =>{
findTaskById(req.params.id).then((value)=>{
res.status(200).send(value);
}).catch((reason)=>{
res.status(500).send(reason);
});
});
router.post("/", (req, res) =>{
//Delete parent if set to ""
if(req.body.parent===""){
delete req.body.parent;
}
try{
addTask(req.body).then((value)=>{
res.status(200).send(value);
}).catch((reason)=>{
res.status(500).send(reason);
});
}catch(error){
res.status(500).send(error);
}
});
router.put("/:id",(req,res)=>{
//Delete parent if set to ""
if(req.body.parent===""){
delete req.body.parent;
req.body=Object.assign(req.body, {$unset:{parent:1}});
}
updateTask(req.params.id,req.body)
.then((value)=>
{
if(value===null){
res.status(500).send("No changes, invalid id ?");
}else{
res.status(200).send(value);
}
},(reason)=>{
res.status(500).send(reason.toString());
})
.catch((reason)=>{
res.status(500).send(reason);
});
});
router.delete("/:id", (req, res) =>{
deleteTask(req.params.id).then((value)=>{
if(value===null){
res.status(500).send("No changes, invalid id ?");
}else{
res.status(200).send(value);
}
}).catch((reason)=>{
res.status(500).send(reason);
});
});
module.exports=router;