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
b36eefd4
Commit
b36eefd4
authored
3 years ago
by
elit04
Browse files
Options
Downloads
Patches
Plain Diff
show boat type according to given boat id Controller+Route
parent
a4fa36d5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/src/controllers/boatTypeControllers.controllers.ts
+27
-3
27 additions, 3 deletions
server/src/controllers/boatTypeControllers.controllers.ts
server/src/routes/boatTypeRoutes.routes.ts
+7
-0
7 additions, 0 deletions
server/src/routes/boatTypeRoutes.routes.ts
with
34 additions
and
3 deletions
server/src/controllers/boatTypeControllers.controllers.ts
+
27
−
3
View file @
b36eefd4
import
{
Request
,
Response
}
from
"
express
"
;
import
BoatType
from
"
../db/models/BoatType
"
;
import
Boat
from
"
../db/models/Boat
"
;
//show all BoatTypes
const
showAllBoatTypes
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
...
...
@@ -28,8 +30,6 @@ const createBoatTypeController = async (req: Request, res: Response) => {
const
newBoatTypeInput
=
req
.
body
;
console
.
log
(
"
input von req.body:
"
,
newBoatTypeInput
);
const
newBoatType
=
await
BoatType
.
create
(
newBoatTypeInput
);
const
{
id
,
name
,
seats
}
=
newBoatType
;
...
...
@@ -72,10 +72,34 @@ const deleteBoatTypeById = async (req: Request, res: Response) => {
};
//show type of a boat using boat's id
const
showBoatTypeById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
givenId
=
req
.
params
.
id
;
const
boatid
=
await
Boat
.
findByPk
(
givenId
);
if
(
boatid
)
{
const
boattypeid
=
boatid
.
boattype
;
const
boatname
=
await
BoatType
.
findByPk
(
boattypeid
);
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
{
name
:
boatname
.
name
}
});
}
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFound
"
});
}
catch
(
error
)
{
console
.
error
(
"
server error:
"
,
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
boatTypeControllers
=
{
showAllBoatTypes
,
createBoatTypeController
,
deleteBoatTypeById
deleteBoatTypeById
,
showBoatTypeById
,
};
export
default
boatTypeControllers
;
This diff is collapsed.
Click to expand it.
server/src/routes/boatTypeRoutes.routes.ts
+
7
−
0
View file @
b36eefd4
...
...
@@ -30,4 +30,11 @@ boatTypeRouter.delete(
boatTypeControllers
.
deleteBoatTypeById
);
//show specific boat type by given boat id
boatTypeRouter
.
get
(
"
/api/boattype/:id/
"
,
validateToken
,
boatTypeControllers
.
showBoatTypeById
);
export
default
boatTypeRouter
;
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