# All files / core/router route-params-factory.ts

100% Statements 14/14
86.96% Branches 20/23
100% Functions 1/1
100% Lines 14/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    361x

    1x

    15x

    3x

    1x

    1x

    3x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

     import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
    import { IRouteParamsFactory } from './interfaces/route-params-factory.interface';

    export class RouteParamsFactory implements IRouteParamsFactory {
      public exchangeKeyForValue(
        key: RouteParamtypes | string,
        data: string | object | any,
        { req, res, next },
      ) {
        switch (key) {
          case RouteParamtypes.NEXT:
            return next;
          case RouteParamtypes.REQUEST:
            return req;
          case RouteParamtypes.RESPONSE:
            return res;
          case RouteParamtypes.BODY:
            return data && req.body ? req.body[data] : req.body;
          case RouteParamtypes.PARAM:
            return data ? req.params[data] : req.params;
          case RouteParamtypes.QUERY:
            return data ? req.query[data] : req.query;
          case RouteParamtypes.HEADERS:
            return data ? req.headers[data] : req.headers;
          case RouteParamtypes.SESSION:
            return req.session;
          case RouteParamtypes.FILE:
            return req[data || 'file'];
          case RouteParamtypes.FILES:
            return req.files;
          default:
            return null;
        }
      }
    }