added new Ep
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateStudentDto {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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