mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
change client request time to client timezone offset
This commit is contained in:
parent
1b6dab32bf
commit
e89e30e33e
@ -9,7 +9,7 @@ export interface Context {
|
||||
setHeaders: { key: string; value: string }[]
|
||||
role?: Role
|
||||
user?: dbUser
|
||||
clientRequestTime?: string
|
||||
clientTimezoneOffset?: number
|
||||
// hack to use less DB calls for Balance Resolver
|
||||
lastTransaction?: dbTransaction
|
||||
transactionCount?: number
|
||||
@ -19,7 +19,7 @@ export interface Context {
|
||||
|
||||
const context = (args: ExpressContext): Context => {
|
||||
const authorization = args.req.headers.authorization
|
||||
const clientRequestTime = args.req.headers.clientrequesttime
|
||||
const clientTimezoneOffset = args.req.headers.clienttimezoneoffset
|
||||
const context: Context = {
|
||||
token: null,
|
||||
setHeaders: [],
|
||||
@ -27,8 +27,8 @@ const context = (args: ExpressContext): Context => {
|
||||
if (authorization) {
|
||||
context.token = authorization.replace(/^Bearer /, '')
|
||||
}
|
||||
if (clientRequestTime && typeof clientRequestTime === 'string') {
|
||||
context.clientRequestTime = clientRequestTime
|
||||
if (clientTimezoneOffset && typeof clientTimezoneOffset === 'string') {
|
||||
context.clientTimezoneOffset = Number(clientTimezoneOffset)
|
||||
}
|
||||
return context
|
||||
}
|
||||
@ -38,4 +38,10 @@ export const getUser = (context: Context): dbUser => {
|
||||
throw new Error('No user given in context!')
|
||||
}
|
||||
|
||||
export const getClientTimezoneOffset = (context: Context): number => {
|
||||
if (context.clientTimezoneOffset && Math.abs(context.clientTimezoneOffset) <= 27 * 60)
|
||||
return context.clientTimezoneOffset
|
||||
throw new Error('No valid client time zone offset in context!')
|
||||
}
|
||||
|
||||
export default context
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user