#166 remove some rows and eddit a little create task router

parent f986cafc
...@@ -11,7 +11,6 @@ import { Project } from '../models/Project'; ...@@ -11,7 +11,6 @@ import { Project } from '../models/Project';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
/**get all tasks */ /**get all tasks */
router.get('/', async(req:Request, res:Response):Promise<Response> => { router.get('/', async(req:Request, res:Response):Promise<Response> => {
try{ try{
...@@ -33,13 +32,9 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => { ...@@ -33,13 +32,9 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
try{ try{
const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority, calendar} = req.body; const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority, calendar} = req.body;
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
const dateTimeDeadlineFinal= dateTimeDeadLine const dateTimeDeadlineFinal= dateTimeDeadLine
if (!dateTimeDue && dateTimeDeadLine) { let dateTimeDueFinal = dateTimeDue ?? dateTimeDeadLine;
dateTimeDueFinal = dateTimeDeadLine let dateTimeStartFinal = dateTimeStart ?? subtractHours(dateTimeDueFinal, 1);
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
}
const newTask = new Task(); const newTask = new Task();
newTask.title = title; newTask.title = title;
...@@ -74,22 +69,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -74,22 +69,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
title:"Личные дела" title:"Личные дела"
} }
}) })
if(personalProject){ if (personalProject) newTask.project = personalProject;
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Личные дела";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
} }
newTask.dateTimeDeadLine= dateTimeDeadlineFinal; newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user; newTask.author= user;
if(newTask.project.title==="Личные дела"){ if(newTask.project.title==="Личные дела"){
...@@ -151,20 +133,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=> ...@@ -151,20 +133,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
title:"Не определено" title:"Не определено"
} }
}) })
if(personalProject){ if(personalProject) newTask.project = personalProject;
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Не определено";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
} }
newTask.dateTimeDeadLine=dateTimeDeadLine; newTask.dateTimeDeadLine=dateTimeDeadLine;
...@@ -201,8 +170,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -201,8 +170,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
{ {
executor:{ executor:{
id:userId id:userId
} }},
},
}) })
return res.send({tasks}) return res.send({tasks})
} catch(e){ } catch(e){
...@@ -229,9 +197,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ ...@@ -229,9 +197,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
id: user.id id: user.id
}, },
roleProject:Not(MemberRole.WATCHER) roleProject:Not(MemberRole.WATCHER)
} }}}
}
}
) )
const projectsList= projectsRawId.map(project=> {return project.id}) const projectsList= projectsRawId.map(project=> {return project.id})
...@@ -249,9 +215,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ ...@@ -249,9 +215,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
}, },
project:{ project:{
id:In(projectsList) id:In(projectsList)
} }}}
}
}
) )
const projects = await dataSource const projects = await dataSource
.getRepository(Project) .getRepository(Project)
...@@ -261,8 +225,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ ...@@ -261,8 +225,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
}, },
where:{ where:{
id:In(projectsList) id:In(projectsList)
} }})
})
return res.send({tasks, projects}) return res.send({tasks, projects})
} catch(e){ } catch(e){
return res.status(502).send({message:(e as Error).message}) return res.status(502).send({message:(e as Error).message})
...@@ -306,9 +269,7 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response ...@@ -306,9 +269,7 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response
members: members:
{project:In( {project:In(
projectsIdArray projectsIdArray
)} )}}})
}
})
} }
return res.send({tasks, users}) return res.send({tasks, users})
} catch(e){ } catch(e){
...@@ -423,7 +384,6 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{ ...@@ -423,7 +384,6 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
}) })
/**check other users tasks that are related to the user through common projects, by user token*/ /**check other users tasks that are related to the user through common projects, by user token*/
router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{
const {user} = req.body const {user} = req.body
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment