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
53e17d6e
Commit
53e17d6e
authored
Nov 24, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#63
added router/tasks/related adress
parent
99d6d937
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
+57
-5
fixtures.ts
planner-api/src/fixtures.ts
+0
-4
tasks.ts
planner-api/src/routers/tasks.ts
+57
-1
No files found.
planner-api/src/fixtures.ts
View file @
53e17d6e
...
@@ -68,8 +68,6 @@ const loadFixtures = async () => {
...
@@ -68,8 +68,6 @@ const loadFixtures = async () => {
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
title
=
`Buy
${
faker
.
commerce
.
productName
()}
`
;
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
description
=
faker
.
random
.
words
(
4
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
executor
=
faker
.
helpers
.
arrayElement
(
users
);
// newTask.dateTimeDue = null;
// newTask.dateTimeStart = null;
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
author
=
faker
.
helpers
.
arrayElement
(
users
);
newTask
.
accomplish
=
accomplish
[
0
];
newTask
.
accomplish
=
accomplish
[
0
];
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
newTask
.
priority
=
faker
.
helpers
.
arrayElement
(
priorities
);
...
@@ -93,9 +91,7 @@ const loadFixtures = async () => {
...
@@ -93,9 +91,7 @@ const loadFixtures = async () => {
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
=
faker
.
helpers
.
arrayElements
(
members
,
randomIntFromInterval
(
1
,
3
))
newProject
.
members
=
faker
.
helpers
.
arrayElements
(
members
,
randomIntFromInterval
(
1
,
3
))
// newProject.admin = faker.helpers.arrayElement(users);
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
1
,
3
));
newProject
.
tasks
=
faker
.
helpers
.
arrayElements
(
tasks
,
randomIntFromInterval
(
1
,
3
));
// newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));
await
newProject
.
save
();
await
newProject
.
save
();
projects
.
push
(
newProject
)
projects
.
push
(
newProject
)
}
}
...
...
planner-api/src/routers/tasks.ts
View file @
53e17d6e
...
@@ -2,6 +2,8 @@ import express,{Router, Request, Response} from 'express';
...
@@ -2,6 +2,8 @@ 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
{
Member
}
from
'../models/Member'
;
import
{
In
}
from
'typeorm'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -97,6 +99,61 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
...
@@ -97,6 +99,61 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
router
.
get
(
'/related'
,
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
rawMembership
=
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
})
.
getMany
()
let
projectIds
:
any
[]
=
[]
if
(
rawMembership
.
length
>
0
){
for
(
let
member
of
rawMembership
){
const
projectId
=
member
?.
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
})
}
if
(
projectIds
.
length
>
0
){
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
find
({
relations
:{
author
:
true
,
executor
:
true
,
project
:
true
},
where
:{
project
:
{
id
:
In
(
projectsIdArray
)}
}
})
}
return
res
.
send
({
tasks
})
})
router
.
delete
(
'/:taskId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
delete
(
'/:taskId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
taskId
=
req
.
params
.
taskId
;
const
taskId
=
req
.
params
.
taskId
;
await
myDataSource
await
myDataSource
...
@@ -144,7 +201,6 @@ router.put('/',async(req:Request, res:Response)=> {
...
@@ -144,7 +201,6 @@ router.put('/',async(req:Request, res:Response)=> {
router
.
post
(
'/project'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
post
(
'/project'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
let
projectArray
:
string
[]
=
req
.
body
;
let
projectArray
:
string
[]
=
req
.
body
;
console
.
log
(
'projectArray '
,
projectArray
)
if
(
projectArray
.
length
===
0
)
{
if
(
projectArray
.
length
===
0
)
{
const
rawTasks
=
await
const
rawTasks
=
await
dataSource
dataSource
...
...
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