Commit 9c90a525 authored by “Yevgeniy's avatar “Yevgeniy

#25 added admin in request of one porject by id

parent eec5934c
......@@ -59,7 +59,7 @@ import {
dateDue!: Date| null;
@Column({ name: 'department', type: Boolean,nullable:true ,default: false})
department!: boolean | false;
department!: boolean;
@ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects)
admin!: User;
......
......@@ -12,11 +12,18 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
return res.send({projects})
})
router.get("/:project_id",async (req:Request, res:Response): Promise<Response> => {
const project : Project|null= await dataSource.manager.findOneBy(Project, {
id: req.params.project_id
})
if (!project) return res.status(404).send({Message:'no info in the base'})
router.get("/project_id/:project_id",async (req:Request, res:Response): Promise<Response> => {
const project = await dataSource
.createQueryBuilder()
.select("project")
.from(Project, "project")
// .where("user.workerInProjects= :projects", {projects.id : req.params.project_id } )
// .innerJoinAndSelect('project.workers','user')
.leftJoinAndSelect('project.admin','user')
.where("project.id = :id", { id: req.params.project_id })
.getOne()
if (!project) return res.status(404).send({Message:'no such project in the base'})
return res.send({project})
})
......@@ -43,21 +50,21 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
})
// router.get('/:userId', async (req : Request, res : Response): Promise<Response>=>{
// const userId:string = req.params.userId
// const user = await dataSource
// .createQueryBuilder()
// .select("user")
// .from(User, "user")
// .where("user.id = :id", { id: userId })
// .getOne()
// console.log('user ', user)
// const userProjects = await dataSource
// .createQueryBuilder()
// .select('project')
// .from(Project, "project")
// .where("Project_adminId = :id", { id: userId })
// return res.send({userProjects})
// })
router.get('/:userId', async (req : Request, res : Response): Promise<Response>=>{
const userId:string = req.params.userId
const user = await dataSource
.createQueryBuilder()
.select("user")
.from(User, "user")
.where("user.id = :id", { id: userId })
.getOne()
console.log('user ', user)
const userProjects = await dataSource
.createQueryBuilder()
.select('project')
.from(Project, "project")
.where("Project_adminId = :id", { id: userId })
return res.send({userProjects})
})
export default router;
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