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
615ba434
Commit
615ba434
authored
3 years ago
by
Leander Tolksdorf
Browse files
Options
Downloads
Patches
Plain Diff
send cookie with checkin
parent
9739a16c
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/createLogEntry.controllers.ts
+101
-50
101 additions, 50 deletions
server/src/controllers/createLogEntry.controllers.ts
with
101 additions
and
50 deletions
server/src/controllers/createLogEntry.controllers.ts
+
101
−
50
View file @
615ba434
...
...
@@ -2,6 +2,8 @@ import { Request, Response } from "express";
import
CheckIn
from
"
../db/models/CheckIn
"
;
import
Boat
from
"
../db/models/Boat
"
;
import
Sport
from
"
../db/models/Sport
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
envVars
from
"
../config
"
;
export
const
checkInController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -13,7 +15,7 @@ export const checkInController = async (req: Request, res: Response) => {
destination
,
email
,
persons
,
responsible
responsible
,
}:
{
sport
:
string
;
boatName
:
string
;
...
...
@@ -25,16 +27,26 @@ export const checkInController = async (req: Request, res: Response) => {
responsible
:
string
;
}
=
req
.
body
;
const
boat
=
await
Boat
.
findByPk
(
boatName
);
if
(
boat
)
{
if
(
boat
.
status
!=
0
||
(
await
CheckIn
.
findAll
({
where
:
{
BoatId
:
boatName
,
returned
:
false
}
})).
length
>
0
)
{
return
res
.
status
(
400
).
json
({
success
:
false
,
error
:
"
Boat not Availible
"
});
if
(
boat
)
{
if
(
boat
.
status
!=
0
||
(
await
CheckIn
.
findAll
({
where
:
{
BoatId
:
boatName
,
returned
:
false
},
})
).
length
>
0
)
{
return
res
.
status
(
400
)
.
json
({
success
:
false
,
error
:
"
Boat not Availible
"
});
}
}
else
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFound
"
});
}
else
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
boatIdNotFound
"
});
const
sportObj
=
await
Sport
.
findByPk
(
sport
);
if
(
!
sportObj
)
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
sportIdNotFound
"
});
if
(
!
sportObj
)
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
sportIdNotFound
"
});
const
newLogEntry
=
await
CheckIn
.
create
({
SportId
:
sport
,
BoatId
:
boatName
,
...
...
@@ -47,28 +59,40 @@ export const checkInController = async (req: Request, res: Response) => {
bookingType
:
"
default
"
,
returned
:
false
,
note
:
null
,
date
:
new
Date
()
date
:
new
Date
()
,
});
const
payload
=
{
id
:
newLogEntry
.
id
,
};
const
token
=
jwt
.
sign
(
payload
,
envVars
.
JWT_SECRET
);
//return result after checking all possible error-cases
return
res
.
status
(
201
).
json
({
success
:
true
,
result
:
{
id
:
newLogEntry
.
id
,
sport
,
boatName
,
startTime
,
estimatedEndTime
,
destination
,
responsible
,
email
,
persons
,
bookingType
:
"
default
"
,
returned
:
false
,
note
:
null
,
date
:
new
Date
()
},
});
return
res
.
cookie
(
"
checkin_token
"
,
token
,
{
secure
:
process
.
env
.
NODE_ENV
===
"
production
"
,
path
:
"
/
"
,
})
.
status
(
201
)
.
json
({
success
:
true
,
result
:
{
id
:
newLogEntry
.
id
,
sport
,
boatName
,
startTime
,
estimatedEndTime
,
destination
,
responsible
,
email
,
persons
,
bookingType
:
"
default
"
,
returned
:
false
,
note
:
null
,
date
:
new
Date
(),
},
});
}
catch
(
error
)
{
console
.
log
(
error
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
...
...
@@ -76,37 +100,43 @@ export const checkInController = async (req: Request, res: Response) => {
};
export
const
checkOutController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
if
(
!
req
.
params
.
id
||
req
.
params
.
id
==
'
undefined
'
){
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
checkInIdNotFound
"
});
if
(
!
req
.
params
.
id
||
req
.
params
.
id
==
"
undefined
"
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
checkInIdNotFound
"
});
}
const
checkin
=
await
CheckIn
.
findByPk
(
req
.
params
.
id
);
if
(
!
checkin
)
{
return
res
.
status
(
404
).
json
({
success
:
false
,
error
:
"
checkInIdNotFound
"
});
if
(
!
checkin
)
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
checkInIdNotFound
"
});
}
// TODO integrate booking Type
// TODO On annotation send Mail
const
{
note
,
bookingType
bookingType
,
}:
{
note
:
string
;
bookingType
:
string
;
}
=
req
.
body
;
const
updatedCheckin
=
await
CheckIn
.
update
({
returned
:
true
,
note
},
{
where
:
{
id
:
req
.
params
.
id
,
const
updatedCheckin
=
await
CheckIn
.
update
(
{
returned
:
true
,
note
,
},
returning
:
true
,
});
{
where
:
{
id
:
req
.
params
.
id
,
},
returning
:
true
,
}
);
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
updatedCheckin
,
});
}
catch
(
error
)
{
console
.
error
(
error
.
message
);
return
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError
"
});
...
...
@@ -125,14 +155,35 @@ export const getCheckInController = async (req: Request, res: Response) => {
}
};
export
const
getCurrentCheckInController
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
currentId
=
res
.
locals
.
checkinToken
.
id
;
//payload
const
currentCheckIn
=
await
CheckIn
.
findByPk
(
currentId
);
if
(
currentCheckIn
)
{
return
res
.
status
(
200
).
json
({
success
:
true
,
result
:
currentCheckIn
.
id
});
}
else
{
return
res
.
status
(
404
)
.
json
({
success
:
false
,
error
:
"
checkInIdNotFound
"
});
}
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
success
:
false
,
error
:
"
serverError!
"
});
}
};
export
const
resetCheckIns
=
async
(
req
?:
Request
,
res
?:
Response
)
=>
{
const
updatedCheckin
=
await
CheckIn
.
update
({
returned
:
true
,
},
{
where
:
{
returned
:
false
,
const
updatedCheckin
=
await
CheckIn
.
update
(
{
returned
:
true
,
},
returning
:
true
,
});
}
\ No newline at end of file
{
where
:
{
returned
:
false
,
},
returning
:
true
,
}
);
};
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