#167 remove unused requests to db in routers/tasks.ts

parent ac8ddb62
......@@ -40,23 +40,6 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
newTask.title = title;
newTask.description = description;
if (project) {
const watcherOfProject = await dataSource
.getRepository(Project)
.findOne({
relations:{
members:true,
},
where:
{
id:project.id,
members:
{
user:{id:user.id},
roleProject:MemberRole.WATCHER,
},
}
})
if (watcherOfProject) return res.send({message:"watcher could nt make tasks"})
newTask.project = project;
} else {
const personalProject = await dataSource
......@@ -71,14 +54,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
})
if (personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
newTask.executor=user;
} else {
newTask.executor= executor;
}
newTask.project.title==="Личные дела"? newTask.executor=user: newTask.executor= executor;
newTask.priority = priority;
await newTask.save();
if (calendar) {
......@@ -104,23 +82,6 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
newTask.title = title;
newTask.description = description;
if (project) {
const watcherOfProject = await dataSource
.getRepository(Project)
.findOne({
relations:{
members:true,
},
where:
{
id:project.id,
members:
{
user:{id:user.id},
roleProject:MemberRole.WATCHER,
},
}
})
if (watcherOfProject) return res.send({message:"watcher could nt make tasks"})
newTask.project = project;
} else {
const personalProject = await dataSource
......@@ -396,19 +357,15 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
tasks:{
author:true,
executor:true
}
},
}},
where:{
members:{
roleProject:Not(Equal(MemberRole.WATCHER)),
user:{
id:user.id
},
project:{
title:Not(Equal("Личные дела"))
}
}
}})
}}}})
if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'})
let tasks:Task[] = []
......@@ -416,10 +373,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
for (const project of projectsWithTasks){
if (project?.tasks) {
tasks=tasks.concat(project.tasks)
}
}
}
}}}
const projectIds= projectsWithTasks.map(project=> {return project.id})
const projects = await dataSource
.getRepository(Project)
......@@ -432,9 +386,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
id:In(projectIds),
members:{
roleProject: Not(MemberRole.WATCHER)
}
},
})
}},})
return res.send({projects, tasks})
} catch(e){
console.log('Error: ',(e as Error).message);
......
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