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
006036d8
Commit
006036d8
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
organisatorisch
parent
183caa79
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/boatControllers.controllers.ts
+30
-27
30 additions, 27 deletions
server/src/controllers/boatControllers.controllers.ts
server/src/controllers/boatTypeControllers.controllers.ts
+37
-30
37 additions, 30 deletions
server/src/controllers/boatTypeControllers.controllers.ts
with
67 additions
and
57 deletions
server/src/controllers/boatControllers.controllers.ts
+
30
−
27
View file @
006036d8
import
{
Request
,
Response
}
from
"
express
"
;
import
BoatType
from
"
../db/models/BoatType
"
;
import
Boat
from
"
../db/models/Boat
"
;
//create boat
const
createBoat
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
==
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
newBoatInput
=
req
.
body
;
const
boatType
=
await
BoatType
.
findByPk
(
newBoatInput
.
boattype
);
if
(
!
boatType
){
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boattypeNotFound
"
})
}
const
newBoat
=
await
Boat
.
create
(
newBoatInput
);
if
(
newBoat
)
{
return
res
.
status
(
201
)
.
json
({
success
:
true
,
result
:
newBoat
});
}
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
//show all boats
const
showAllBoatsController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -53,33 +83,6 @@ const deleteBoatById = async (req: Request, res: Response) => {
}
};
//create boat
const
createBoat
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
==
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
newBoatInput
=
req
.
body
;
console
.
log
(
"
input von req.body:
"
,
newBoatInput
);
const
newBoat
=
await
Boat
.
create
(
newBoatInput
);
const
{
id
,
name
,
boattype
,
status
,
active
,
tags
}
=
newBoat
;
if
(
newBoat
)
{
return
res
.
status
(
201
)
.
json
({
success
:
true
,
result
:
{
id
,
name
,
boattype
,
status
,
active
,
tags
}
});
}
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
boatControllers
=
{
showAllBoatsController
,
...
...
This diff is collapsed.
Click to expand it.
server/src/controllers/boatTypeControllers.controllers.ts
+
37
−
30
View file @
006036d8
...
...
@@ -2,23 +2,6 @@ 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
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
allBoatTypes
=
await
BoatType
.
findAll
();
return
res
.
status
(
200
).
send
({
success
:
true
,
result
:
allBoatTypes
});
}
catch
(
error
)
{
console
.
error
(
"
server error:
"
,
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
//createBoatTypeController
const
createBoatTypeController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -32,12 +15,15 @@ const createBoatTypeController = async (req: Request, res: Response) => {
const
newBoatType
=
await
BoatType
.
create
(
newBoatTypeInput
);
const
{
id
,
name
,
seats
}
=
newBoatType
;
if
(
newBoatType
)
{
return
res
.
status
(
201
)
.
json
({
success
:
true
,
result
:
{
id
,
name
,
seats
}
});
return
res
.
status
(
201
).
json
({
success
:
true
,
result
:
{
id
:
newBoatType
.
id
,
name
:
newBoatType
.
name
,
seats
:
newBoatType
.
seats
,
},
});
}
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
...
...
@@ -45,6 +31,27 @@ const createBoatTypeController = async (req: Request, res: Response) => {
}
};
//show all BoatTypes
const
showAllBoatTypes
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
(
res
.
locals
.
user
.
role
===
"
coordinator
"
))
{
return
res
.
status
(
403
)
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
allBoatTypes
=
await
BoatType
.
findAll
();
return
res
.
status
(
200
).
send
({
success
:
true
,
result
:
allBoatTypes
.
map
((
boattype
)
=>
{
return
{
id
:
boattype
.
id
,
name
:
boattype
.
name
,
seats
:
boattype
.
seats
};
}),
});
}
catch
(
error
)
{
console
.
error
(
"
server error:
"
,
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
//delete specific BoatType using given id
const
deleteBoatTypeById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -54,7 +61,7 @@ const deleteBoatTypeById = async (req: Request, res: Response) => {
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
givenId
=
req
.
params
.
id
;
const
boatToDelete
=
await
BoatType
.
destroy
({
const
boatToDelete
=
await
BoatType
.
destroy
({
where
:
{
id
:
givenId
,
},
...
...
@@ -71,7 +78,6 @@ const deleteBoatTypeById = async (req: Request, res: Response) => {
}
};
//show type of a boat using boat's id
const
showBoatTypeById
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -81,11 +87,13 @@ const showBoatTypeById = async (req: Request, res: Response) => {
.
json
({
success
:
false
,
error
:
"
MustBeCoordinator
"
});
}
const
givenId
=
req
.
params
.
id
;
const
boat
id
=
await
Boat
.
findByPk
(
givenId
);
if
(
boat
id
)
{
const
boattypeid
=
boat
id
.
boattype
;
const
boat
=
await
Boat
.
findByPk
(
givenId
);
if
(
boat
)
{
const
boattypeid
=
boat
.
boattype
;
const
boatname
=
await
BoatType
.
findByPk
(
boattypeid
);
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
{
name
:
boatname
.
name
}
});
return
res
.
status
(
200
)
.
json
({
success
:
true
,
result
:
{
name
:
boatname
.
name
}
});
}
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFound
"
});
}
catch
(
error
)
{
...
...
@@ -94,11 +102,10 @@ const showBoatTypeById = async (req: Request, res: Response) => {
}
};
const
boatTypeControllers
=
{
showAllBoatTypes
,
createBoatTypeController
,
deleteBoatTypeById
,
deleteBoatTypeById
,
showBoatTypeById
,
};
...
...
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