• 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

83.33
/packages/query-graphql/src/types/query/query-args.type.ts
1
import { Class } from '@nestjs-query/core';
2
import { PagingStrategies } from './paging';
344✔
3
import {
344✔
4
  DEFAULT_QUERY_OPTS,
5
  CursorQueryArgsTypeOpts,
6
  OffsetQueryArgsTypeOpts,
7
  NonePagingQueryArgsTypeOpts,
8
  QueryArgsTypeOpts,
9
  StaticQueryType,
10
  createOffsetQueryArgs,
11
  createNonePagingQueryArgsType,
12
  createCursorQueryArgsType,
13
} from './query-args';
14
import { getQueryOptions } from '../../decorators';
344✔
15
import { removeUndefinedValues } from '../../common';
344✔
16

17
const getMergedQueryOpts = <DTO>(DTOClass: Class<DTO>, opts?: QueryArgsTypeOpts<DTO>): QueryArgsTypeOpts<DTO> => {
344✔
18
  const decoratorOpts = getQueryOptions(DTOClass);
1,124✔
19
  return {
1,124✔
20
    ...DEFAULT_QUERY_OPTS,
21
    pagingStrategy: PagingStrategies.CURSOR,
22
    ...removeUndefinedValues(decoratorOpts ?? {}),
3,372✔
23
    ...removeUndefinedValues(opts ?? {}),
3,372✔
24
  };
25
};
26

27
// tests if the object is a QueryArgs Class
28
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
29
export const isStaticQueryArgsType = <DTO>(obj: any): obj is StaticQueryType<DTO, PagingStrategies> =>
344✔
30
  typeof obj === 'function' && 'PageType' in obj && 'SortType' in obj && 'FilterType' in obj;
×
31

32
export function QueryArgsType<DTO>(
33
  DTOClass: Class<DTO>,
34
  opts: OffsetQueryArgsTypeOpts<DTO>,
35
): StaticQueryType<DTO, PagingStrategies.OFFSET>;
36
export function QueryArgsType<DTO>(
37
  DTOClass: Class<DTO>,
38
  opts: NonePagingQueryArgsTypeOpts<DTO>,
39
): StaticQueryType<DTO, PagingStrategies.NONE>;
40
export function QueryArgsType<DTO>(
41
  DTOClass: Class<DTO>,
42
  opts: CursorQueryArgsTypeOpts<DTO>,
43
): StaticQueryType<DTO, PagingStrategies.CURSOR>;
44
export function QueryArgsType<DTO>(
45
  DTOClass: Class<DTO>,
46
  opts?: QueryArgsTypeOpts<DTO>,
47
): StaticQueryType<DTO, PagingStrategies>;
48
export function QueryArgsType<DTO>(
344✔
49
  DTOClass: Class<DTO>,
50
  opts?: QueryArgsTypeOpts<DTO>,
51
): StaticQueryType<DTO, PagingStrategies> {
52
  // override any options from the DTO with the options passed in
53
  const mergedOpts = getMergedQueryOpts(DTOClass, opts);
1,124✔
54
  if (mergedOpts.pagingStrategy === PagingStrategies.OFFSET) {
1,124✔
55
    return createOffsetQueryArgs(DTOClass, mergedOpts);
136✔
56
  }
57
  if (mergedOpts.pagingStrategy === PagingStrategies.NONE) {
988✔
58
    return createNonePagingQueryArgsType(DTOClass, mergedOpts);
108✔
59
  }
60
  return createCursorQueryArgsType(DTOClass, mergedOpts);
880✔
61
}
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