fixed auth
This commit is contained in:
@@ -10,7 +10,8 @@ import {
|
||||
Request,
|
||||
UseGuards,
|
||||
Delete,
|
||||
ParseIntPipe
|
||||
ParseIntPipe,
|
||||
Query
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from './auth.guard';
|
||||
import { AuthService } from './auth.service';
|
||||
@@ -75,4 +76,12 @@ export class AuthController {
|
||||
return this.authService.profile(id_user);
|
||||
}
|
||||
|
||||
@Get('page')
|
||||
findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10, @Query() filters: any) {
|
||||
page = page < 1 ? 1 : page;
|
||||
limit = limit > 10 || limit < 1 ? 10 : limit;
|
||||
|
||||
return this.authService.findAllPaginated(page, limit);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,4 +124,21 @@ export class AuthService {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async findAllPaginated(
|
||||
page: number,
|
||||
limit: number,
|
||||
): Promise<{ profesores: User[], total: number, totalPages: number }> {
|
||||
const query = this.userRepository.createQueryBuilder('profesor')
|
||||
|
||||
const [profesores, total] = await query
|
||||
.skip((page - 1) * limit)
|
||||
.take(limit)
|
||||
.orderBy('profesor.nombre', 'ASC')
|
||||
.getManyAndCount();
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return { profesores, total, totalPages };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user