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
d2a132e8
Commit
d2a132e8
authored
3 years ago
by
elit04
Browse files
Options
Downloads
Patches
Plain Diff
better way to return updated data from update boat controller
parent
72753a88
No related branches found
Branches containing commit
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/boat.controllers.ts
+16
-6
16 additions, 6 deletions
server/src/controllers/boat.controllers.ts
with
16 additions
and
6 deletions
server/src/controllers/boat.controllers.ts
+
16
−
6
View file @
d2a132e8
...
...
@@ -279,7 +279,7 @@ const updateBoatById = async (req: Request, res: Response) => {
const
newSportsArray
=
input
.
sports
;
if
(
!
(
newSportsArray
===
undefined
))
{
//define empty array, where we store founded/not founded
name
s of sports assigned to boat's id
//define empty array, where we store founded/not founded
id'
s of sports assigned to boat's id
var
listIfNotFound
=
new
Array
();
var
listIfFound
=
new
Array
();
...
...
@@ -317,8 +317,6 @@ const updateBoatById = async (req: Request, res: Response) => {
.
status
(
404
)
.
json
({
success
:
false
,
error
:
listIfNotFound
+
"
sportIdNotFound
"
});
}
// help Array in order to print as response the name of the updated new sports to boat
var
listOfNames
=
new
Array
();
//if sports Array is with valid id's, assign them to boat; create entry (boatid, each id of given sportIds) inf BoatHasSport table
for
(
let
i
=
0
;
i
<
listIfFound
.
length
;
i
++
)
{
const
boatid
=
givenId
;
...
...
@@ -327,12 +325,24 @@ const updateBoatById = async (req: Request, res: Response) => {
//create new entry in boatHasBoatType
await
BoatHasSport
.
create
(
entry
);
const
findSportName
=
await
(
await
Sport
.
findByPk
(
listIfFound
[
i
])).
name
;
listOfNames
.
push
(
findSportName
);
}
}
//get names of assigned sports to boat for the response message
// help Array in order to print as response the name of the updated + previously added new sports to boat
var
listOfNames
=
new
Array
();
const
findAllSportsAssignedToBoat
=
await
BoatHasSport
.
findAll
({
where
:
{
boatid
:
givenId
,
},
});
for
(
let
i
=
0
;
i
<
findAllSportsAssignedToBoat
.
length
;
i
++
)
{
const
foundedSportName
=
await
Sport
.
findByPk
(
findAllSportsAssignedToBoat
[
i
].
sportid
);
listOfNames
.
push
(
foundedSportName
.
name
);
}
//we need this special case res, because sports is not an attribute assigned to Boat table, and if only sports provided as request body error happens
// check if in the requested body only values for sports were provided
if
(
Object
.
keys
(
input
).
length
===
1
&&
!
(
input
.
sports
===
undefined
))
{
...
...
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