• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

doug-martin / nestjs-query / 6447619094

08 Oct 2023 12:30PM CUT coverage: 96.667%. Remained the same
6447619094

push

github

renovate[bot]
chore(deps): update dependency @types/supertest to v2.0.14

1796 of 1940 branches covered (0.0%)

Branch coverage included in aggregate %.

4962 of 5051 relevant lines covered (98.24%)

806.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.0
/packages/query-graphql/src/resolvers/helpers.ts
1
import { applyFilter, Class, Filter } from '@nestjs-query/core';
348✔
2
import { plainToClass } from 'class-transformer';
348✔
3
import { validate } from 'class-validator';
348✔
4
import { BadRequestException } from '@nestjs/common';
348✔
5
import { SubscriptionArgsType, SubscriptionFilterInputType } from '../types';
6

7
/** @internal */
8
export const transformAndValidate = async <T>(TClass: Class<T>, partial: T): Promise<T> => {
348✔
9
  if (partial instanceof TClass) {
956✔
10
    return partial;
824✔
11
  }
12
  const transformed = plainToClass(TClass, partial);
132✔
13
  const validationErrors = await validate(transformed as unknown as Record<keyof never, unknown>);
132✔
14
  if (validationErrors.length) {
132✔
15
    throw new BadRequestException(validationErrors);
4✔
16
  }
17
  return transformed;
128✔
18
};
19

20
export const createSubscriptionFilter =
348✔
21
  <DTO, Input extends SubscriptionFilterInputType<DTO>>(
348✔
22
    InputClass: Class<Input>,
23
    payloadKey: string,
24
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
  ): ((payload: any, variables: SubscriptionArgsType<Input>, context: any) => boolean | Promise<boolean>) =>
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
  async (payload: any, variables: SubscriptionArgsType<Input>): Promise<boolean> => {
1,728✔
28
    const { input } = variables;
×
29
    if (input) {
×
30
      const args = await transformAndValidate(InputClass, input);
×
31
      // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
32
      const dto = payload[payloadKey] as DTO;
×
33
      return applyFilter(dto, args.filter || {});
×
34
    }
35
    return true;
×
36
  };
37

38
export function getSubscriptionEventName<T>(eventName: string, authorizeFilter?: Filter<T>): string {
348✔
39
  return authorizeFilter ? `${eventName}-${JSON.stringify(authorizeFilter)}` : eventName;
208✔
40
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc