feat: Add new sales and shopping cart management module.
All checks were successful
Build (develop) / Promote (main) / build-and-push-deploy (push) Successful in 1m45s

This commit is contained in:
Luis Eduardo Estevao
2026-02-11 10:49:17 -03:00
parent f2b2572a35
commit f0ef3dd21c
3 changed files with 87 additions and 43 deletions

View File

@@ -6,117 +6,127 @@ import { OrderDiscount } from 'src/domain/models/order-discount.model';
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
import { LogOrder } from 'src/domain/models/log-order.model';
import { ApiTags } from '@nestjs/swagger';
import { Cart } from 'src/domain/models/cart.model';
@ApiTags('Shopping')
@Controller('api/v1/shopping')
export class ShoppingController {
constructor(private shoppingService: ShoppingService){}
constructor(private shoppingService: ShoppingService) { }
@Get('cart/:id')
async getCart(@Param('id') id: string){
try {
async getCart(@Param('id') id: string) {
try {
const cart = await this.shoppingService.GetItensCart(id);
if (cart == null || cart.length == 0)
throw new HttpException("Carrinho de compras não encontrado", HttpStatus.NOT_FOUND);
return cart;
} catch (error) {
const status = error.status == 404 ? error.status : HttpStatus.INTERNAL_SERVER_ERROR;
throw new HttpException(error.message, status);
throw new HttpException(error.message, status);
}
}
@Get(':id')
async getPreVenda(@Param('id') id: string ){
try {
async getPreVenda(@Param('id') id: string) {
try {
const cart = await this.shoppingService.getShopping(id);
if (cart == null )
if (cart == null)
throw new HttpException("Carrinho de compras não encontrado", HttpStatus.NOT_FOUND);
return cart;
} catch (error) {
const status = error.status == 404 ? error.status : HttpStatus.INTERNAL_SERVER_ERROR;
throw new HttpException(error.message, status);
throw new HttpException(error.message, status);
}
}
@Put('cart')
async updateCart(@Body() cart: Cart) {
try {
return await this.shoppingService.updateShopping(cart);
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@Get('cart/:idcart/item/:idProduct/tipoentrega/:deliveryType')
async getItemCart(@Req() request, @Param('idCart') idCart: string,
@Param('idProduct') idProduct: string, @Param('deliveryType') deliveryType: string){
async getItemCart(@Req() request, @Param('idCart') idCart: string,
@Param('idProduct') idProduct: string, @Param('deliveryType') deliveryType: string) {
let store = '99';
try {
try {
if (request.headers['x-store'])
store = request.headers['x-store'];
const cart = await this.shoppingService.getItemCart(idCart, idProduct, store, deliveryType);
if (cart == null )
if (cart == null)
throw new HttpException("Item não foi encontrado no carrinho de compras.", HttpStatus.NOT_FOUND);
return cart;
} catch (error) {
const status = error.status == 404 ? error.status : HttpStatus.INTERNAL_SERVER_ERROR;
throw new HttpException(error.message, status);
throw new HttpException(error.message, status);
}
}
@Get('cart/lot/:productId/:customerId')
async getLotProduct( @Req() request, @Param('productId') productId: number,
@Param('customerId') customerId: number ) {
async getLotProduct(@Req() request, @Param('productId') productId: number,
@Param('customerId') customerId: number) {
let store = '99';
try {
try {
if (request.headers['x-store'])
store = request.headers['x-store'];
const lotsProduct = await this.shoppingService.getLotProduct(productId, customerId);
return lotsProduct;
} catch (error) {
const status = error.status == 404 ? error.status : HttpStatus.INTERNAL_SERVER_ERROR;
throw new HttpException(error.message, status);
throw new HttpException(error.message, status);
}
}
@Post('item')
async createItemShopping(@Body() item: ShoppingItem){
async createItemShopping(@Body() item: ShoppingItem) {
console.log('createItemShopping')
try {
try {
return await this.shoppingService.createItemCart(item);
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@Post('log')
async logOrderShopping(@Body() logOrder: LogOrder){
try {
async logOrderShopping(@Body() logOrder: LogOrder) {
try {
console.log('logOrderShopping')
return await this.shoppingService.createLogShopping(logOrder);
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@Put('item')
async updateQuantityItem(@Body() item: ShoppingItem){
console.log(item);
try {
if (item.id == null){
async updateQuantityItem(@Body() item: ShoppingItem) {
console.log(item);
try {
if (item.id == null) {
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
}
const itemCreate = await this.shoppingService.updateItem(item);
return itemCreate;
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@Put('item/discount')
async updatePriceItem(@Body() item: ShoppingItem){
console.log(item);
try {
if (item.id == null){
async updatePriceItem(@Body() item: ShoppingItem) {
console.log(item);
try {
if (item.id == null) {
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
}
const itemCreate = await this.shoppingService.updatePrice(item);
return itemCreate;
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@@ -126,7 +136,7 @@ export class ShoppingController {
const itensOrder = await this.shoppingService.applyDiscountOrder(order);
return itensOrder;
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@@ -137,17 +147,17 @@ export class ShoppingController {
return orderTax;
} catch (error) {
console.log(error);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@Delete('item/delete/:id')
async deleteItem(@Param('id') id: string){
try {
async deleteItem(@Param('id') id: string) {
try {
await this.shoppingService.deleteItem(id);
return new ResultModel(true, 'Item excluído com sucesso!', id, null,);
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
}
}
@@ -165,4 +175,4 @@ export class ShoppingController {
}
}
}