Skip to content

Commit

Permalink
added pagination, modified events.controller and events.service in Fi… (
Browse files Browse the repository at this point in the history
#21)

* added pagination, modified events.controller and events.service in FindAll() function

* fixed issue with feature/17

* added the missing required:false flag

* fix prettier

---------

Co-authored-by: Sámuel Fekete <[email protected]>
  • Loading branch information
pem00 and Tschonti authored Aug 11, 2024
1 parent b4f5ff3 commit 73498f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
26 changes: 22 additions & 4 deletions apps/backend/src/events/events.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { CurrentUser } from '@kir-dev/passport-authsch';
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
DefaultValuePipe,
Delete,
Get,
Param,
ParseIntPipe,
ParseUUIDPipe,
Patch,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';
import { User } from 'src/users/entities/user.entity';

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

@Get()
async findAll(): Promise<Event[]> {
return this.eventsService.findAll();
@ApiQuery({ name: 'skip', required: false, type: Number })
@ApiQuery({ name: 'take', required: false, type: Number })
async findAll(
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip?: number,
@Query('take', new DefaultValuePipe(10), ParseIntPipe) take?: number
): Promise<Event[]> {
return this.eventsService.findAll(take, skip);
}

@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 @@ -19,8 +19,14 @@ export class EventsService {
});
}

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

0 comments on commit 73498f8

Please sign in to comment.