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
965ff03b
Commit
965ff03b
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
update boat by id controller
parent
8f7c7643
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/boatControllers.controllers.ts
+50
-0
50 additions, 0 deletions
server/src/controllers/boatControllers.controllers.ts
with
50 additions
and
0 deletions
server/src/controllers/boatControllers.controllers.ts
+
50
−
0
View file @
965ff03b
...
@@ -110,11 +110,61 @@ const deleteBoatById = async (req: Request, res: Response) => {
...
@@ -110,11 +110,61 @@ const deleteBoatById = async (req: Request, res: Response) => {
}
}
};
};
//update boat by given id
const
updateBoatById
=
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 boat can be found using givenId
const
foundBoat
=
await
Boat
.
findByPk
(
givenId
);
if
(
!
foundBoat
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFound
"
});
}
//get new input
const
input
=
req
.
body
;
//try to update
const
updatedBoat
=
await
Boat
.
update
(
input
,
{
where
:
{
id
:
givenId
,
},
returning
:
true
,
});
//return after updating
const
boatDataAfterUpdate
=
updatedBoat
[
1
][
0
];
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
{
id
:
boatDataAfterUpdate
.
id
,
name
:
boatDataAfterUpdate
.
name
,
boattype
:
boatDataAfterUpdate
.
boattype
,
status
:
boatDataAfterUpdate
.
status
,
tags
:
boatDataAfterUpdate
.
tags
,
},
});
}
catch
(
error
)
{
console
.
error
(
"
server error:
"
,
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
boatControllers
=
{
const
boatControllers
=
{
showAllBoatsController
,
showAllBoatsController
,
showBoatById
,
showBoatById
,
deleteBoatById
,
deleteBoatById
,
createBoat
,
createBoat
,
updateBoatById
,
};
};
export
default
boatControllers
;
export
default
boatControllers
;
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