Merge branch 'Lino' of https://repositorio.acatlan.unam.mx/mcervantesag/api_directorio into Sam
This commit is contained in:
@@ -17,11 +17,11 @@ export class ProfesorController {
|
||||
}
|
||||
|
||||
@Get('page')
|
||||
findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10) {
|
||||
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; // Limitar el límite máximo a 10 por página
|
||||
limit = limit > 10 || limit < 1 ? 10 : limit;
|
||||
|
||||
return this.profesorService.findAllPaginated(page, limit);
|
||||
return this.profesorService.findAllPaginated(page, limit, filters);
|
||||
}
|
||||
|
||||
@Put(':id_profesor')
|
||||
|
||||
@@ -100,14 +100,30 @@ export class ProfesorService {
|
||||
return query.getMany();
|
||||
}
|
||||
|
||||
async findAllPaginated(page: number, limit: number): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const [profesores, total] = await this.profesorRepository.findAndCount({
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
order: {
|
||||
nombre: 'ASC',
|
||||
},
|
||||
});
|
||||
async findAllPaginated(page: number, limit: number, filters: any): Promise<{ profesores: Profesor[], total: number, totalPages: number }> {
|
||||
const query = this.profesorRepository.createQueryBuilder('profesor');
|
||||
|
||||
if (filters.nombre) {
|
||||
query.andWhere('profesor.nombre LIKE :nombre', { nombre: `%${filters.nombre}%` });
|
||||
}
|
||||
|
||||
if (filters.adscripcion) {
|
||||
query.andWhere('profesor.adscripcion = :adscripcion', { adscripcion: filters.adscripcion });
|
||||
}
|
||||
|
||||
if (filters.categoria) {
|
||||
query.andWhere('profesor.categoria = :categoria', { categoria: filters.categoria });
|
||||
}
|
||||
|
||||
if (filters.edificio) {
|
||||
query.andWhere('profesor.edificio = :edificio', { edificio: filters.edificio });
|
||||
}
|
||||
|
||||
const [profesores, total] = await query
|
||||
.skip((page - 1) * limit)
|
||||
.take(limit)
|
||||
.orderBy('profesor.nombre', 'ASC')
|
||||
.getManyAndCount();
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AdscripcionService } from './adscripcion.service';
|
||||
|
||||
@Controller('adscripcion')
|
||||
export class AdscripcionController {
|
||||
constructor(private readonly adscripcionService: AdscripcionService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.adscripcionService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Adscripcion } from './entities/adscripcion.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AdscripcionService {
|
||||
constructor(
|
||||
@InjectRepository(Adscripcion)
|
||||
private adscripcionRepository: Repository<Adscripcion>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Adscripcion[]> {
|
||||
return this.adscripcionRepository.find();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AdscripcionController } from './adscripcion.controller'; // Asumiendo que el controlador se llama EdificioController
|
||||
|
||||
describe('EdificioController', () => {
|
||||
let controller: AdscripcionController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AdscripcionController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AdscripcionController>(AdscripcionController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AdscripcionService } from './adscripcion.service'; // Asegúrate de importar el servicio correcto
|
||||
|
||||
describe('EdificioService', () => {
|
||||
let service: AdscripcionService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AdscripcionService], // Asegúrate de incluir el servicio correcto aquí
|
||||
}).compile();
|
||||
|
||||
service = module.get<AdscripcionService>(AdscripcionService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { CategoriaService } from './categoria.service';
|
||||
|
||||
@Controller('categoria')
|
||||
export class CategoriaController {
|
||||
constructor(private readonly categoriaService: CategoriaService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.categoriaService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Categoria } from './entities/categoria.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CategoriaService {
|
||||
constructor(
|
||||
@InjectRepository(Categoria)
|
||||
private categoriaRepository: Repository<Categoria>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Categoria[]> {
|
||||
return this.categoriaRepository.find();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CategoriaController } from './categiria.controller'; // Asumiendo que el controlador se llama EdificioController
|
||||
|
||||
describe('EdificioController', () => {
|
||||
let controller: CategoriaController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CategoriaController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CategoriaController>(CategoriaController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CategoriaService } from './categoria.service'; // Asegúrate de importar el servicio correcto
|
||||
|
||||
describe('EdificioService', () => {
|
||||
let service: CategoriaService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CategoriaService], // Asegúrate de incluir el servicio correcto aquí
|
||||
}).compile();
|
||||
|
||||
service = module.get<CategoriaService>(CategoriaService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EdificioController } from './edificio.controller'; // Asumiendo que el controlador se llama EdificioController
|
||||
|
||||
describe('EdificioController', () => {
|
||||
let controller: EdificioController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [EdificioController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<EdificioController>(EdificioController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { EdificioService } from './edificio.service';
|
||||
|
||||
@Controller('categoria')
|
||||
export class EdificioController {
|
||||
constructor(private readonly edificioService: EdificioService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.edificioService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EdificioService } from './edificio.service'; // Asegúrate de importar el servicio correcto
|
||||
|
||||
describe('EdificioService', () => {
|
||||
let service: EdificioService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [EdificioService], // Asegúrate de incluir el servicio correcto aquí
|
||||
}).compile();
|
||||
|
||||
service = module.get<EdificioService>(EdificioService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Edificio } from './entities/edificio.entity';
|
||||
|
||||
@Injectable()
|
||||
export class EdificioService {
|
||||
constructor(
|
||||
@InjectRepository(Edificio)
|
||||
private categoriaRepository: Repository<Edificio>,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Edificio[]> {
|
||||
return this.categoriaRepository.find();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user