#58 added get projects/id for project details

parent da9c76fa
...@@ -34,7 +34,7 @@ import { ...@@ -34,7 +34,7 @@ import {
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() }) @CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
createdAt!: Date; createdAt!: Date;
@ManyToOne(() => User, (user: { members: Member[]; }) => user.members,{cascade: true, onUpdate:'CASCADE'}) @ManyToOne(() => User, (user: { members: Member[]; }) => user.members,{cascade: true, onUpdate:'CASCADE',eager:true})
user!: User; user!: User;
@ManyToOne(() => Project, (project: { members: Member[]; }) => project.members,{cascade: true, onUpdate:'CASCADE',nullable:true}) @ManyToOne(() => Project, (project: { members: Member[]; }) => project.members,{cascade: true, onUpdate:'CASCADE',nullable:true})
......
...@@ -56,8 +56,8 @@ import { ...@@ -56,8 +56,8 @@ import {
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true}) // @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User; // admin!: User;
@OneToMany(() => Task, (task: { project: Project; })=>task.project) @OneToMany(() => Task, (task: { project: Project; })=>task.project,{nullable:true})
tasks!:Task[]|null; tasks!:Task[];
@OneToMany(() => Member, (member: { project: Project; })=>member.project) @OneToMany(() => Member, (member: { project: Project; })=>member.project)
members!:Member[]; members!:Member[];
......
...@@ -13,12 +13,25 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> { ...@@ -13,12 +13,25 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
return res.send({projects}) return res.send({projects})
}) })
router.get('/my',async (req:Request, res:Response): Promise<Response>=> {
const token = req.get('Authorization');
const user = await dataSource
.createQueryBuilder()
.select("user")
.from(User, "user")
.where("user.token = :token", { token: token })
.getOne();
if(!user) return res.status(404).send({Message:'user not found'})
const projects:Project[] = await dataSource.manager.find(Project)
return res.send({projects})
})
router.post('/', async (req:Request, res:Response): Promise<Response> => { router.post('/', async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'}) if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const token = req.get('Authorization'); const token = req.get('Authorization');
console.log("token:" + token) const {title,color}= req.body;
const {title, dateDue,color,department,workers,tasks}= req.body;
const user = await dataSource const user = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select("user") .select("user")
...@@ -34,10 +47,6 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => { ...@@ -34,10 +47,6 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
project.title = title; project.title = title;
project.color = color; project.color = color;
project.members=[member] project.members=[member]
// project.department = department;
// project.workers = workers|| null;
project.tasks = tasks || null;
// project.admin = user;
await project.save() await project.save()
return res.send({project}) return res.send({project})
}) })
...@@ -47,7 +56,9 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => { ...@@ -47,7 +56,9 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
.createQueryBuilder() .createQueryBuilder()
.select("project") .select("project")
.from(Project, "project") .from(Project, "project")
.leftJoinAndSelect('project.admin', 'user') .leftJoinAndSelect('project.members', 'member')
.leftJoinAndSelect('member.user', 'user' )
.leftJoinAndSelect('project.tasks','task')
.where("project.id = :id", { id: req.params.id }) .where("project.id = :id", { id: req.params.id })
.getOne() .getOne()
if (!project) return res.status(404).send({Message:'no info on this project'}) if (!project) return res.status(404).send({Message:'no info on this project'})
......
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