From f9891da06af52b5b3c289e2983043f6967b8cc98 Mon Sep 17 00:00:00 2001 From: Adam Refaey Date: Fri, 25 Apr 2025 19:26:56 +0300 Subject: [PATCH 1/2] Update reportService API endpoint for marking reports as read - Changed the API endpoint for marking a report as read from `/api/reports/${reportId}` to `/api/reports/${reportId}/status` in both the reportService and its corresponding test file. - This change improves clarity in the API structure. --- frontend/src/common/api/__tests__/reportService.test.ts | 2 +- frontend/src/common/api/reportService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/common/api/__tests__/reportService.test.ts b/frontend/src/common/api/__tests__/reportService.test.ts index 7734aac..ffb020d 100644 --- a/frontend/src/common/api/__tests__/reportService.test.ts +++ b/frontend/src/common/api/__tests__/reportService.test.ts @@ -103,7 +103,7 @@ vi.mock('../reportService', async (importOriginal) => { // Mock markReportAsRead to avoid the dependency on getAuthConfig markReportAsRead: async (reportId: string) => { try { - const response = await axios.patch(`/api/reports/${reportId}`, { + const response = await axios.patch(`/api/reports/${reportId}/status`, { status: 'READ', }); return response.data; diff --git a/frontend/src/common/api/reportService.ts b/frontend/src/common/api/reportService.ts index 5b31a4e..840cf6e 100644 --- a/frontend/src/common/api/reportService.ts +++ b/frontend/src/common/api/reportService.ts @@ -142,7 +142,7 @@ export const fetchAllReports = async (): Promise => { export const markReportAsRead = async (reportId: string): Promise => { try { const response = await axios.patch( - `${API_URL}/api/reports/${reportId}`, + `${API_URL}/api/reports/${reportId}/status`, { status: 'READ', }, From f1d5ff23304c8636d2a8d8f64eed9a3f1e815fc2 Mon Sep 17 00:00:00 2001 From: Adam Refaey Date: Fri, 25 Apr 2025 19:34:20 +0300 Subject: [PATCH 2/2] Update ReportsService to include userId in report update key - Modified the UpdateItemCommand in ReportsService to use both userId and id as keys for report updates. This change ensures that the report belongs to the correct user, enhancing data integrity. --- backend/src/reports/reports.service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/reports/reports.service.ts b/backend/src/reports/reports.service.ts index 2c3c2b2..e5e8d99 100644 --- a/backend/src/reports/reports.service.ts +++ b/backend/src/reports/reports.service.ts @@ -243,7 +243,10 @@ export class ReportsService { const command = new UpdateItemCommand({ TableName: this.tableName, - Key: marshall({ id }), + Key: marshall({ + userId, // Partition key + id, // Sort key + }), UpdateExpression: 'SET #status = :status, updatedAt = :updatedAt', ConditionExpression: 'userId = :userId', // Ensure the report belongs to the user ExpressionAttributeNames: {