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
1d73c96f
Commit
1d73c96f
authored
Nov 22, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58
added get projects/id for project details
parent
da9c76fa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
10 deletions
+21
-10
Member.ts
planner-api/src/models/Member.ts
+1
-1
Project.ts
planner-api/src/models/Project.ts
+2
-2
projects.ts
planner-api/src/routers/projects.ts
+18
-7
No files found.
planner-api/src/models/Member.ts
View file @
1d73c96f
...
@@ -34,7 +34,7 @@ import {
...
@@ -34,7 +34,7 @@ import {
@
CreateDateColumn
({
name
:
'createdAt'
,
type
:
Date
,
default
:
new
Date
()
})
@
CreateDateColumn
({
name
:
'createdAt'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
createdAt
!
:
Date
;
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
})
@
ManyToOne
(()
=>
User
,
(
user
:
{
members
:
Member
[];
})
=>
user
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
eager
:
true
})
user
!
:
User
;
user
!
:
User
;
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
nullable
:
true
})
@
ManyToOne
(()
=>
Project
,
(
project
:
{
members
:
Member
[];
})
=>
project
.
members
,{
cascade
:
true
,
onUpdate
:
'CASCADE'
,
nullable
:
true
})
...
...
planner-api/src/models/Project.ts
View file @
1d73c96f
...
@@ -56,8 +56,8 @@ import {
...
@@ -56,8 +56,8 @@ import {
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User;
// admin!: User;
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
)
@
OneToMany
(()
=>
Task
,
(
task
:
{
project
:
Project
;
})
=>
task
.
project
,{
nullable
:
true
}
)
tasks
!
:
Task
[]
|
null
;
tasks
!
:
Task
[];
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
@
OneToMany
(()
=>
Member
,
(
member
:
{
project
:
Project
;
})
=>
member
.
project
)
members
!
:
Member
[];
members
!
:
Member
[];
...
...
planner-api/src/routers/projects.ts
View file @
1d73c96f
...
@@ -13,12 +13,25 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
...
@@ -13,12 +13,25 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
return
res
.
send
({
projects
})
return
res
.
send
({
projects
})
})
})
router
.
get
(
'/my'
,
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
projects
:
Project
[]
=
await
dataSource
.
manager
.
find
(
Project
)
return
res
.
send
({
projects
})
})
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
if
(
!
req
.
body
)
return
res
.
status
(
400
).
send
({
Message
:
'problem in incoming req.body'
})
if
(
!
req
.
body
)
return
res
.
status
(
400
).
send
({
Message
:
'problem in incoming req.body'
})
const
token
=
req
.
get
(
'Authorization'
);
const
token
=
req
.
get
(
'Authorization'
);
console
.
log
(
"token:"
+
token
)
const
{
title
,
color
}
=
req
.
body
;
const
{
title
,
dateDue
,
color
,
department
,
workers
,
tasks
}
=
req
.
body
;
const
user
=
await
dataSource
const
user
=
await
dataSource
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"user"
)
.
select
(
"user"
)
...
@@ -34,10 +47,6 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
...
@@ -34,10 +47,6 @@ router.post('/', async (req:Request, res:Response): Promise<Response> => {
project
.
title
=
title
;
project
.
title
=
title
;
project
.
color
=
color
;
project
.
color
=
color
;
project
.
members
=
[
member
]
project
.
members
=
[
member
]
// project.department = department;
// project.workers = workers|| null;
project
.
tasks
=
tasks
||
null
;
// project.admin = user;
await
project
.
save
()
await
project
.
save
()
return
res
.
send
({
project
})
return
res
.
send
({
project
})
})
})
...
@@ -47,7 +56,9 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
...
@@ -47,7 +56,9 @@ router.get("/:id",async (req:Request, res:Response): Promise<Response> => {
.
createQueryBuilder
()
.
createQueryBuilder
()
.
select
(
"project"
)
.
select
(
"project"
)
.
from
(
Project
,
"project"
)
.
from
(
Project
,
"project"
)
.
leftJoinAndSelect
(
'project.admin'
,
'user'
)
.
leftJoinAndSelect
(
'project.members'
,
'member'
)
.
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'
})
...
...
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