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