#166 remove some rows and eddit a little create task router

parent f986cafc
......@@ -11,7 +11,6 @@ import { Project } from '../models/Project';
const router:Router = express.Router();
const dataSource = myDataSource;
/**get all tasks */
router.get('/', async(req:Request, res:Response):Promise<Response> => {
try{
......@@ -33,13 +32,9 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
try{
const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority, calendar} = req.body;
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
const dateTimeDeadlineFinal= dateTimeDeadLine
if (!dateTimeDue && dateTimeDeadLine) {
dateTimeDueFinal = dateTimeDeadLine
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
}
let dateTimeDueFinal = dateTimeDue ?? dateTimeDeadLine;
let dateTimeStartFinal = dateTimeStart ?? subtractHours(dateTimeDueFinal, 1);
const newTask = new Task();
newTask.title = title;
......@@ -74,22 +69,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
title:"Личные дела"
}
})
if(personalProject){
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Личные дела";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
if (personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
......@@ -151,20 +133,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
title:"Не определено"
}
})
if(personalProject){
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Не определено";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
if(personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine=dateTimeDeadLine;
......@@ -201,8 +170,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
{
executor:{
id:userId
}
},
}},
})
return res.send({tasks})
} catch(e){
......@@ -229,9 +197,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
id: user.id
},
roleProject:Not(MemberRole.WATCHER)
}
}
}
}}}
)
const projectsList= projectsRawId.map(project=> {return project.id})
......@@ -249,9 +215,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
},
project:{
id:In(projectsList)
}
}
}
}}}
)
const projects = await dataSource
.getRepository(Project)
......@@ -261,8 +225,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
},
where:{
id:In(projectsList)
}
})
}})
return res.send({tasks, projects})
} catch(e){
return res.status(502).send({message:(e as Error).message})
......@@ -306,9 +269,7 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response
members:
{project:In(
projectsIdArray
)}
}
})
)}}})
}
return res.send({tasks, users})
} catch(e){
......@@ -423,7 +384,6 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
})
/**check other users tasks that are related to the user through common projects, by user token*/
router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{
const {user} = req.body
......
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