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
dfbe560c
Commit
dfbe560c
authored
3 years ago
by
elit04
Browse files
Options
Downloads
Patches
Plain Diff
modify show boatType using boat's id controller
parent
5b09f53f
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/boatType.controllers.ts
+15
-1
15 additions, 1 deletion
server/src/controllers/boatType.controllers.ts
with
15 additions
and
1 deletion
server/src/controllers/boatType.controllers.ts
+
15
−
1
View file @
dfbe560c
import
{
Request
,
Response
}
from
"
express
"
;
import
BoatType
from
"
../db/models/BoatType
"
;
import
Boat
from
"
../db/models/Boat
"
;
import
BoatHasBoatType
from
"
../db/models/BoatHasBoatType
"
;
//createBoatTypeController
const
createBoatTypeController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
...
...
@@ -87,9 +88,22 @@ const showBoatTypeById = async (req: Request, res: Response) => {
}
const
givenId
=
req
.
params
.
id
;
const
boat
=
await
Boat
.
findByPk
(
givenId
);
if
(
boat
)
{
const
boattypeid
=
boat
.
boattype
;
//find if boatid exists in BoatHasBoatType table => if not then boat doesn't have assigned boattype
const
boatid
=
await
BoatHasBoatType
.
findByPk
(
boat
.
id
);
if
(
!
boatid
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFoundInBoatHasBoatIdTable
"
});
}
//get boattypeid from BoatHasBoatType table which is assigned to boatid
const
boattypeid
=
boatid
.
boattypeid
;
//find this key in the BoatType table
const
boatname
=
await
BoatType
.
findByPk
(
boattypeid
);
//return the type/name of the given boatid
return
res
.
status
(
200
)
.
json
({
success
:
true
,
result
:
{
name
:
boatname
.
name
}
});
...
...
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