Merge branch 'Axel' of https://repositorio.acatlan.unam.mx/CIDWA/Censo_api into Lino
This commit is contained in:
@@ -7,6 +7,10 @@ import {
|
||||
UseGuards,
|
||||
Get,
|
||||
Query,
|
||||
Delete,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
NotFoundException,
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
@@ -48,7 +52,15 @@ export class EquipoController {
|
||||
) {
|
||||
return this.equipoService.updateEquipo(equipoNuevo, id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async deleteEquipo(@Param('id', ParseIntPipe) id_equipo: number) {
|
||||
try {
|
||||
return await this.equipoService.deleteEquipo(id_equipo);
|
||||
} catch (error) {
|
||||
throw new NotFoundException(error.message);
|
||||
}
|
||||
}
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('usos')
|
||||
findUsos() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
@@ -242,4 +242,22 @@ export class EquipoService {
|
||||
|
||||
return this.equipoRepository.save(nuevoEquipo);
|
||||
}
|
||||
|
||||
async deleteEquipo(id_equipo: number): Promise<{ message: string }> {
|
||||
const equipo = await this.equipoRepository.findOne({
|
||||
where: { id_equipo },
|
||||
});
|
||||
|
||||
if (!equipo) {
|
||||
throw new NotFoundException(
|
||||
`No se encontró el equipo con id ${id_equipo}`,
|
||||
);
|
||||
}
|
||||
|
||||
await this.equipoRepository.remove(equipo);
|
||||
|
||||
return {
|
||||
message: `Equipo con id ${id_equipo} eliminado correctamente`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user