import { getValue , setValue } from 'express-ctx' ; import type { LanguageCode } from '../constants' ; import type { UserEntity } from '../modules/user/user.entity' ; export class ContextProvider { private static readonly nameSpace = 'request' ; private static readonly authUserKey = 'user_key' ; private static readonly languageKey = 'language_key' ; private static get < T > ( key ) { return getValue < T > ( ContextProvider . getKeyWithNamespace ( key ) ) ; } private static set ( key , value ) { setValue ( ContextProvider . getKeyWithNamespace ( key ) , value ) ; } private static getKeyWithNamespace ( key ) { return `${ ContextProvider . nameSpace }.${ key }` ; } static setAuthUser ( user ) { ContextProvider . set ( ContextProvider . authUserKey , user ) ; } static setLanguage ( language ) { ContextProvider . set ( ContextProvider . languageKey , language ) ; } static getLanguage ( ) { return ContextProvider . get < LanguageCode > ( ContextProvider . languageKey ) ; } static getAuthUser ( ) { return ContextProvider . get < UserEntity > ( ContextProvider . authUserKey ) ; } }