Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pagination, modified events.controller and events.service in Fi… #21

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apps/backend/src/events/events.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { CreateEventDto } from './dto/create-event.dto';
Expand All @@ -17,8 +17,10 @@ export class EventsController {
}

@Get()
async findAll(): Promise<Event[]> {
return this.eventsService.findAll();
async findAll(@Query('skip') skip?: string, @Query('take') take?: string): Promise<Event[]> {
const skipVal = skip ? parseInt(skip, 10) : 0;
const takeVal = take ? parseInt(take, 10) : 10;
return this.eventsService.findAll(skipVal, takeVal);
}

@Get(':id')
Expand Down
10 changes: 8 additions & 2 deletions apps/backend/src/events/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ export class EventsService {
return await this.prisma.event.create({ data });
}

async findAll(): Promise<Event[]> {
return await this.prisma.event.findMany();
async findAll(skip = 0, take = 10): Promise<Event[]> {
return await this.prisma.event.findMany({
orderBy: {
endDate: 'desc',
},
skip,
take,
});
}

async findOne(id: string): Promise<Event> {
Expand Down