diff --git a/__tests__/__fixtures__/cars.fixture.ts b/__tests__/__fixtures__/cars.fixture.ts index 56bed3f..2547c72 100644 --- a/__tests__/__fixtures__/cars.fixture.ts +++ b/__tests__/__fixtures__/cars.fixture.ts @@ -1,6 +1,11 @@ import type { MangoFinderOptionsDTO } from '@/dtos' import type { MangoCacheFinder } from '@/interfaces' -import type { MangoParsedUrlQuery, MangoSearchParams, UID } from '@/types' +import type { + DTOFilter, + MangoParsedUrlQuery, + MangoSearchParams, + UID +} from '@/types' import { IsNotEmpty, IsNumber, IsString } from 'class-validator' /** @@ -19,6 +24,8 @@ export type CarUID = 'vin' export type CarParams = MangoSearchParams export type CarQuery = MangoParsedUrlQuery +export type CarDTOFilter = DTOFilter + export class Car implements ICar { @IsString() @IsNotEmpty() diff --git a/src/types/repository.types.ts b/src/types/repository.types.ts index 4b1e21a..81f637f 100644 --- a/src/types/repository.types.ts +++ b/src/types/repository.types.ts @@ -1,4 +1,10 @@ -import type { ObjectEmpty, ObjectPlain } from '@flex-development/tutils' +import type { + DeepPartialByRequiredHelper, + ObjectEmpty, + ObjectPlain, + ObjectUnknown, + Path +} from '@flex-development/tutils' import type { UID } from './utils.types' /** @@ -6,6 +12,24 @@ import type { UID } from './utils.types' * @module types/repository */ +/** + * DTO filter object. + * + * @template E - Entity + * @template P - Required object field paths + * @template F - Object field path filter object. Omits fields + * + * @example + * interface IUser{ ... } + * type Filter = DTOFilter + */ +export type DTOFilter< + E extends ObjectPlain = ObjectUnknown, + P extends Path = Path, + /* eslint-disable-next-line @typescript-eslint/ban-types */ + F extends Partial, never>> = {} +> = DeepPartialByRequiredHelper + /** * Type representing the root of a repository. *