#51 added post tasks/project

parent 1ba82002
...@@ -2,6 +2,7 @@ import express,{Router, Request, Response} from 'express'; ...@@ -2,6 +2,7 @@ import express,{Router, Request, Response} from 'express';
import {Task} from '../models/Task'; import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source'; import {myDataSource} from '../app-data-source';
import { User } from '../models/User'; import { User } from '../models/User';
import { Project } from '../models/Project';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -111,4 +112,32 @@ router.put('/',async(req:Request, res:Response)=> { ...@@ -111,4 +112,32 @@ router.put('/',async(req:Request, res:Response)=> {
}) })
router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
let projectArray :string[]= req.body;
console.log('projectArray ', projectArray)
if (projectArray.length===0) {
const rawTasks = await
dataSource
.getRepository(Task)
.find({
relations:{
executors:true,
author:true,
project:true
}
})
const tasks:object[]= rawTasks.filter(task=>task.project===null)
return res.send({tasks})
}
const tasks = await
dataSource
.getRepository(Task)
.createQueryBuilder('task')
.innerJoinAndSelect( 'task.project', 'project')
.where('task.project IN(:...projects)', {projects:projectArray})
.getMany()
return res.send({tasks})
})
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