# All files / core/pipes pipes-consumer.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 5/5
100% Lines 9/9

    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
    1x

    1x
    116x

    9x
    9x

    15x
    12x
    12x
    12x

     import { Transform } from '@nestjs/common/interfaces';
    import { ParamsTokenFactory } from './params-token-factory';

    export class PipesConsumer {
      private readonly paramsTokenFactory = new ParamsTokenFactory();

      public async apply(
        value,
        { metatype, type, data },
        transforms: Transform<any>[],
      ) {
        const token = this.paramsTokenFactory.exchangeEnumForString(type);
        return this.applyPipes(
          value,
          { metatype, type: token, data },
          transforms,
        );
      }

      public async applyPipes(
        value,
        { metatype, type, data }: { metatype; type?; data? },
        transforms: Transform<any>[],
      ) {
        return transforms.reduce(async (defferedValue, fn) => {
          const val = await defferedValue;
          const result = fn(val, { metatype, type, data });
          return result;
        }, Promise.resolve(value));
      }
    }