nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

How to override the FilterType to make sure a date range is provided?

Open GP4cK opened this issue 2 years ago • 1 comments

📚 Documentation

I'm trying to force the user to provide a date range when querying tasks using @FilterableField({ filterRequired: true, allowedComparisons: ['between'] }). However, when I start the app, I get this error and I can't find how to fix it:

./node_modules/@nestjs/graphql/dist/utils/reflection.utilts.js:15
        throw new undefined_type_error_1.UndefinedTypeError((0, lodash_1.get)(prototype, 'constructor.name'), propertyKey, index);
              ^
Error: Undefined type error. Make sure you are providing an explicit type for the "date" of the "TaskCalendarFilter" class.

Here's my code:

@ObjectType('TaskCalendarFilter')
@QueryOptions({ pagingStrategy: PagingStrategies.NONE })
class TaskCalendarFilter extends TaskCalendar {
  @FilterableField({ filterRequired: true, allowedComparisons: ['between'] })
  date: CommonFieldComparisonBetweenType<number>
}

@ArgsType()
export class TaskCalendarQuery extends QueryArgsType(TaskCalendarFilter) {}

Have you read the Contributing Guidelines on issues?

Yes

GP4cK avatar Mar 03 '22 07:03 GP4cK

This is because between is/was not working when defining them yourself in allowedComparisons, this is fixed in my fork with this pr

TriPSs avatar Jun 06 '22 07:06 TriPSs