Merge branch 'Lino' of https://repositorio.acatlan.unam.mx/mcervantesag/api_directorio into Lino
This commit is contained in:
@@ -2,10 +2,6 @@ import { IsBoolean, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional, Length} f
|
||||
|
||||
export class profesorDto{
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_profesor: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_usuario: number;
|
||||
@@ -78,10 +74,10 @@ export class profesorDto{
|
||||
fotografia: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
activo: boolean = false;
|
||||
@IsOptional()
|
||||
activo: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
mostrar: boolean = true;
|
||||
@IsOptional()
|
||||
mostrar: boolean;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import { IsOptional, IsString, IsInt, IsBoolean } from 'class-validator';
|
||||
|
||||
export class ProfesorFilterDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
nombre?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
id_categoria?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
id_carrera?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
extension?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
id_adscripcion?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
id_edificio?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
activo?: boolean;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
@@ -16,7 +16,7 @@ import { User } from 'src/users/entities/user.entity';
|
||||
|
||||
@Entity()
|
||||
export class Profesor {
|
||||
@PrimaryColumn({ type: 'int', nullable: false })
|
||||
@PrimaryGeneratedColumn()
|
||||
id_profesor: number;
|
||||
|
||||
@Column({ type: 'int',nullable: false })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common';
|
||||
import { ProfesorService } from './profesor.service';
|
||||
import { profesorDto } from './dto/profesorDto.dto';
|
||||
|
||||
@@ -16,6 +16,14 @@ export class ProfesorController {
|
||||
return this.profesorService.findAll();
|
||||
}
|
||||
|
||||
@Get('page')
|
||||
findAllPaginated(@Query('page') page: number = 1, @Query('limit') limit: number = 10) {
|
||||
page = page < 1 ? 1 : page;
|
||||
limit = limit > 10 || limit < 1 ? 10 : limit; // Limitar el límite máximo a 10 por página
|
||||
|
||||
return this.profesorService.findAllPaginated(page, limit);
|
||||
}
|
||||
|
||||
@Put(':id_profesor')
|
||||
async postModify(@Param('id_profesor', ParseIntPipe) id_profesor: number, @Body() data: profesorDto) {
|
||||
return this.profesorService.modify(id_profesor, data);
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Profesor } from './entities/profesor.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { profesorDto } from './dto/profesorDto.dto';
|
||||
import { ProfesorFilterDto } from './dto/profesorFilterDto.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ProfesorService {
|
||||
@@ -31,7 +30,11 @@ export class ProfesorService {
|
||||
|
||||
//brings all teachers
|
||||
async findAll(): Promise<Profesor[]> {
|
||||
return this.profesorRepository.find();
|
||||
return this.profesorRepository.find({
|
||||
order: {
|
||||
nombre: 'ASC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//modify teacher
|
||||
@@ -96,4 +99,18 @@ 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',
|
||||
},
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return { profesores, total, totalPages };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Put('Modificacion/:id')
|
||||
async update(@Param('id') userId: number, @Body() updateUserDto: Record<string, any>) {
|
||||
return this.authService.update(userId, updateUserDto);
|
||||
async update(@Param('id') userId: number, @Body() data: registerDto) {
|
||||
return this.authService.update(userId, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
|
||||
@@ -65,16 +65,17 @@ export class AuthService {
|
||||
return { token: token };
|
||||
}
|
||||
|
||||
async update(userId, updateUserDto) {
|
||||
//update user
|
||||
async update(userId, data:registerDto) {
|
||||
|
||||
const{contraseña}=updateUserDto;
|
||||
const{contraseña}=data;
|
||||
|
||||
if(contraseña){
|
||||
const hashedpassword = await hash(contraseña, 10);
|
||||
updateUserDto = {...updateUserDto,contraseña:hashedpassword};
|
||||
data = {...data,contraseña:hashedpassword};
|
||||
}
|
||||
|
||||
return await this.userRepository.update(userId, updateUserDto);
|
||||
return await this.userRepository.update(userId, data);
|
||||
}
|
||||
|
||||
async remove(userId: number): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user