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
163f3062
Commit
163f3062
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
update boatType by id controller
parent
4dcd32ba
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/boatTypeControllers.controllers.ts
+51
-1
51 additions, 1 deletion
server/src/controllers/boatTypeControllers.controllers.ts
with
51 additions
and
1 deletion
server/src/controllers/boatTypeControllers.controllers.ts
+
51
−
1
View file @
163f3062
...
...
@@ -43,7 +43,7 @@ const showAllBoatTypes = async (req: Request, res: Response) => {
return
res
.
status
(
200
).
send
({
success
:
true
,
result
:
allBoatTypes
.
map
((
boattype
)
=>
{
return
{
name
:
boattype
.
name
,
seats
:
boattype
.
seats
};
return
{
id
:
boattype
.
id
,
name
:
boattype
.
name
,
seats
:
boattype
.
seats
};
}),
});
}
catch
(
error
)
{
...
...
@@ -102,11 +102,61 @@ const showBoatTypeById = async (req: Request, res: Response) => {
}
};
//update boatType by given id
const
updateBoatTypeById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
//check authority
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
//get id
const
givenId
=
req
.
params
.
id
;
//check if boatType can be found using givenId
const
foundBoatType
=
await
BoatType
.
findByPk
(
givenId
);
if
(
!
foundBoatType
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
boatTypeIdNotFound
"
});
}
//get new input
const
input
=
req
.
body
;
//try to update
const
updatedBoatType
=
await
BoatType
.
update
(
input
,
{
where
:
{
id
:
givenId
,
},
returning
:
true
,
});
//return after updating
const
boatTypeDataAfterUpdate
=
updatedBoatType
[
1
][
0
];
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
{
id
:
boatTypeDataAfterUpdate
.
id
,
name
:
boatTypeDataAfterUpdate
.
name
,
seats
:
boatTypeDataAfterUpdate
.
seats
,
},
});
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
boatTypeControllers
=
{
showAllBoatTypes
,
createBoatTypeController
,
deleteBoatTypeById
,
showBoatTypeById
,
updateBoatTypeById
,
};
export
default
boatTypeControllers
;
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