All files / lib/decorators i18n-lang.decorator.ts

100% Statements 8/8
50% Branches 3/6
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 206x   6x     15x 4x   11x       11x       4x 4x    
import { createParamDecorator } from '@nestjs/common';
 
export const I18nLang = createParamDecorator((data, req) => {
  // this is gonna be so nasty..
  // FIXME: This has to be fixed in later stages! PLEASE!
  if (Array.isArray(req)) {
    return resolveI18nLanguageFromGraphQLContext(req);
  }
  return resolveI18nLanguageFromRestRequest(req);
});
 
function resolveI18nLanguageFromRestRequest(req) {
  return req.i18nLang || (req.raw ? req.raw.i18nLang : undefined);
}
 
function resolveI18nLanguageFromGraphQLContext(req) {
  const [root, args, ctx, info] = req;
  return ctx.req.i18nLang;
}