-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow filtering events by campus ID
- Loading branch information
Showing
9 changed files
with
119 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { FindEventsResponseDto } from '../../ft-api/dto/find-events-response.dto'; | ||
import { FindAllEventsDto } from '../../events/dto/find-all-events.dto'; | ||
|
||
export function filterEventsByCampusIds(events: FindEventsResponseDto, campusIds: FindAllEventsDto['campusIds']) { | ||
if (campusIds === undefined) { | ||
return events; | ||
} | ||
return events.filter((event) => { | ||
return event.campus_ids.some((campusId) => campusIds.includes(campusId)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IsNumberString, IsOptional } from 'class-validator'; | ||
|
||
export class FindAllEventsDto { | ||
@IsOptional() | ||
@IsNumberString({}, { each: true }) | ||
campusIds?: Array<number>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { Controller, Get, UseInterceptors } from '@nestjs/common'; | ||
import { Controller, Get, ParseArrayPipe, Query, UseInterceptors } from '@nestjs/common'; | ||
import { EventsService } from './events.service'; | ||
import { EventsToIcsInterceptor } from '../events-to-ics/events-to-ics.interceptor'; | ||
import { CALENDAR_NAME_ALL_EVENTS } from '../common/constants/calendars-name'; | ||
import { FindAllEventsDto } from './dto/find-all-events.dto'; | ||
|
||
@Controller('events') | ||
export class EventsController { | ||
constructor(private readonly eventsService: EventsService) {} | ||
|
||
@Get() | ||
@UseInterceptors(new EventsToIcsInterceptor({ name: CALENDAR_NAME_ALL_EVENTS })) | ||
findAll() { | ||
return this.eventsService.findAll(); | ||
findAll( | ||
@Query('campusIds', new ParseArrayPipe({ items: Number, separator: ',' })) campusIds: FindAllEventsDto['campusIds'], | ||
) { | ||
return this.eventsService.findAll({ campusIds }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
### GET all events | ||
{{base_url}}/events | ||
|
||
### GET all events from Paris campus | ||
{{base_url}}/events?campusIds=1 | ||
|
||
### GET all events from Paris and Málaga campuses | ||
{{base_url}}/events?campusIds=1,37 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { ValidationPipe } from '@nestjs/common'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, | ||
whitelist: true, | ||
}), | ||
); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |