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
5e44574f
Commit
5e44574f
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
check if num of the other clients + main client = num of total seats of chosen boat
parent
238838db
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/createLogEntryControllers.controllers.ts
+29
-6
29 additions, 6 deletions
.../src/controllers/createLogEntryControllers.controllers.ts
with
29 additions
and
6 deletions
server/src/controllers/createLogEntryControllers.controllers.ts
+
29
−
6
View file @
5e44574f
import
{
Request
,
Response
}
from
"
express
"
;
import
{
Request
,
Response
}
from
"
express
"
;
import
CheckIn
from
"
../db/models/CheckIn
"
;
import
CheckIn
from
"
../db/models/CheckIn
"
;
import
Boat
from
"
../db/models/Boat
"
;
import
Boat
from
"
../db/models/Boat
"
;
import
BoatType
from
"
../db/models/BoatType
"
;
//create log entry
//create log entry
const
createLogEntryController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
createLogEntryController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
try
{
//get input
const
logEntry
=
req
.
body
;
const
logEntry
=
req
.
body
;
const
boatid
=
await
Boat
.
findByPk
(
logEntry
.
boatID
);
//find related boat using given boatId
const
chosenBoat
=
await
Boat
.
findByPk
(
logEntry
.
boatId
);
//if boat not found
if
(
!
chosenBoat
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
givenBoatIdNotFound
"
});
}
//get status of boat
//get status of boat
const
bootAvailability
=
b
oat
id
.
status
;
const
bootAvailability
=
chosenB
oat
.
status
;
//if boat is not available =>
it's
locked
//if boat
status is false =>
is not available =>
boat
locked
if
(
bootAvailability
===
false
)
{
if
(
bootAvailability
===
false
)
{
return
res
.
status
(
409
).
json
({
success
:
false
,
error
:
"
BoatLocked
"
});
return
res
.
status
(
409
).
json
({
success
:
false
,
error
:
"
BoatLocked
"
});
}
}
//check if number of additional clients == number of seats - 1 (responsable client)
const
numOfAdditionalClients
=
logEntry
.
additionalClients
.
length
;
const
boatTypeOfChosenBoat
=
await
BoatType
.
findByPk
(
chosenBoat
.
boattype
);
//number of seats of any boat can be found in its boattype
if
(
numOfAdditionalClients
!==
boatTypeOfChosenBoat
.
seats
-
1
)
{
//minus responsable client
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
numOfAllGivenClientsDoesNotMatchNumOfChosenBoatSeats
"
,
});
}
//create entry
const
newLogEntry
=
await
CheckIn
.
create
(
logEntry
);
const
newLogEntry
=
await
CheckIn
.
create
(
logEntry
);
//return result after checking all possible error-cases
return
res
.
status
(
201
).
json
({
return
res
.
status
(
201
).
json
({
success
:
true
,
success
:
true
,
result
:
{
result
:
{
startTime
:
newLogEntry
.
startTime
,
startTime
:
newLogEntry
.
startTime
,
estimatedEndTime
:
newLogEntry
.
estimatedEndTime
,
estimatedEndTime
:
newLogEntry
.
estimatedEndTime
,
email
:
newLogEntry
.
email
,
email
:
newLogEntry
.
email
,
firstName
:
newLogEntry
.
firstName
,
fullNameOfResponsableClient
:
newLogEntry
.
fullNameOfResponsableClient
,
lastName
:
newLogEntry
.
lastName
,
additionalClients
:
newLogEntry
.
additionalClients
,
additionalClients
:
newLogEntry
.
additionalClients
,
boatID
:
newLogEntry
.
boatI
D
,
boatID
:
newLogEntry
.
boatI
d
,
},
},
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
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