Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
daac8395
Commit
daac8395
authored
Nov 28, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#69
optimize tasks/related & fix fixtures
parent
9224cf77
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
25 deletions
+23
-25
fixtures.ts
planner-api/src/fixtures.ts
+2
-2
tasks.ts
planner-api/src/routers/tasks.ts
+21
-23
No files found.
planner-api/src/fixtures.ts
View file @
daac8395
...
@@ -113,7 +113,7 @@ const loadFixtures = async () => {
...
@@ -113,7 +113,7 @@ const loadFixtures = async () => {
}
}
const
members
:
Member
[]
=
[]
const
members
:
Member
[]
=
[]
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
const
newMember
=
new
Member
();
const
newMember
=
new
Member
();
newMember
.
user
=
faker
.
helpers
.
arrayElement
(
users
);
newMember
.
user
=
faker
.
helpers
.
arrayElement
(
users
);
newMember
.
roleProject
=
cycleThroughObject
(
countRolesProject
,
MemberRole
);
newMember
.
roleProject
=
cycleThroughObject
(
countRolesProject
,
MemberRole
);
...
@@ -126,7 +126,7 @@ const loadFixtures = async () => {
...
@@ -126,7 +126,7 @@ const loadFixtures = async () => {
const
newProject
=
new
Project
();
const
newProject
=
new
Project
();
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
title
=
`Project
${
faker
.
random
.
words
(
1
)}
`
;
newProject
.
color
=
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
));
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
2
,
19
));
await
newProject
.
save
();
await
newProject
.
save
();
projects
.
push
(
newProject
)
projects
.
push
(
newProject
)
...
...
planner-api/src/routers/tasks.ts
View file @
daac8395
...
@@ -95,47 +95,45 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
...
@@ -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*/
/**check tasks of projects in which current user is involved, search by token*/
router
.
get
(
'/related'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/related'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
console
.
log
(
'related'
)
const
user
=
req
.
body
.
user
const
user
=
req
.
body
.
user
const
rawMembership
=
await
dataSource
const
tasks
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"member"
)
.
select
([
"task"
])
.
from
(
Member
,
"member"
)
.
from
(
Task
,
"task"
)
.
leftJoinAndSelect
(
'member.user'
,
'user'
)
.
leftJoinAndSelect
(
"task.executor"
,
"user"
)
.
leftJoinAndSelect
(
'member.project'
,
'project'
)
.
leftJoinAndSelect
(
"task.dateTimeTasks"
,
"dateTimeTask"
)
.
leftJoinAndSelect
(
'project.tasks'
,
'task'
)
.
leftJoinAndSelect
(
"task.author"
,
"users"
)
.
where
(
"member.userId = :id"
,
{
id
:
user
.
id
})
.
leftJoinAndSelect
(
"task.project"
,
"project"
)
.
leftJoinAndSelect
(
"project.members"
,
"member"
)
.
where
(
"member.userId = :userId"
,
{
userId
:
user
.
id
})
.
getMany
()
.
getMany
()
let
projectIds
:
any
[]
=
[]
let
projectIds
:
any
[]
=
[]
if
(
rawMembership
.
length
>
0
){
if
(
tasks
.
length
>
0
){
for
(
let
member
of
rawMembership
){
for
(
let
task
of
tasks
){
const
projectId
=
member
?.
project
?.
id
const
projectId
=
task
?.
project
?.
id
projectIds
.
push
(
projectId
)
projectIds
.
push
(
projectId
)
}
}
}
}
let
tasks
:
Task
[]
=
[]
const
projectsIdArray
=
[...
new
Set
(
projectIds
)];
const
projectsIdArray
=
[...
new
Set
(
projectIds
)];
const
searchByProjectsIdArray
:
object
[]
=
[]
let
users
:
User
[]
=
[]
for
(
let
projectId
of
projectsIdArray
){
searchByProjectsIdArray
.
push
({
id
:
projectId
})
}
if
(
projectIds
.
length
>
0
){
if
(
projectIds
.
length
>
0
){
task
s
=
await
dataSource
user
s
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
User
)
.
find
({
.
find
({
relations
:{
relations
:{
author
:
true
,
members
:
true
,
executor
:
true
,
project
:
true
},
},
where
:{
where
:{
project
:
members
:
{
id
:
In
(
{
project
:
In
(
projectsIdArray
projectsIdArray
)}
)}
}
}
})
})
}
}
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
,
users
})
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment