All checks were successful
Dev CI / Backend — Lint (push) Successful in 10m23s
Dev CI / Backend — Unit Tests (push) Successful in 10m17s
Dev CI / Frontend — Lint & Type-check (push) Successful in 11m3s
Dev CI / Frontend — Unit Tests (push) Successful in 10m33s
Dev CI / Notify Failure (push) Has been skipped
20 lines
674 B
TypeScript
20 lines
674 B
TypeScript
/**
|
|
* UserPreferenceResolver
|
|
*
|
|
* nestjs-i18n resolver that reads the authenticated user's preferredLanguage
|
|
* from the request (populated by JwtAuthGuard). Highest priority in the chain.
|
|
*/
|
|
|
|
import { Injectable, ExecutionContext } from '@nestjs/common';
|
|
import { I18nResolver } from 'nestjs-i18n';
|
|
import { isLocale } from '@domain/value-objects/locale.vo';
|
|
|
|
@Injectable()
|
|
export class UserPreferenceResolver implements I18nResolver {
|
|
resolve(context: ExecutionContext): string | undefined {
|
|
const request = context.switchToHttp().getRequest();
|
|
const preferred = request?.user?.preferredLanguage;
|
|
return isLocale(preferred) ? preferred : undefined;
|
|
}
|
|
}
|