#69 optimize tasks/related & fix fixtures

parent 9224cf77
......@@ -113,7 +113,7 @@ const loadFixtures = async () => {
}
const members:Member[]=[]
for (let i = 0; i <3; i++) {
for (let i = 0; i <5; i++) {
const newMember = new Member();
newMember.user = faker.helpers.arrayElement(users);
newMember.roleProject=cycleThroughObject(countRolesProject, MemberRole);
......@@ -126,7 +126,7 @@ const loadFixtures = async () => {
const newProject = new Project();
newProject.title = `Project ${faker.random.words(1)}`;
newProject.color = faker.random.words(1);
newProject.members = [cycleArrayOfMembers(countMembers,members), cycleArrayOfMembers(countMembers,members),cycleArrayOfMembers(countMembers,members)]
newProject.members = faker.helpers.arrayElements(members, 3);
newProject.tasks= faker.helpers.arrayElements(tasks, randomIntFromInterval(2, 19));
await newProject.save();
projects.push(newProject)
......
......@@ -95,47 +95,45 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
/**check tasks of projects in which current user is involved, search by token*/
router.get('/related', auth,async (req: Request, res: Response):Promise<Response>=>{
console.log('related')
const user = req.body.user
const rawMembership = await dataSource
const tasks = await dataSource
.createQueryBuilder()
.select("member")
.from(Member, "member")
.leftJoinAndSelect('member.user', 'user' )
.leftJoinAndSelect('member.project', 'project' )
.leftJoinAndSelect('project.tasks', 'task' )
.where("member.userId = :id", { id: user.id })
.select(["task"])
.from(Task,"task")
.leftJoinAndSelect("task.executor","user")
.leftJoinAndSelect("task.dateTimeTasks","dateTimeTask")
.leftJoinAndSelect("task.author","users")
.leftJoinAndSelect("task.project","project")
.leftJoinAndSelect("project.members", "member")
.where("member.userId = :userId", {userId:user.id})
.getMany()
let projectIds:any[] = []
if (rawMembership.length>0){
for (let member of rawMembership){
const projectId = member?.project?.id
if (tasks.length>0){
for (let task of tasks){
const projectId = task?.project?.id
projectIds.push(projectId)
}
}
let tasks :Task[]= []
const projectsIdArray = [...new Set(projectIds)];
const searchByProjectsIdArray:object[] = []
for (let projectId of projectsIdArray){
searchByProjectsIdArray.push({id:projectId})
}
let users:User[]=[]
if (projectIds.length>0){
tasks = await dataSource
.getRepository(Task)
users = await dataSource
.getRepository(User)
.find({
relations:{
author:true,
executor:true,
project:true
members:true,
},
where:{
project:
{id:In(
members:
{project:In(
projectsIdArray
)}
}
})
}
return res.send({tasks})
return res.send({tasks, users})
})
......
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