From f8c3568b4b6ee356e85929b2aee14958de5b2a7b Mon Sep 17 00:00:00 2001 From: dieg0code Date: Tue, 27 Aug 2024 13:33:41 -0400 Subject: [PATCH] fix ishue with getByDate endpoint --- sales-microservice/src/controllers/sale_controller_impl.ts | 2 +- sales-microservice/src/repository/sales_repository_impl.ts | 6 ++---- sales-microservice/src/services/sale_service.ts | 2 +- sales-microservice/src/services/sale_service_impl.ts | 5 ++--- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sales-microservice/src/controllers/sale_controller_impl.ts b/sales-microservice/src/controllers/sale_controller_impl.ts index b68c96c..29da485 100644 --- a/sales-microservice/src/controllers/sale_controller_impl.ts +++ b/sales-microservice/src/controllers/sale_controller_impl.ts @@ -152,7 +152,7 @@ export class SaleControllerImpl implements SaleController { async getSalesByDate(req: Request, res: Response): Promise { try { - const date = new Date(req.params.date); + const date = req.params.date; const sales = await this.saleService.getSalesByDate(date); diff --git a/sales-microservice/src/repository/sales_repository_impl.ts b/sales-microservice/src/repository/sales_repository_impl.ts index b447b17..ba2c76c 100644 --- a/sales-microservice/src/repository/sales_repository_impl.ts +++ b/sales-microservice/src/repository/sales_repository_impl.ts @@ -95,16 +95,14 @@ export class SalesRepositoryImpl implements SalesRepository { async getSalesByDate(createdAt: string): Promise { const params = { TableName: this.tableName, - FilterExpression: '#createdAt = :createdAt', - ExpressionAttributeNames: { - '#createdAt': 'createdAt' - }, + FilterExpression: 'createdAt = :createdAt', ExpressionAttributeValues: { ':createdAt': createdAt } }; try { + this.logger.info(`Getting sales for date ${createdAt}`); const result = await this.db.scan(params).promise(); return result.Items as Sale[]; } catch (error) { diff --git a/sales-microservice/src/services/sale_service.ts b/sales-microservice/src/services/sale_service.ts index ec976cb..8a19017 100644 --- a/sales-microservice/src/services/sale_service.ts +++ b/sales-microservice/src/services/sale_service.ts @@ -5,7 +5,7 @@ export interface SaleService { createSale(saleRequest: CreateSaleRequest): Promise; getSaleByID(saleID: string): Promise; getSalesByUserID(userID: number): Promise; - getSalesByDate(date: Date): Promise; + getSalesByDate(date: string): Promise; getAllSales(): Promise; deleteSale(saleID: string): Promise; } \ No newline at end of file diff --git a/sales-microservice/src/services/sale_service_impl.ts b/sales-microservice/src/services/sale_service_impl.ts index 896b098..1aaba3c 100644 --- a/sales-microservice/src/services/sale_service_impl.ts +++ b/sales-microservice/src/services/sale_service_impl.ts @@ -92,10 +92,9 @@ export class SaleServiceImpl implements SaleService { throw new Error("Failed to retrieve sales"); } } - async getSalesByDate(date: Date): Promise { - const dateStr = date.toISOString(); + async getSalesByDate(date: string): Promise { try { - const sales = await this.saleRepo.getSalesByDate(dateStr); + const sales = await this.saleRepo.getSalesByDate(date); return sales.map(sale => { return { saleID: sale.saleID,