entrega y regreso a espera de pruebas
This commit is contained in:
parent
585cc1e8e5
commit
582942d3a6
@ -1,6 +1,6 @@
|
||||
import { IsInt } from 'class-validator';
|
||||
|
||||
export class PrestamoCancelarOperadorDto {
|
||||
export class PrestamoUpdateOperadorDto {
|
||||
@IsInt()
|
||||
id_operador: number;
|
||||
|
@ -9,7 +9,7 @@ import { PrestamoNumeroInventarioDto } from './dto/prestamo-numero-inventario.dt
|
||||
import { PrestamoHistorialEquipoDto } from './dto/prestamo-historial-equipo.dto';
|
||||
import { PrestamoHistorialUsuarioDto } from './dto/prestamo-historial-usuario.dto';
|
||||
import { PrestamoHistorialDto } from './dto/prestamo-historial.dto';
|
||||
import { PrestamoCancelarOperadorDto } from './dto/prestamo-cancelar-operador.dto';
|
||||
import { PrestamoUpdateOperadorDto } from './dto/prestamo-update-operador.dto';
|
||||
import { PrestamoCancelarUsuarioDto } from './dto/prestamo-cancelar-usuario.dto';
|
||||
|
||||
@Controller('prestamo')
|
||||
@ -87,7 +87,7 @@ export class PrestamoController {
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 1 } } },
|
||||
})
|
||||
cancelarOperador(@Body() body: PrestamoCancelarOperadorDto) {
|
||||
cancelarOperador(@Body() body: PrestamoUpdateOperadorDto) {
|
||||
return this.prestamoService.cancelarOperador(
|
||||
body.id_prestamo,
|
||||
body.id_operador,
|
||||
@ -110,7 +110,13 @@ export class PrestamoController {
|
||||
@ApiOperation({
|
||||
description: 'Endpoint que actualiza el status del equipo a "En uso".',
|
||||
})
|
||||
entregar() {}
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 4 } } },
|
||||
})
|
||||
entregar(@Body() body: PrestamoUpdateOperadorDto) {
|
||||
return this.prestamoService.entregar(body.id_prestamo, body.id_operador);
|
||||
}
|
||||
|
||||
@Get('historial')
|
||||
@ApiOperation({
|
||||
@ -301,8 +307,14 @@ export class PrestamoController {
|
||||
}
|
||||
|
||||
@Put('regresar')
|
||||
@ApiOperation({ description: 'Endpoint .' })
|
||||
regresar() {}
|
||||
@ApiOperation({ description: 'Endpoint que desactiva un préstamo.' })
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 4 } } },
|
||||
})
|
||||
regresar(@Body() body: PrestamoUpdateOperadorDto) {
|
||||
return this.prestamoService.regresar(body.id_prestamo, body.id_operador);
|
||||
}
|
||||
|
||||
// @Get('reporte')
|
||||
// reporte() {}
|
||||
|
@ -137,6 +137,43 @@ export class PrestamoService {
|
||||
);
|
||||
}
|
||||
|
||||
async entregar(id_prestamo: number, id_operador: number) {
|
||||
const ahora = moment();
|
||||
const operadorEntrega = await this.operadorService.findById(id_operador);
|
||||
const prestamo = await this.findById(id_prestamo);
|
||||
|
||||
prestamo.hora_inicio = ahora.toDate();
|
||||
prestamo.hora_fin = ahora
|
||||
.add(operadorEntrega.institucion.tiempo_prestamo, 'm')
|
||||
.toDate();
|
||||
prestamo.operadorEntrega = operadorEntrega;
|
||||
prestamo.equipo.status = await this.statusService.findById(3);
|
||||
prestamo.equipo.prestado = true;
|
||||
return this.equipoService
|
||||
.update(prestamo.equipo)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({
|
||||
message: 'Se entregó el equipo de cómputo correctamente.',
|
||||
}));
|
||||
}
|
||||
|
||||
async regresar(id_prestamo: number, id_operador: number) {
|
||||
const ahora = moment();
|
||||
const operadorRegreso = await this.operadorService.findById(id_operador);
|
||||
const prestamo = await this.findById(id_prestamo);
|
||||
|
||||
prestamo.activo = false;
|
||||
prestamo.fecha_entrega = ahora.toDate();
|
||||
prestamo.operadorRegreso = operadorRegreso;
|
||||
prestamo.equipo.status = await this.statusService.findById(1);
|
||||
return this.equipoService
|
||||
.update(prestamo.equipo)
|
||||
.then((_) => this.repository.save(prestamo))
|
||||
.then((_) => ({
|
||||
message: 'Se regresó el equipo de cómputo correctamente.',
|
||||
}));
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
activo?: string | boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user