Skip to content

Commit

Permalink
fix ishue with getByDate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieg0Code committed Aug 27, 2024
1 parent de3768c commit f8c3568
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sales-microservice/src/controllers/sale_controller_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class SaleControllerImpl implements SaleController {
async getSalesByDate(req: Request, res: Response): Promise<void> {

try {
const date = new Date(req.params.date);
const date = req.params.date;

const sales = await this.saleService.getSalesByDate(date);

Expand Down
6 changes: 2 additions & 4 deletions sales-microservice/src/repository/sales_repository_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ export class SalesRepositoryImpl implements SalesRepository {
async getSalesByDate(createdAt: string): Promise<Sale[]> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion sales-microservice/src/services/sale_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface SaleService {
createSale(saleRequest: CreateSaleRequest): Promise<string>;
getSaleByID(saleID: string): Promise<SaleResponse | null>;
getSalesByUserID(userID: number): Promise<SaleResponse[]>;
getSalesByDate(date: Date): Promise<SaleResponse[]>;
getSalesByDate(date: string): Promise<SaleResponse[]>;
getAllSales(): Promise<SaleResponse[]>;
deleteSale(saleID: string): Promise<boolean>;
}
5 changes: 2 additions & 3 deletions sales-microservice/src/services/sale_service_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ export class SaleServiceImpl implements SaleService {
throw new Error("Failed to retrieve sales");
}
}
async getSalesByDate(date: Date): Promise<SaleResponse[]> {
const dateStr = date.toISOString();
async getSalesByDate(date: string): Promise<SaleResponse[]> {
try {
const sales = await this.saleRepo.getSalesByDate(dateStr);
const sales = await this.saleRepo.getSalesByDate(date);
return sales.map(sale => {
return {
saleID: sale.saleID,
Expand Down

0 comments on commit f8c3568

Please sign in to comment.