Skip to content

Commit

Permalink
endpoints terminados
Browse files Browse the repository at this point in the history
  • Loading branch information
S14vcGt committed Nov 7, 2024
1 parent ebddbde commit 48018f8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ name: CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- main

permissions:
actions: read
Expand Down
2 changes: 1 addition & 1 deletion maquina_facturadora/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { JwtAuthPayload } from './models/JwtAuthPayload';
import { JwtAuthPayload } from './models/jwtAuthPayload';

@Injectable()
export class AuthDataService {
Expand Down
6 changes: 3 additions & 3 deletions maquina_facturadora/src/facturas/facturas.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body, Patch, Param } from '@nestjs/common';
import { Controller, Get, Post, Body, Patch, Param, ParseUUIDPipe } from '@nestjs/common';
import { FacturasService } from './facturas.service';
import { CreateFacturaDto } from './dto/create-factura.dto';
import { UpdateFacturaDto } from './dto/update-factura.dto';
Expand All @@ -18,8 +18,8 @@ export class FacturasController {
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.facturasService.findOne(+id);
findOne(@Param('id', new ParseUUIDPipe() )id: string) {
return this.facturasService.findOne(id);
}

@Patch(':id')
Expand Down
16 changes: 12 additions & 4 deletions maquina_facturadora/src/facturas/facturas.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { CreateFacturaDto } from './dto/create-factura.dto';
import { UpdateFacturaDto } from './dto/update-factura.dto';
import { InjectRepository } from '@nestjs/typeorm';
Expand All @@ -18,15 +18,23 @@ export class FacturasService {
}

findAll() {
return `This action returns all facturas`;
return this.facturaRepository.find();
}

findOne(id: number) {
return `This action returns a #${id} factura`;
findOne(id: string) {
return this.checkExistence(id)
}

update(id: number, updateFacturaDto: UpdateFacturaDto) {
console.log(updateFacturaDto);
return `This action updates a #${id} factura`;
}

async checkExistence(id: string): Promise<Factura> {
const checkFactura = await this.facturaRepository.findOneBy({ id });
if (!checkFactura) {
throw new NotFoundException(`Factura no registrada`);
}
return checkFactura;
}
}
8 changes: 4 additions & 4 deletions maquina_facturadora/src/productos/productos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export class ProductosController {
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateProductoDto: UpdateProductoDto) {
return this.productosService.update(+id, updateProductoDto);
update(@Param('id', new ParseUUIDPipe()) id: string, @Body() updateProductoDto: UpdateProductoDto) {
return this.productosService.update(id, updateProductoDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.productosService.remove(+id);
remove(@Param('id', new ParseUUIDPipe()) id: string) {
return this.productosService.remove(id);
}
}
22 changes: 15 additions & 7 deletions maquina_facturadora/src/productos/productos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,34 @@ export class ProductosService {
}

findAll() {
return `This action returns all productos`;
return this.productoRepository.find();
}

findOne(id: string) {
return this.checkExistence(id);
}

update(id: number, updateProductoDto: UpdateProductoDto) {
console.log(updateProductoDto);
return `This action updates a #${id} producto`;
async update(
id: string,
updateProductoDto: UpdateProductoDto
): Promise<Producto> {
const existingProducto = await this.checkExistence(id);
const updatedProducto = this.productoRepository.merge(
existingProducto,
updateProductoDto
);
return this.productoRepository.save(updatedProducto);
}

remove(id: number) {
return `This action removes a #${id} producto`;
async remove(id: string): Promise<void> {
const product = await this.checkExistence(id);
this.productoRepository.remove(product);
}

async checkExistence(id: string): Promise<Producto> {
const checkProducto = await this.productoRepository.findOneBy({ id });
if (!checkProducto) {
throw new NotFoundException(`Producto no registrado`);
throw new NotFoundException(`Product not registrated`);
}
return checkProducto;
}
Expand Down

0 comments on commit 48018f8

Please sign in to comment.