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 }[]
|
setHeaders: { key: string; value: string }[]
|
||||||
role?: Role
|
role?: Role
|
||||||
user?: dbUser
|
user?: dbUser
|
||||||
clientRequestTime?: string
|
clientTimezoneOffset?: number
|
||||||
// hack to use less DB calls for Balance Resolver
|
// hack to use less DB calls for Balance Resolver
|
||||||
lastTransaction?: dbTransaction
|
lastTransaction?: dbTransaction
|
||||||
transactionCount?: number
|
transactionCount?: number
|
||||||
@ -19,7 +19,7 @@ export interface Context {
|
|||||||
|
|
||||||
const context = (args: ExpressContext): Context => {
|
const context = (args: ExpressContext): Context => {
|
||||||
const authorization = args.req.headers.authorization
|
const authorization = args.req.headers.authorization
|
||||||
const clientRequestTime = args.req.headers.clientrequesttime
|
const clientTimezoneOffset = args.req.headers.clienttimezoneoffset
|
||||||
const context: Context = {
|
const context: Context = {
|
||||||
token: null,
|
token: null,
|
||||||
setHeaders: [],
|
setHeaders: [],
|
||||||
@ -27,8 +27,8 @@ const context = (args: ExpressContext): Context => {
|
|||||||
if (authorization) {
|
if (authorization) {
|
||||||
context.token = authorization.replace(/^Bearer /, '')
|
context.token = authorization.replace(/^Bearer /, '')
|
||||||
}
|
}
|
||||||
if (clientRequestTime && typeof clientRequestTime === 'string') {
|
if (clientTimezoneOffset && typeof clientTimezoneOffset === 'string') {
|
||||||
context.clientRequestTime = clientRequestTime
|
context.clientTimezoneOffset = Number(clientTimezoneOffset)
|
||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
@ -38,4 +38,10 @@ export const getUser = (context: Context): dbUser => {
|
|||||||
throw new Error('No user given in context!')
|
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
|
export default context
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user