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