Skip to content

Commit 95846a8

Browse files
committed
Fix bug in backend reports related to is int check
1 parent 7903ad1 commit 95846a8

File tree

3 files changed

+22
-59
lines changed

3 files changed

+22
-59
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsNumber, IsOptional, Min, Max } from 'class-validator';
2+
import { IsOptional, IsInt, Min, Max } from 'class-validator';
33
import { Type } from 'class-transformer';
44

55
export class GetReportsQueryDto {
@@ -10,8 +10,8 @@ export class GetReportsQueryDto {
1010
})
1111
@IsOptional()
1212
@Type(() => Number)
13-
@IsNumber()
13+
@IsInt()
1414
@Min(1)
1515
@Max(100)
16-
limit?: number = 10;
16+
limit?: number;
1717
}

backend/src/reports/reports.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export class ReportsService {
6161
}
6262

6363
async findLatest(queryDto: GetReportsQueryDto): Promise<Report[]> {
64-
const limit = queryDto.limit || 10;
64+
// Convert limit to a number to avoid serialization errors
65+
const limit =
66+
typeof queryDto.limit === 'string' ? parseInt(queryDto.limit, 10) : queryDto.limit || 10;
6567

6668
const command = new ScanCommand({
6769
TableName: this.tableName,
Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import axios from 'axios';
2-
import { MedicalReport, ReportStatus, ReportCategory } from '../models/medicalReport';
2+
import { MedicalReport, ReportStatus } from '../models/medicalReport';
33

4-
// Base API URL - should be configured from environment variables in a real app
5-
// Removed unused API_URL variable
4+
// Get the API URL from environment variables
5+
const API_URL = import.meta.env.VITE_BASE_URL_API || '';
66

77
/**
88
* Error thrown when report operations fail.
@@ -21,12 +21,10 @@ export class ReportError extends Error {
2121
*/
2222
export const fetchLatestReports = async (limit = 3): Promise<MedicalReport[]> => {
2323
try {
24-
// In a real app, this would be an actual API call
25-
// const response = await axios.get(`/api/reports/latest?limit=${limit}`);
26-
// return response.data;
27-
28-
// For now, return mock data
29-
return mockReports.slice(0, limit);
24+
const response = await axios.get(`${API_URL}/reports/latest?limit=${limit}`);
25+
console.log('response', response.data);
26+
console.log('API_URL', API_URL);
27+
return response.data;
3028
} catch (error) {
3129
if (axios.isAxiosError(error)) {
3230
throw new ReportError(`Failed to fetch latest reports: ${error.message}`);
@@ -41,12 +39,8 @@ export const fetchLatestReports = async (limit = 3): Promise<MedicalReport[]> =>
4139
*/
4240
export const fetchAllReports = async (): Promise<MedicalReport[]> => {
4341
try {
44-
// In a real app, this would be an actual API call
45-
// const response = await axios.get(`/api/reports`);
46-
// return response.data;
47-
48-
// For now, return mock data
49-
return mockReports;
42+
const response = await axios.get(`${API_URL}/reports`);
43+
return response.data;
5044
} catch (error) {
5145
if (axios.isAxiosError(error)) {
5246
throw new ReportError(`Failed to fetch all reports: ${error.message}`);
@@ -62,18 +56,16 @@ export const fetchAllReports = async (): Promise<MedicalReport[]> => {
6256
*/
6357
export const markReportAsRead = async (reportId: string): Promise<MedicalReport> => {
6458
try {
65-
// In a real app, this would be an actual API call
66-
// const response = await axios.patch(`/api/reports/${reportId}`, {
67-
// status: ReportStatus.READ
68-
// });
69-
// return response.data;
70-
71-
// For now, update mock data
72-
const report = mockReports.find(r => r.id === reportId);
59+
const response = await axios.patch(`${API_URL}/reports/${reportId}`, {
60+
status: ReportStatus.READ
61+
});
62+
63+
const report = response.data;
64+
7365
if (!report) {
7466
throw new Error(`Report with ID ${reportId} not found`);
7567
}
76-
68+
7769
report.status = ReportStatus.READ;
7870
return { ...report };
7971
} catch (error) {
@@ -83,34 +75,3 @@ export const markReportAsRead = async (reportId: string): Promise<MedicalReport>
8375
throw new ReportError('Failed to mark report as read');
8476
}
8577
};
86-
87-
// Mock data for development
88-
const mockReports: MedicalReport[] = [
89-
{
90-
id: '1',
91-
title: 'Blood Test',
92-
category: ReportCategory.GENERAL,
93-
date: '2025-01-27',
94-
status: ReportStatus.UNREAD,
95-
doctor: 'Dr. Smith',
96-
facility: 'City Hospital'
97-
},
98-
{
99-
id: '2',
100-
title: 'Cranial Nerve Exam',
101-
category: ReportCategory.NEUROLOGICAL,
102-
date: '2025-01-19',
103-
status: ReportStatus.UNREAD,
104-
doctor: 'Dr. Johnson',
105-
facility: 'Neurology Center'
106-
},
107-
{
108-
id: '3',
109-
title: 'Stress Test',
110-
category: ReportCategory.HEART,
111-
date: '2024-12-26',
112-
status: ReportStatus.READ,
113-
doctor: 'Dr. Williams',
114-
facility: 'Heart Institute'
115-
}
116-
];

0 commit comments

Comments
 (0)