added new EP
This commit is contained in:
@@ -7,9 +7,10 @@ import { OperationsService } from './operations.services';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Alumno, DetalleServicio]), // entidades que usarán las transacciones
|
||||
TypeOrmModule.forFeature([Alumno, DetalleServicio]),
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
})
|
||||
export class OperationsModule {}
|
||||
//IO
|
||||
@@ -93,6 +93,6 @@ export class Alumno {
|
||||
@JoinColumn({ name: 'id_carrera' })
|
||||
carrera: Carrera;
|
||||
|
||||
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.id_cuenta)
|
||||
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
|
||||
sanciones: AlumnoSancion[];
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
|
||||
@Controller('student')
|
||||
export class StudentController {
|
||||
export class AlumnoController {
|
||||
constructor(private readonly alumnoService: AlumnoService) {}
|
||||
|
||||
@Post()
|
||||
@@ -22,3 +22,4 @@ export class StudentController {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AlumnoService } from './student.service';
|
||||
import { StudentController } from './student.controller';
|
||||
import { AlumnoController } from './student.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Alumno])],
|
||||
controllers: [StudentController],
|
||||
controllers: [AlumnoController],
|
||||
providers: [AlumnoService],
|
||||
exports:[AlumnoService]
|
||||
})
|
||||
export class StudentModule {}
|
||||
export class AlumnoModule {}
|
||||
//IO
|
||||
@@ -50,3 +50,4 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -1,16 +1,13 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
|
||||
@Controller('alumno-sancion')
|
||||
export class AlumnoSancionController {
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Body() createAlumnoSancionDto: CreateAlumnoSancionDto,
|
||||
): Promise<AlumnoSancion> {
|
||||
async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@@ -24,3 +21,4 @@ export class AlumnoSancionController {
|
||||
return this.alumnoSancionService.findOne(+id);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -5,10 +5,18 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { SancionModule } from 'src/sancion/sancion.module';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([AlumnoSancion,Alumno,Sancion])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]),
|
||||
AlumnoModule,
|
||||
SancionModule,
|
||||
],
|
||||
controllers: [AlumnoSancionController],
|
||||
providers: [AlumnoSancionService],
|
||||
})
|
||||
export class AlumnoSancionModule {}
|
||||
//IO
|
||||
|
||||
@@ -3,25 +3,35 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
import { SancionService } from 'src/sancion/sancion.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoSancionService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoSancion)
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
|
||||
private readonly alumnoService: AlumnoService,
|
||||
private readonly sancionService: SancionService,
|
||||
) {}
|
||||
|
||||
async create(
|
||||
createAlumnoSancionDto: CreateAlumnoSancionDto,
|
||||
): Promise<AlumnoSancion> {
|
||||
) {
|
||||
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
||||
|
||||
// Crear la entidad con relaciones
|
||||
const alumno = await this.alumnoService.findOne(id_cuenta);
|
||||
const sancion = await this.sancionService.findOne(id_sancion);
|
||||
|
||||
if (!alumno)
|
||||
throw new NotFoundException(`Alumno ${id_cuenta} no encontrado`);
|
||||
if (!sancion)
|
||||
throw new NotFoundException(`Sancion ${id_sancion} no encontrada`);
|
||||
|
||||
const alumnosancion = this.alumnosancionRepository.create({
|
||||
id_sancion: { id_sancion }, // se asigna por FK
|
||||
id_cuenta: { id_cuenta }, // se asigna por FK
|
||||
alumno,
|
||||
sancion,
|
||||
});
|
||||
|
||||
return await this.alumnosancionRepository.save(alumnosancion);
|
||||
@@ -33,7 +43,7 @@ export class AlumnoSancionService {
|
||||
|
||||
async findOne(id_cuenta: number): Promise<AlumnoSancion> {
|
||||
const alusancion = await this.alumnosancionRepository.findOne({
|
||||
where: { id_cuenta: { id_cuenta } },
|
||||
where: { alumno: { id_cuenta } },
|
||||
});
|
||||
if (!alusancion) {
|
||||
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
||||
@@ -41,3 +51,4 @@ export class AlumnoSancionService {
|
||||
return alusancion;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -23,15 +23,15 @@ export class AlumnoSancion {
|
||||
|
||||
@ManyToOne(() => Alumno, (student) => student.sanciones, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
nullable: false,
|
||||
})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
id_cuenta: Alumno;
|
||||
alumno: Alumno;
|
||||
|
||||
@ManyToOne(() => Sancion, (sancion) => sancion.sancion, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
nullable: false,
|
||||
})
|
||||
@JoinColumn({ name: 'id_sancion' })
|
||||
id_sancion: Sancion;
|
||||
sancion: Sancion;
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { StudentModule } from './alumno/student.module';
|
||||
import { AlumnoModule } from './alumno/student.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
import { Perfil, User } from './user/entities/user.entity';
|
||||
import { DetalleServicioModule } from './detalle_servicio/detalle_servicio.module';
|
||||
@@ -48,11 +48,10 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
}),
|
||||
}),
|
||||
UserModule,
|
||||
StudentModule,
|
||||
AlumnoModule,
|
||||
DetalleServicioModule,
|
||||
PeriodoModule,
|
||||
ServicioModule,
|
||||
StudentModule,
|
||||
SancionModule,
|
||||
AlumnoSancionModule,
|
||||
],
|
||||
@@ -60,3 +59,4 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
//IO
|
||||
@@ -14,7 +14,7 @@ export class Sancion {
|
||||
|
||||
@OneToMany(
|
||||
() => AlumnoSancion,
|
||||
(alusancion) => alusancion.id_sancion,
|
||||
(alusancion) => alusancion.sancion,
|
||||
)
|
||||
alumnosSancionados: AlumnoSancion[];
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SancionService } from './sancion.service';
|
||||
import { SancionController } from './sancion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Sancion } from './entities/sancion.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Sancion])],
|
||||
controllers: [SancionController],
|
||||
providers: [SancionService],
|
||||
exports:[SancionService],
|
||||
})
|
||||
export class SancionModule {}
|
||||
//IO
|
||||
@@ -1,9 +1,16 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateSancionDto } from './dto/create-sancion.dto';
|
||||
import { UpdateSancionDto } from './dto/update-sancion.dto';
|
||||
import { Sancion } from './entities/sancion.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class SancionService {
|
||||
constructor(
|
||||
@InjectRepository(Sancion)
|
||||
private readonly sancionRepository: Repository<Sancion>
|
||||
){}
|
||||
create(createSancionDto: CreateSancionDto) {
|
||||
return 'This action adds a new sancion';
|
||||
}
|
||||
@@ -12,8 +19,14 @@ export class SancionService {
|
||||
return `This action returns all sancion`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} sancion`;
|
||||
async findOne(id_sancion: number): Promise<Sancion> {
|
||||
const sancion = await this.sancionRepository.findOne({
|
||||
where: { id_sancion },
|
||||
});
|
||||
if (!sancion) {
|
||||
throw new NotFoundException(`Sancion not found`);
|
||||
}
|
||||
return sancion;
|
||||
}
|
||||
|
||||
update(id: number, updateSancionDto: UpdateSancionDto) {
|
||||
@@ -24,3 +37,4 @@ export class SancionService {
|
||||
return `This action removes a #${id} sancion`;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -17,8 +17,8 @@ export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto) {
|
||||
return this.userService.Login(data);
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
|
||||
@@ -11,6 +11,7 @@ export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
@@ -21,14 +22,26 @@ export class UserService {
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(`El usuario ${usuario} no fue encontrado`);
|
||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto) {
|
||||
async Login(data: CreateUserDto, res: Response) {
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
return user;
|
||||
|
||||
const payload = { id: user.id_usuario, usuario: user.usuario };
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
res.cookie('token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // en dev desactívalo
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return res.json({ message: 'Inicio de sesión exitoso' });
|
||||
}
|
||||
}
|
||||
//IO
|
||||
Reference in New Issue
Block a user