Skip to content

Commit

Permalink
fix dates
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirGer committed Mar 16, 2024
1 parent 48c789e commit eecedb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/brokencrystals/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: |
Benchmark application that uses modern technologies and implements a set of
common security vulnerabilities
type: application
version: 0.0.60
version: 0.0.61
keywords:
- brokencrystals
- brkn
17 changes: 15 additions & 2 deletions src/products/products.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export class ProductsController {

constructor(private readonly productsService: ProductsService) {}

private parseDate(dateString: string): Date {
const dateParts = dateString.split('-');
const year = parseInt(dateParts[2], 10);
const month = parseInt(dateParts[1], 10) - 1;
const day = parseInt(dateParts[0], 10);

return new Date(year, month, day);
}

@Get()
@UseGuards(AuthGuard)
@JwtType(JwtProcessorType.RSA)
Expand Down Expand Up @@ -67,10 +76,14 @@ export class ProductsController {
let df = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
let dt = new Date();
if (dateFrom) {
df = new Date(`${dateFrom} 00:00:00.000Z`);
df = this.parseDate(dateFrom);
}
if (dateTo) {
dt = new Date(`${dateTo} 00:00:00.000Z`);
dt = this.parseDate(dateTo);
}

if (isNaN(df.getTime()) || isNaN(dt.getTime())) {
throw new BadRequestException('Invalid date format');
}

const allProducts = await this.productsService.findAll(df, dt);
Expand Down

0 comments on commit eecedb7

Please sign in to comment.