Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fahrtenbuch
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWP WS21_22 - Fahrtenbuch
Team Einhorn
fahrtenbuch
Commits
25123cff
Commit
25123cff
authored
3 years ago
by
elit04
Browse files
Options
Downloads
Patches
Plain Diff
check if color is defined in create sport controller
parent
ffeeb9aa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/src/controllers/sport.controllers.ts
+15
-15
15 additions, 15 deletions
server/src/controllers/sport.controllers.ts
with
15 additions
and
15 deletions
server/src/controllers/sport.controllers.ts
+
15
−
15
View file @
25123cff
...
...
@@ -26,15 +26,17 @@ const createSportController = async (req: Request, res: Response) => {
}
//check if color already assigned to another sport (for the statistics)
const
findIfColorAlreadyAssigned
=
await
Sport
.
findOne
({
where
:
{
color
:
newSportInput
.
color
,
},
});
if
(
findIfColorAlreadyAssigned
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
givenSportColorAlreadyExists
"
});
if
(
!
(
newSportInput
.
color
===
undefined
))
{
const
findIfColorAlreadyAssigned
=
await
Sport
.
findOne
({
where
:
{
color
:
newSportInput
.
color
,
},
});
if
(
findIfColorAlreadyAssigned
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
givenSportColorAlreadyExists
"
});
}
}
const
newSport
=
await
Sport
.
create
(
newSportInput
);
...
...
@@ -249,12 +251,10 @@ const showSportBySportId = async (req: Request, res: Response) => {
const
givenId
=
req
.
params
.
id
;
const
sport
=
await
Sport
.
findByPk
(
givenId
);
if
(
sport
)
{
return
res
.
status
(
200
)
.
json
({
success
:
true
,
result
:
{
id
:
givenId
,
name
:
sport
.
name
,
color
:
sport
.
color
},
});
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
{
id
:
givenId
,
name
:
sport
.
name
,
color
:
sport
.
color
},
});
}
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
sportIdNotFound
"
});
}
catch
(
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment