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
e7982023
Commit
e7982023
authored
Nov 22, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58
tasks/user/:userId resolved
parent
21d8af09
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
47 deletions
+63
-47
projects.ts
planner-api/src/routers/projects.ts
+20
-3
tasks.ts
planner-api/src/routers/tasks.ts
+43
-44
No files found.
planner-api/src/routers/projects.ts
View file @
e7982023
...
@@ -3,6 +3,9 @@ import {Project} from '../models/Project';
...
@@ -3,6 +3,9 @@ import {Project} from '../models/Project';
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
User
}
from
'../models/User'
;
import
{
User
}
from
'../models/User'
;
import
{
Member
,
MemberRole
}
from
'../models/Member'
;
import
{
Member
,
MemberRole
}
from
'../models/Member'
;
import
{
userInfo
}
from
'os'
;
import
{
Task
}
from
'../models/Task'
;
import
{
getRepository
}
from
'typeorm'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -58,14 +61,28 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
...
@@ -58,14 +61,28 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
.
from
(
Project
,
"project"
)
.
from
(
Project
,
"project"
)
.
leftJoinAndSelect
(
'project.members'
,
'member'
)
.
leftJoinAndSelect
(
'project.members'
,
'member'
)
.
leftJoinAndSelect
(
'member.user'
,
'user'
)
.
leftJoinAndSelect
(
'member.user'
,
'user'
)
.
leftJoinAndSelect
(
'project.tasks'
,
'task'
)
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
id
})
.
where
(
"project.id = :id"
,
{
id
:
req
.
params
.
id
})
.
getOne
()
.
getOne
()
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no info on this project'
})
if
(
!
project
)
return
res
.
status
(
404
).
send
({
Message
:
'no info on this project'
})
return
res
.
send
({
project
})
const
tasks
=
await
dataSource
.
getRepository
(
'Task'
)
.
find
(
{
relations
:{
executor
:
true
,
author
:
true
,
},
where
:{
project
:{
id
:
req
.
params
.
id
}
}
}
)
return
res
.
send
({
project
,
tasks
})
})
})
router
.
get
(
'/userId/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
userId
:
string
=
req
.
params
.
userId
const
userId
:
string
=
req
.
params
.
userId
const
userProjects
=
await
dataSource
const
userProjects
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
...
...
planner-api/src/routers/tasks.ts
View file @
e7982023
...
@@ -2,8 +2,6 @@ import express,{Router, Request, Response} from 'express';
...
@@ -2,8 +2,6 @@ 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'
;
import
{
Member
}
from
'../models/Member'
;
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
...
@@ -11,14 +9,18 @@ const dataSource = myDataSource;
...
@@ -11,14 +9,18 @@ const dataSource = myDataSource;
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
find
()
.
find
({
relations
:{
executor
:
true
,
author
:
true
,
}})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
const
newTask
=
new
Task
();
const
newTask
=
new
Task
();
const
{
title
,
description
,
project
,
executors
,
dateTimeDue
,
dateTimeStart
,
accomplish
,
priority
}
=
req
.
body
;
const
{
title
,
description
,
project
,
dateTimeDue
,
dateTimeStart
,
accomplish
,
priority
}
=
req
.
body
;
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"user"
)
.
select
(
"user"
)
...
@@ -29,7 +31,6 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -29,7 +31,6 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
newTask
.
title
=
title
;
newTask
.
title
=
title
;
newTask
.
description
=
description
;
newTask
.
description
=
description
;
newTask
.
project
=
project
;
newTask
.
project
=
project
;
// newTask.executors = executors;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeDue
=
dateTimeDue
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
dateTimeStart
=
dateTimeStart
;
newTask
.
author
=
user
;
newTask
.
author
=
user
;
...
@@ -41,22 +42,26 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
...
@@ -41,22 +42,26 @@ router.post('/', async(req:Request, res:Response):Promise<Response>=>{
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
router
.
get
(
'/user/:userId'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
const
userId
=
req
.
params
.
userId
;
const
userId
=
req
.
params
.
userId
;
// const tasks = await dataSource
// .getRepository(Task)
// .createQueryBuilder('task')
// .innerJoinAndSelect('task.executors', 'user')
// .where('user.id = :userId', {userId :userId})
// .getMany()
// return res.send({tasks})
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Member
)
.
getRepository
(
Task
)
.
createQueryBuilder
(
'member'
)
.
find
({
.
innerJoinAndSelect
(
'member.project'
,
'project'
)
relations
:{
.
innerJoinAndSelect
(
'project.tasks'
,
'task'
)
executor
:
true
,
.
where
(
'member.user.id = :userId'
)
author
:
true
,
.
andWhere
(
'member.project.id= task.project.id'
)
},
.
select
(
'task.*'
)
where
:[
.
getMany
()
{
executor
:{
id
:
userId
}
},
{
author
:{
id
:
userId
}
},
]
})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
...
@@ -71,10 +76,24 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
...
@@ -71,10 +76,24 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
tasks
=
await
dataSource
const
tasks
=
await
dataSource
.
getRepository
(
Task
)
.
getRepository
(
Task
)
.
createQueryBuilder
(
'task'
)
.
find
({
.
innerJoinAndSelect
(
'task.executors'
,
'user'
)
relations
:{
.
where
(
'user.id = :userId'
,
{
userId
:
user
.
id
})
executor
:
true
,
.
getMany
()
author
:
true
,
},
where
:[
{
executor
:{
id
:
user
.
id
}
},
{
author
:{
id
:
user
.
id
}
},
]
})
return
res
.
send
({
tasks
})
return
res
.
send
({
tasks
})
})
})
...
@@ -152,24 +171,4 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
...
@@ -152,24 +171,4 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
// router.post('/projects',async (req: Request, res: Response):Promise<Response>=>{
// let projectArray :string[]= req.body;
// console.log('projectArray ', projectArray)
// if (projectArray.length===0) {
// const tasks = await
// dataSource
// .getRepository(Task)
// .createQueryBuilder('task')
// // .innerJoinAndSelect('task.executors', 'user')
// .innerJoinAndSelect('task.executors AND task.author', 'user')
// .where('task.project IS NULL')
// .getMany()
// return res.send({tasks})
// }
// ///ssome code
// return res.send({message:"some other staff"})
// })
export
default
router
;
export
default
router
;
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