Merge branch 'Lino' into Dev
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateStudentDto {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AlumnoSancion } from 'src/alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Recibo } from 'src/recibo/entities/recibo.entity';
|
||||
import {
|
||||
@@ -10,23 +11,6 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity({ name: 'carrera' })
|
||||
export class Carrera {
|
||||
@PrimaryGeneratedColumn({ name: 'id_carrera', type: 'int', unsigned: true })
|
||||
id_carrera: number;
|
||||
|
||||
@Column({
|
||||
name: 'carrera',
|
||||
type: 'varchar',
|
||||
length: 100,
|
||||
nullable: false,
|
||||
})
|
||||
carrera: string;
|
||||
|
||||
@OneToMany(() => Alumno, (student) => student.carrera)
|
||||
estudiantes: Alumno[];
|
||||
}
|
||||
|
||||
@Entity({ name: 'alumno' })
|
||||
export class Alumno {
|
||||
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
||||
import { AlumnoService } from './student.service';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
|
||||
@Controller('student')
|
||||
export class AlumnoController {
|
||||
|
||||
@@ -2,13 +2,14 @@ import { Module } from '@nestjs/common';
|
||||
import { AlumnoService } from './student.service';
|
||||
import { AlumnoController } from './student.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Alumno, Carrera } from './entities/student.entity';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Alumno,Carrera])],
|
||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera])],
|
||||
controllers: [AlumnoController],
|
||||
providers: [AlumnoService],
|
||||
exports:[AlumnoService]
|
||||
exports: [AlumnoService],
|
||||
})
|
||||
export class AlumnoModule {}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno, Carrera } from './entities/student.entity';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoService {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { CreateAlumnoInscritoDto } from './dto/create-alumno_inscrito.dto';
|
||||
import { UpdateAlumnoInscritoDto } from './dto/update-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { CreateAlumnoInscritoDto } from './dto/create-alumno_inscrito.dto';
|
||||
import { UpdateAlumnoInscritoDto } from './dto/update-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
+8
-2
@@ -9,7 +9,7 @@ import { Perfil, User } from './user/entities/user.entity';
|
||||
import { DetalleServicioModule } from './detalle_servicio/detalle_servicio.module';
|
||||
import { PeriodoModule } from './periodo/periodo.module';
|
||||
import { ServicioModule } from './servicio/servicio.module';
|
||||
import { Alumno, Carrera } from './alumno/entities/student.entity';
|
||||
import { Alumno } from './alumno/entities/student.entity';
|
||||
import { DetalleServicio } from './detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Periodo } from './periodo/entities/periodo.entity';
|
||||
import { Servicio } from './servicio/entities/servicio.entity';
|
||||
@@ -23,8 +23,13 @@ import { ReciboModule } from './recibo/recibo.module';
|
||||
import { MesaModule } from './mesa/mesa.module';
|
||||
import { Mesa } from './mesa/entities/mesa.entity';
|
||||
import { AlumnoInscritoModule } from './alumno_inscrito/alumno_inscrito.module';
|
||||
import { AlumnoInscrito, Plataforma } from './alumno_inscrito/entities/alumno_inscrito.entity';
|
||||
import {
|
||||
AlumnoInscrito,
|
||||
Plataforma,
|
||||
} from './alumno_inscrito/entities/alumno_inscrito.entity';
|
||||
import { EquipoModule } from './equipo/equipo.module';
|
||||
import { CarreraModule } from './carrera/carrera.module';
|
||||
import { Carrera } from './carrera/entities/carrera.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -71,6 +76,7 @@ import { EquipoModule } from './equipo/equipo.module';
|
||||
MesaModule,
|
||||
AlumnoInscritoModule,
|
||||
EquipoModule,
|
||||
CarreraModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { CarreraService } from './carrera.service';
|
||||
|
||||
@Controller('carrera')
|
||||
export class CarreraController {
|
||||
constructor(private readonly carreraService: CarreraService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.carreraService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CarreraService } from './carrera.service';
|
||||
import { CarreraController } from './carrera.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Carrera } from './entities/carrera.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Carrera])],
|
||||
controllers: [CarreraController],
|
||||
providers: [CarreraService],
|
||||
})
|
||||
export class CarreraModule {}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Carrera } from './entities/carrera.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CarreraService {
|
||||
constructor(
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carreraRepository: Repository<Carrera>,
|
||||
) {}
|
||||
findAll() {
|
||||
return this.carreraRepository.find();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateCarreraDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateCarreraDto } from './create-carrera.dto';
|
||||
|
||||
export class UpdateCarreraDto extends PartialType(CreateCarreraDto) {}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'carrera' })
|
||||
export class Carrera {
|
||||
@PrimaryGeneratedColumn({ name: 'id_carrera', type: 'int', unsigned: true })
|
||||
id_carrera: number;
|
||||
|
||||
@Column({
|
||||
name: 'carrera',
|
||||
type: 'varchar',
|
||||
length: 100,
|
||||
nullable: false,
|
||||
})
|
||||
carrera: string;
|
||||
|
||||
@OneToMany(() => Alumno, (student) => student.carrera)
|
||||
estudiantes: Alumno[];
|
||||
}
|
||||
@@ -7,11 +7,6 @@ import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createEquipoDto: CreateEquipoDto) {
|
||||
return this.equipoService.create(createEquipoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.equipoService.findAll();
|
||||
@@ -21,14 +16,4 @@ export class EquipoController {
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.equipoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateEquipoDto: UpdateEquipoDto) {
|
||||
return this.equipoService.update(+id, updateEquipoDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.equipoService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { EquipoController } from './equipo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Equipo])],
|
||||
controllers: [EquipoController],
|
||||
providers: [EquipoService],
|
||||
})
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
|
||||
@Injectable()
|
||||
export class EquipoService {
|
||||
create(createEquipoDto: CreateEquipoDto) {
|
||||
return 'This action adds a new equipo';
|
||||
}
|
||||
constructor(@InjectRepository(Equipo)
|
||||
private readonly equipoRepository: Repository<Equipo>){}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all equipo`;
|
||||
return this.equipoRepository.find();
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} equipo`;
|
||||
}
|
||||
|
||||
update(id: number, updateEquipoDto: UpdateEquipoDto) {
|
||||
return `This action updates a #${id} equipo`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} equipo`;
|
||||
findOne(id_equipo: number) {
|
||||
return this.equipoRepository.findOne({where:{id_equipo}});
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -10,11 +10,10 @@ async function bootstrap() {
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
|
||||
app.enableCors(
|
||||
{
|
||||
origin: configService.get<string>('Front_URL'),
|
||||
}
|
||||
// {
|
||||
// origin: configService.get<string>('Front_URL'),
|
||||
// }
|
||||
);
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -4,6 +4,11 @@ import { SancionService } from './sancion.service';
|
||||
export class SancionController {
|
||||
constructor(private readonly sancionService: SancionService) {}
|
||||
|
||||
@Get()
|
||||
find() {
|
||||
return this.sancionService.find();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.sancionService.findOne(+id);
|
||||
|
||||
@@ -10,6 +10,10 @@ export class SancionService {
|
||||
private readonly sancionRepository: Repository<Sancion>,
|
||||
) {}
|
||||
|
||||
async find(){
|
||||
return this.sancionRepository.find()
|
||||
}
|
||||
|
||||
async findOne(id_sancion: number): Promise<Sancion> {
|
||||
const sancion = await this.sancionRepository.findOne({
|
||||
where: { id_sancion },
|
||||
|
||||
+10
-2
@@ -1,5 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
// jwt-auth.guard.ts
|
||||
import { ExecutionContext, Injectable, ForbiddenException } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||
handleRequest(err: any, user: any, info: any, context: ExecutionContext) {
|
||||
if (err || !user) {
|
||||
throw new ForbiddenException('Acceso denegado: token inválido o ausente');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
// jwt.strategy.ts
|
||||
import { Injectable, ForbiddenException } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
export interface JwtPayload {
|
||||
id: string;
|
||||
usuario: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private configService: ConfigService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: configService.get('JWT_SECRET')!,
|
||||
secretOrKey: configService.get<string>('JWT_SECRET')!,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
async validate(payload: JwtPayload) {
|
||||
if (!payload || !payload.id || !payload.usuario) {
|
||||
throw new ForbiddenException('Token inválido o corrupto');
|
||||
}
|
||||
return { id: payload.id, usuario: payload.usuario };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
|
||||
@Controller('user')
|
||||
@@ -23,7 +22,7 @@ export class UserController {
|
||||
return this.userService.Login(data, res);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/validate-token')
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
@@ -35,7 +34,7 @@ export class UserController {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/change-password')
|
||||
@Post('/changePassword')
|
||||
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
||||
const id_usuario = req.user.id;
|
||||
await this.userService.changePassword(data, id_usuario);
|
||||
|
||||
Reference in New Issue
Block a user