From c542c7a2e0a163c65b16a5078bc26cd7dddc38ff Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 11:42:18 -0400 Subject: [PATCH 1/8] Add amount for bolivares payment --- src/payments/dto/payment-confirmation.dto.ts | 7 ++++++- .../entities/payment-confirmation.entity.ts | 3 +++ .../1749310705475-add-amount-in-bs-migration.ts | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts diff --git a/src/payments/dto/payment-confirmation.dto.ts b/src/payments/dto/payment-confirmation.dto.ts index bc218f8..52fc305 100644 --- a/src/payments/dto/payment-confirmation.dto.ts +++ b/src/payments/dto/payment-confirmation.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty, IntersectionType } from '@nestjs/swagger'; import { Expose } from 'class-transformer'; -import { IsString, IsUUID } from 'class-validator'; +import { IsInt, IsString, IsUUID } from 'class-validator'; import { BaseDTO } from 'src/utils/dto/base.dto'; class PaymentConfirmationDTO { @@ -23,6 +23,11 @@ class PaymentConfirmationDTO { @ApiProperty() @IsString() phoneNumber: string; + + @Expose() + @ApiProperty() + @IsInt() + amountBs: number; } export class CreatePaymentConfirmationDTO extends PaymentConfirmationDTO { diff --git a/src/payments/entities/payment-confirmation.entity.ts b/src/payments/entities/payment-confirmation.entity.ts index f41e688..495ec69 100644 --- a/src/payments/entities/payment-confirmation.entity.ts +++ b/src/payments/entities/payment-confirmation.entity.ts @@ -16,6 +16,9 @@ export class PaymentConfirmation extends BaseModel { @Column({ type: 'character varying', name: 'phone_number' }) phoneNumber: string; + @Column({ type: 'integer', name: 'amount_bs', default: 0 }) + amountBs: number; + @OneToOne(() => Order, (order) => order.paymentConfirmation, { onDelete: 'RESTRICT', }) diff --git a/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts b/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts new file mode 100644 index 0000000..dd6c9fc --- /dev/null +++ b/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddAmountInBsMigration1749310705475 implements MigrationInterface { + name = 'AddAmountInBsMigration1749310705475'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "payment_confirmation" ADD "amount_bs" integer NOT NULL DEFAULT 0`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "payment_confirmation" DROP COLUMN "amount_bs"`, + ); + } +} From 021507d390f6c0bc6e690b201a2809c7e0faea4f Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 11:51:29 -0400 Subject: [PATCH 2/8] Revert amount in bs --- src/payments/dto/payment-confirmation.dto.ts | 7 +------ .../entities/payment-confirmation.entity.ts | 3 --- .../1749310705475-add-amount-in-bs-migration.ts | 17 ----------------- 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts diff --git a/src/payments/dto/payment-confirmation.dto.ts b/src/payments/dto/payment-confirmation.dto.ts index 52fc305..bc218f8 100644 --- a/src/payments/dto/payment-confirmation.dto.ts +++ b/src/payments/dto/payment-confirmation.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty, IntersectionType } from '@nestjs/swagger'; import { Expose } from 'class-transformer'; -import { IsInt, IsString, IsUUID } from 'class-validator'; +import { IsString, IsUUID } from 'class-validator'; import { BaseDTO } from 'src/utils/dto/base.dto'; class PaymentConfirmationDTO { @@ -23,11 +23,6 @@ class PaymentConfirmationDTO { @ApiProperty() @IsString() phoneNumber: string; - - @Expose() - @ApiProperty() - @IsInt() - amountBs: number; } export class CreatePaymentConfirmationDTO extends PaymentConfirmationDTO { diff --git a/src/payments/entities/payment-confirmation.entity.ts b/src/payments/entities/payment-confirmation.entity.ts index 495ec69..f41e688 100644 --- a/src/payments/entities/payment-confirmation.entity.ts +++ b/src/payments/entities/payment-confirmation.entity.ts @@ -16,9 +16,6 @@ export class PaymentConfirmation extends BaseModel { @Column({ type: 'character varying', name: 'phone_number' }) phoneNumber: string; - @Column({ type: 'integer', name: 'amount_bs', default: 0 }) - amountBs: number; - @OneToOne(() => Order, (order) => order.paymentConfirmation, { onDelete: 'RESTRICT', }) diff --git a/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts b/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts deleted file mode 100644 index dd6c9fc..0000000 --- a/src/payments/migrations/1749310705475-add-amount-in-bs-migration.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class AddAmountInBsMigration1749310705475 implements MigrationInterface { - name = 'AddAmountInBsMigration1749310705475'; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `ALTER TABLE "payment_confirmation" ADD "amount_bs" integer NOT NULL DEFAULT 0`, - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `ALTER TABLE "payment_confirmation" DROP COLUMN "amount_bs"`, - ); - } -} From c3f16a0e6e6c8d971bdc4307dd0147268b9c48a9 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 15:35:38 -0400 Subject: [PATCH 3/8] Add with promo query param --- src/products/dto/product.dto.ts | 11 +++++++++++ src/products/products.service.ts | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/products/dto/product.dto.ts b/src/products/dto/product.dto.ts index deb1532..090ed43 100644 --- a/src/products/dto/product.dto.ts +++ b/src/products/dto/product.dto.ts @@ -141,6 +141,15 @@ export class ProductQueryDTO extends PaginationQueryDTO { @IsBoolean() isVisible?: boolean; + @IsOptional() + @Transform(({ value }) => { + if (value === 'true') return true; + if (value === 'false') return false; + return undefined; + }) + @IsBoolean() + withPromo?: boolean; + constructor( page: number, limit: number, @@ -152,6 +161,7 @@ export class ProductQueryDTO extends PaginationQueryDTO { genericProductId?: string[], priceRange?: number[], isVisible?: boolean, + withPromo?: boolean, id?: string[], ) { super(page, limit); @@ -163,6 +173,7 @@ export class ProductQueryDTO extends PaginationQueryDTO { this.genericProductId = genericProductId ? genericProductId : []; this.priceRange = priceRange ? priceRange : []; this.isVisible = isVisible; + this.withPromo = withPromo; this.id = id ? id : []; } } diff --git a/src/products/products.service.ts b/src/products/products.service.ts index 35aac10..5f13177 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -22,6 +22,7 @@ export class ProductsService { priceRange?: number[], isVisible?: boolean, ids?: string[], + withPromo?: boolean, ) { const query = this.productPresentationRepository.createQueryBuilder( 'product_presentation', @@ -31,8 +32,13 @@ export class ProductsService { .innerJoinAndSelect('product.images', 'images') .innerJoinAndSelect('product.manufacturer', 'manufacturer') .innerJoinAndSelect('product.categories', 'categories') - .innerJoinAndSelect('product_presentation.presentation', 'presentation') - .leftJoinAndSelect('product_presentation.promo', 'promo'); + .innerJoinAndSelect('product_presentation.presentation', 'presentation'); + + if (withPromo) { + query.innerJoinAndSelect('product_presentation.promo', 'promo'); + } else { + query.leftJoinAndSelect('product_presentation.promo', 'promo'); + } if (searchQuery) { query.where( From 630612e8a36d7a306273901fe16afd675b6fba32 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 15:56:35 -0400 Subject: [PATCH 4/8] Fix with promo filter --- src/products/products.controller.ts | 4 +++- src/products/products.service.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/products/products.controller.ts b/src/products/products.controller.ts index c9d377a..bcf98b7 100644 --- a/src/products/products.controller.ts +++ b/src/products/products.controller.ts @@ -150,6 +150,7 @@ export class ProductsController { priceRange, isVisible, id, + withPromo, } = pagination; const { products, total } = await this.productsServices.getProductQueryBuilder( @@ -164,6 +165,7 @@ export class ProductsController { priceRange, isVisible, id, + withPromo, ); return { @@ -181,7 +183,7 @@ export class ProductsController { async getProductRecommendations(@Req() req: CustomRequest) { const userId = req.user.id; const recommendations = await this.recommendationService.recommend(userId); - const products = await this.productsServices.getProducts( + const products = await this.productsServices.getProductQueryBuilder( 1, 10, undefined, diff --git a/src/products/products.service.ts b/src/products/products.service.ts index 5f13177..71c3089 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -55,6 +55,17 @@ export class ProductsService { }), ); } + + if (withPromo) { + query + .andWhere('promo.startAt <= :currentDate', { + currentDate: new Date(), + }) + .andWhere('promo.expiredAt >= :currentDate', { + currentDate: new Date(), + }); + } + if (ids && ids.length > 0) { query.andWhere('product_presentation.id IN (:...ids)', { ids }); } From b3ea92863342b8066bd30f7fc14d08984b23b289 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 16:11:16 -0400 Subject: [PATCH 5/8] Order by priority --- src/products/products.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/products/products.service.ts b/src/products/products.service.ts index 71c3089..69a97db 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -114,7 +114,7 @@ export class ProductsService { query.andWhere('product_presentation.isVisible = true'); } query - .orderBy('product_presentation.createdAt', 'DESC') + .orderBy('product.priority', 'ASC') .skip((page - 1) * limit) .take(limit); const [products, total] = await query.getManyAndCount(); From 0ebf7ba9305d73a5559e1f8dd6d745d24694e192 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sat, 7 Jun 2025 16:36:05 -0400 Subject: [PATCH 6/8] Order by id --- src/products/products.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/products/products.service.ts b/src/products/products.service.ts index 69a97db..bcd7ab4 100644 --- a/src/products/products.service.ts +++ b/src/products/products.service.ts @@ -115,6 +115,7 @@ export class ProductsService { } query .orderBy('product.priority', 'ASC') + .addOrderBy('product_presentation.id', 'ASC') .skip((page - 1) * limit) .take(limit); const [products, total] = await query.getManyAndCount(); From 38b40dcce87cbf62ef2e38d79931dc1bbfa82771 Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Sun, 8 Jun 2025 10:45:40 -0400 Subject: [PATCH 7/8] Fix for negative numbers --- src/sales/sales.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sales/sales.service.ts b/src/sales/sales.service.ts index cd48143..7c9ee9d 100644 --- a/src/sales/sales.service.ts +++ b/src/sales/sales.service.ts @@ -94,8 +94,9 @@ export class SalesService { return { date: formatted, - predictedTotal: parseInt( - (predictedValues as number[][])[index][0].toFixed(2), + predictedTotal: Math.max( + parseInt((predictedValues as number[][])[index][0].toFixed(2)), + 0, ), }; }); From 1db9c7f4e819c86c2ea1e96cc66f0701a75b7d3b Mon Sep 17 00:00:00 2001 From: Andres Alvarez Date: Mon, 9 Jun 2025 16:10:34 -0400 Subject: [PATCH 8/8] Upgrade version 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f9de463..979c8c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "1.0.1", + "version": "1.1.0", "description": "", "author": "", "private": true,