added Inscription
This commit is contained in:
@@ -21,12 +21,12 @@ export class OperationsController {
|
||||
return this.operationsService.addCredit(data, id_usuario);
|
||||
}
|
||||
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
// @Post('registration')
|
||||
// async addReceiptInscription(@Body() data, @Req() req: any) {
|
||||
// const id_usuario = req.user.id;
|
||||
// return this.operationsService.addReceiptInscription(data, id_usuario);
|
||||
// }
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('registration')
|
||||
async addReceiptInscription(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addReceiptInscription(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('time')
|
||||
|
||||
@@ -9,6 +9,7 @@ import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
import { ReciboModule } from 'src/recibo/recibo.module';
|
||||
import { AlumnoInscritoModule } from 'src/alumno_inscrito/alumno_inscrito.module';
|
||||
import { PeriodoModule } from 'src/periodo/periodo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -17,7 +18,8 @@ import { AlumnoInscritoModule } from 'src/alumno_inscrito/alumno_inscrito.module
|
||||
AlumnoModule,
|
||||
UserModule,
|
||||
ReciboModule,
|
||||
AlumnoInscritoModule
|
||||
AlumnoInscritoModule,
|
||||
PeriodoModule,
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
|
||||
@@ -10,6 +10,7 @@ import { chargePrintDto } from './dto/operations.dto';
|
||||
import { UserService } from 'src/user/user.service';
|
||||
import { ReciboService } from 'src/recibo/recibo.service';
|
||||
import { AlumnoInscritoService } from 'src/alumno_inscrito/alumno_inscrito.service';
|
||||
import { PeriodoService } from 'src/periodo/periodo.service';
|
||||
|
||||
@Injectable()
|
||||
export class OperationsService {
|
||||
@@ -20,6 +21,7 @@ export class OperationsService {
|
||||
private readonly detalleServicioService: DetalleServicioService,
|
||||
private readonly userService: UserService,
|
||||
private readonly reciboService: ReciboService,
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
|
||||
async chargePrint(data: chargePrintDto, id_usuario: number) {
|
||||
@@ -109,13 +111,7 @@ export class OperationsService {
|
||||
}
|
||||
|
||||
async addTime(data, id_usuario: number) {
|
||||
const {
|
||||
monto,
|
||||
id_cuenta,
|
||||
idPlataforma,
|
||||
folio_recibo,
|
||||
fecha_recibo,
|
||||
} = data;
|
||||
const { monto, id_cuenta, idPlataforma, folio_recibo, fecha_recibo } = data;
|
||||
|
||||
const studentRegister = await this.alumnoInscritoService.findRegister(
|
||||
id_cuenta,
|
||||
@@ -161,7 +157,68 @@ export class OperationsService {
|
||||
);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return { studentRegister};
|
||||
return { studentRegister };
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw new InternalServerErrorException(error.message);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async addReceiptInscription(data, id_usuario: number) {
|
||||
const {
|
||||
monto,
|
||||
id_cuenta,
|
||||
id_plataforma,
|
||||
folio_recibo,
|
||||
fecha_recibo,
|
||||
realizo_pago,
|
||||
} = data;
|
||||
|
||||
await this.alumnoInscritoService.findNotRegister(id_cuenta, id_plataforma);
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
try {
|
||||
const detalleRecibo = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleRecibo, queryRunner.manager);
|
||||
|
||||
const detalleData = {
|
||||
servicio: 4,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
detalleData,
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
const plataforma =
|
||||
await this.alumnoInscritoService.findPlataformaById(id_plataforma);
|
||||
|
||||
await this.alumnoInscritoService.create(
|
||||
{ realizo_pago, alumno: alum, plataforma, periodo },
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw new InternalServerErrorException(error.message);
|
||||
|
||||
@@ -10,10 +10,10 @@ import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
|
||||
@Post()
|
||||
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
return this.alumnoInscritoService.create(dto);
|
||||
}
|
||||
// @Post()
|
||||
// async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
// return this.alumnoInscritoService.create(dto);
|
||||
// }
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
|
||||
@@ -19,32 +19,33 @@ export class AlumnoInscritoService {
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
|
||||
async create(dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
const periodoActivo = await this.periodoService.getPeriodoActivo();
|
||||
//Borrar
|
||||
// async createBorrar(dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
// const periodoActivo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const existing = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta: dto.id_cuenta },
|
||||
periodo: { id_periodo: periodoActivo.id_periodo },
|
||||
plataforma: { id_plataforma: dto.id_plataforma },
|
||||
},
|
||||
});
|
||||
// const existing = await this.alumnoInscritoRepo.findOne({
|
||||
// where: {
|
||||
// alumno: { id_cuenta: dto.id_cuenta },
|
||||
// periodo: { id_periodo: periodoActivo.id_periodo },
|
||||
// plataforma: { id_plataforma: dto.id_plataforma },
|
||||
// },
|
||||
// });
|
||||
|
||||
if (existing) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya está inscrito en este periodo y plataforma',
|
||||
);
|
||||
}
|
||||
// if (existing) {
|
||||
// throw new BadRequestException(
|
||||
// 'El alumno ya está inscrito en este periodo y plataforma',
|
||||
// );
|
||||
// }
|
||||
|
||||
const alumnoInscrito = this.alumnoInscritoRepo.create({
|
||||
realizo_pago: dto.realizo_pago ?? false,
|
||||
alumno: { id_cuenta: dto.id_cuenta },
|
||||
plataforma: { id_plataforma: dto.id_plataforma },
|
||||
periodo: periodoActivo,
|
||||
});
|
||||
// const alumnoInscrito = this.alumnoInscritoRepo.create({
|
||||
// realizo_pago: dto.realizo_pago ?? false,
|
||||
// alumno: { id_cuenta: dto.id_cuenta },
|
||||
// plataforma: { id_plataforma: dto.id_plataforma },
|
||||
// periodo: periodoActivo,
|
||||
// });
|
||||
|
||||
return this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
}
|
||||
// return this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
// }
|
||||
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoRepo.find({
|
||||
@@ -57,6 +58,10 @@ export class AlumnoInscritoService {
|
||||
return this.plataformaRepo.find();
|
||||
}
|
||||
|
||||
async findPlataformaById(id_plataforma:number) {
|
||||
return this.plataformaRepo.findOne({where:{id_plataforma}});
|
||||
}
|
||||
|
||||
async findById(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
const students = await this.alumnoInscritoRepo
|
||||
.createQueryBuilder('ai')
|
||||
@@ -95,16 +100,19 @@ export class AlumnoInscritoService {
|
||||
return { message: 'Plática marcada correctamente' };
|
||||
}
|
||||
|
||||
async findRegister(id_cuenta: number, id_plataforma: number):Promise<AlumnoInscrito> {
|
||||
async findRegister(
|
||||
id_cuenta: number,
|
||||
id_plataforma: number,
|
||||
): Promise<AlumnoInscrito> {
|
||||
const periodoActivo = await this.periodoService.getPeriodoActivo();
|
||||
console.log(id_cuenta)
|
||||
|
||||
const student = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta },
|
||||
plataforma: { id_plataforma },
|
||||
periodo: { id_periodo: periodoActivo.id_periodo },
|
||||
},
|
||||
relations:['alumno','periodo','plataforma']
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
@@ -112,10 +120,28 @@ console.log(id_cuenta)
|
||||
'No existe inscripción en el periodo y plataforma actual',
|
||||
);
|
||||
}
|
||||
console.log(student)
|
||||
return student;
|
||||
}
|
||||
|
||||
async findNotRegister(id_cuenta: number, id_plataforma: number) {
|
||||
const periodoActivo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const student = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta },
|
||||
plataforma: { id_plataforma },
|
||||
periodo: { id_periodo: periodoActivo.id_periodo },
|
||||
},
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
|
||||
if (student) {
|
||||
throw new Error(
|
||||
'El alumno ya está inscrito en este periodo y plataforma',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Borrar
|
||||
async addTimeBorrar(
|
||||
idCuenta: number,
|
||||
@@ -143,8 +169,14 @@ console.log(id_cuenta)
|
||||
return await this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
}
|
||||
|
||||
async save(data, manager: EntityManager) {
|
||||
const repo = manager.getRepository(AlumnoInscrito);
|
||||
return await repo.save(data);
|
||||
}
|
||||
async save(data, manager: EntityManager) {
|
||||
const repo = manager.getRepository(AlumnoInscrito);
|
||||
return await repo.save(data);
|
||||
}
|
||||
|
||||
async create(data, manager: EntityManager) {
|
||||
const repo = manager.getRepository(AlumnoInscrito);
|
||||
const create = repo.create(data);
|
||||
return await repo.save(create);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user