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
e3590830
Commit
e3590830
authored
Jan 10, 2023
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#136
adding try catch and check title on project creation
parent
6b05046c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
11 deletions
+34
-11
fixtures.ts
planner-api/src/fixtures.ts
+2
-0
projects.ts
planner-api/src/routers/projects.ts
+32
-11
No files found.
planner-api/src/fixtures.ts
View file @
e3590830
...
...
@@ -71,6 +71,7 @@ const loadFixtures = async () => {
user
.
role
=
userRoles
[
i
].
role
;
user
.
generateToken
()
await
user
.
save
();
// начало: создание проектов "Личные дела" и "Не определелено" новому юзеру
const
newProject
=
new
Project
();
newProject
.
title
=
'Личные дела'
;
newProject
.
color
=
'#f595ee'
;
...
...
@@ -89,6 +90,7 @@ const loadFixtures = async () => {
notDefinedTaskProjectMember
.
project
=
notDefinedTaskProject
;
notDefinedTaskProjectMember
.
roleProject
=
MemberRole
.
ADMIN
;
await
notDefinedTaskProjectMember
.
save
();
// конец
users
.
push
(
user
)
}
...
...
planner-api/src/routers/projects.ts
View file @
e3590830
...
...
@@ -49,9 +49,26 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
/**create new project */
router
.
post
(
'/'
,
auth
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
if
(
!
req
.
body
)
return
res
.
status
(
400
).
send
({
Message
:
'problem in incoming req.body'
})
const
{
user
,
title
,
color
}
=
req
.
body
;
try
{
const
projectCheck
=
await
dataSource
.
getRepository
(
Project
)
.
find
({
where
:{
title
:
title
}
})
if
(
projectCheck
.
length
>
0
)
{
return
res
.
status
(
400
).
send
({
message
:
"suchc Project already exists"
})}
}
catch
(
e
){
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
try
{
const
member
:
Member
=
new
Member
;
member
.
user
=
user
;
member
.
roleProject
=
MemberRole
.
ADMIN
;
...
...
@@ -62,6 +79,10 @@ router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
project
.
members
=
[
member
]
await
project
.
save
()
return
res
.
send
({
project
})
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
})
}
})
/**get project with all FK & tasks with all FK, by project ID */
router
.
get
(
"/:id"
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>
=>
{
...
...
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