added concelation

This commit is contained in:
2026-01-27 13:48:32 -06:00
parent 5c08fc1c25
commit 99ccd9b457
2 changed files with 33 additions and 15 deletions
+14 -12
View File
@@ -1,10 +1,4 @@
import {
Controller,
Get,
Post,
Body,
Param,
} from '@nestjs/common';
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
import { BitacoraService } from './bitacora.service';
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
@@ -17,11 +11,6 @@ export class BitacoraController {
return this.bitacoraService.create(createBitacoraDto);
}
@Get()
findAll() {
return this.bitacoraService.findAll();
}
@Get('/cuenta/:id')
findOneByAcount(@Param('id') id: string) {
return this.bitacoraService.findOneByAcount(+id);
@@ -31,4 +20,17 @@ export class BitacoraController {
findOneByMachine(@Param('id') id: string) {
return this.bitacoraService.findOneByMachine(+id);
}
@Patch('cancelar/:id')
cancelationByMachine(
@Param('id') id: number,
@Body('tiempo_asignado') tiempo_asignado: number,
) {
return this.bitacoraService.cancelation(id, tiempo_asignado);
}
@Get(':id')
findAll(@Param('id') id: string) {
return this.bitacoraService.findAll();
}
}
+19 -3
View File
@@ -9,7 +9,7 @@ import { Repository } from 'typeorm';
export class BitacoraService {
constructor(
@InjectRepository(Bitacora)
private readonly bitacoraService: Repository<Bitacora>,
private readonly bitacoraRepository: Repository<Bitacora>,
) {}
create(createBitacoraDto: CreateBitacoraDto) {
return 'This action adds a new bitacora';
@@ -20,7 +20,7 @@ export class BitacoraService {
}
async findOneByAcount(id_cuenta: number) {
const student = await this.bitacoraService
const student = await this.bitacoraRepository
.createQueryBuilder('bitacora')
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
@@ -42,7 +42,7 @@ export class BitacoraService {
}
async findOneByMachine(ubicacion: number) {
const student = await this.bitacoraService
const student = await this.bitacoraRepository
.createQueryBuilder('bitacora')
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
@@ -63,4 +63,20 @@ export class BitacoraService {
return student;
}
async cancelation(id_bitacora: number, nuevoTiempo: number) {
const bitacora = await this.bitacoraRepository.findOne({
where: { id_bitacora },
});
if (!bitacora) {
throw new NotFoundException('alumno sin equipo asignado');
}
bitacora.tiempo_asignado -= nuevoTiempo;
await this.bitacoraRepository.save(bitacora);
return { message: 'Tiempo cancelado' };
}
}