#58 added get projects/id for project details

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