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
2ba1a654
Commit
2ba1a654
authored
3 years ago
by
alrwasheda
Browse files
Options
Downloads
Patches
Plain Diff
exporting controller directly + some fixes
parent
983c582f
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/createLogEntryControllers.controllers.ts
+30
-38
30 additions, 38 deletions
.../src/controllers/createLogEntryControllers.controllers.ts
server/src/routes/createLogEntryRoutes.routes.ts
+13
-13
13 additions, 13 deletions
server/src/routes/createLogEntryRoutes.routes.ts
with
43 additions
and
51 deletions
server/src/controllers/createLogEntryControllers.controllers.ts
+
30
−
38
View file @
2ba1a654
...
...
@@ -3,44 +3,36 @@ import CheckIn from "../db/models/CheckIn";
import
Boat
from
"
../db/models/Boat
"
;
//create log entry
const
createLogEntry
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
createLogEntryController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
logEntry
=
req
.
body
;
const
boatid
=
await
Boat
.
findByPk
(
logEntry
.
boatID
);
try
{
const
logEntry
=
req
.
body
;
const
boatid
=
Boat
.
findByPk
(
logEntry
.
boatID
);
//get status of boat
const
bootAvailability
=
(
await
boatid
).
status
;
//if boat is not available => it's locked
if
(
!
(
bootAvailability
===
true
))
{
return
res
.
status
(
409
).
json
({
success
:
false
,
error
:
"
BoatLocked
"
});
};
const
newLogEntry
=
await
CheckIn
.
create
(
logEntry
);
return
res
.
status
(
201
).
json
({
success
:
true
,
account
:
{
startTime
:
newLogEntry
.
startTime
,
estimatedEndTime
:
newLogEntry
.
estimatedEndTime
,
email
:
newLogEntry
.
email
,
firstName
:
newLogEntry
.
firstName
,
lastName
:
newLogEntry
.
lastName
,
additionalClients
:
newLogEntry
.
additionalClients
,
boatID
:
newLogEntry
.
boatID
,
},
});
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
//get status of boat
const
bootAvailability
=
boatid
.
status
;
//if boat is not available => it's locked
if
(
bootAvailability
===
false
)
{
return
res
.
status
(
409
).
json
({
success
:
false
,
error
:
"
BoatLocked
"
});
}
const
newLogEntry
=
await
CheckIn
.
create
(
logEntry
);
return
res
.
status
(
201
).
json
({
success
:
true
,
result
:
{
startTime
:
newLogEntry
.
startTime
,
estimatedEndTime
:
newLogEntry
.
estimatedEndTime
,
email
:
newLogEntry
.
email
,
firstName
:
newLogEntry
.
firstName
,
lastName
:
newLogEntry
.
lastName
,
additionalClients
:
newLogEntry
.
additionalClients
,
boatID
:
newLogEntry
.
boatID
,
},
});
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
}
};
const
createLogEntryControllers
=
{
createLogEntry
,
};
export
default
createLogEntryControllers
;
\ No newline at end of file
export
default
createLogEntryController
;
This diff is collapsed.
Click to expand it.
server/src/routes/createLogEntryRoutes.routes.ts
+
13
−
13
View file @
2ba1a654
import
{
Router
}
from
"
express
"
;
import
{
body
}
from
"
express-validator
"
;
import
handleValidationResult
from
"
../middleware/handleValidationResult
"
;
import
createLogEntryController
s
from
"
../controllers/createLogEntryControllers.controllers
"
;
import
createLogEntryController
from
"
../controllers/createLogEntryControllers.controllers
"
;
const
entryRouter
=
Router
();
//create new log entry route
entryRouter
.
post
(
"
/api/logentry/
"
,
//isISO8601() checks if string is a valid date+time
body
(
"
startTime
"
).
isISO8601
(),
body
(
"
estimatedEndTime
"
).
isISO8601
(),
body
(
"
email
"
).
isEmail
().
normalizeEmail
(),
body
(
"
firstName
"
).
not
().
isEmpty
(),
body
(
"
lastName
"
).
not
().
isEmpty
(),
body
(
"
boatID
"
).
isUUID
(),
handleValidationResult
,
createLogEntryController
s
.
createLogEntry
);
"
/api/logentry/
"
,
//isISO8601() checks if string is a valid date+time
body
(
"
startTime
"
).
isISO8601
(),
body
(
"
estimatedEndTime
"
).
isISO8601
(),
body
(
"
email
"
).
isEmail
().
normalizeEmail
(),
body
(
"
firstName
"
).
not
().
isEmpty
(),
body
(
"
lastName
"
).
not
().
isEmpty
(),
body
(
"
boatID
"
).
isUUID
(),
handleValidationResult
,
createLogEntryController
);
export
default
entryRouter
;
\ No newline at end of file
export
default
entryRouter
;
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