I'm trying to code a getAll() method for an Api. This method takes in a ton of different @Query() optional params as to build a filters object, and one of them is an array of enums.
like so:
enum Week{
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
}
@Controller('activity')
export class ActivityController {
constructor(private readonly service: ActivityService) { }
@Get('/')
getAllActivities(
//many other @Query('') param
@Query('weekDays') weekDays?: Week[],
) {
//build filters object here
// const filters = {foo}
return this.service.getAllActivities(filters)
}
Is there a way of parsing this using validationPipes? or any other Nest.js resource that might be unknown to me?
So far i haven't been able to use the pipes either way, it appears pipes don't really work with optional params since they throw an error if a value isn't provided.
Maybe i should just set weekDays to string, make a weekDaysParse() function and parse inside controller logic. Would that be a good practice?