#167 added week-data-start to router/tasks

parent dffb6345
......@@ -47,6 +47,7 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
.leftJoinAndSelect('member.user', 'user')
.where('project.id IN(:...projectIds)', {projectIds})
.getMany()
console.log('projects \n',projects)
return res.send({projects})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
......
......@@ -133,6 +133,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
id:userId
}},
})
console.log('tasks \n',tasks)
return res.send({tasks})
} catch(e){
return res.status(502).send({message:(e as Error).message})
......@@ -395,4 +396,68 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
})
/**router GET "/week-data-start/{userId}` which receives user through req.body.user,
* returns list of Task related to the userId,
* object with key displayName related to userId, list of Project related to user
*/
router.get('/week-data-start/:userId',auth, async (req: Request, res: Response):Promise<Response>=>{
const {userId} = req.params
try{
const requesterUser= req.body.user
const user = await dataSource
.getRepository(User)
.findOne({
relations:{
members:true
},
where:{
id:userId
}
})
if (!user) return res.status(404).send({Message:'user not found'})
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:true
},
where:{
members:{
user:{
id:requesterUser.id
}
}
}
})
if (!projects) return res.status(404).send({Message:'projects not found'})
const projectIds = projects.map(project=>{return project.id})
const tasks = await dataSource
.getRepository(Task)
.find({
relations:{
project:true,
},
where:{
project:{
id:In(projectIds)
}
}
})
const {displayName} = user
if (!tasks) return res.status(404).send({Message:'tasks not found'})
console.log('tasks: ',tasks, "projects" ,projects , 'displayName' ,displayName)
return res.send({displayName, projects, tasks})
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
})
export default router;
......@@ -51,6 +51,7 @@ return res.send({users})
.where("user.id = :userId", { userId })
.getOne()
if (!displayName) return res.status(404).send({message:'displayName not found'})
console.log('displayName \n',displayName)
return res.send(displayName)
} catch(e) {
return res.status(502).send({message:(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