Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions backend/src/reports/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ export class ReportsService {

const command = new GetItemCommand({
TableName: this.tableName,
Key: marshall({ id }),
Key: marshall({
userId, // Partition key
id, // Sort key
}),
});

try {
Expand All @@ -161,14 +164,9 @@ export class ReportsService {

const report = unmarshall(response.Item) as Report;

// Verify the report belongs to the user
if (report.userId !== userId) {
throw new ForbiddenException('You do not have permission to access this report');
}

return report;
} catch (error: unknown) {
if (error instanceof NotFoundException) {
if (error instanceof NotFoundException || error instanceof ForbiddenException) {
throw error;
}

Expand All @@ -180,6 +178,14 @@ export class ReportsService {
throw new InternalServerErrorException(
`Table "${this.tableName}" not found. Please check your database configuration.`,
);
} else if (error.name === 'UnrecognizedClientException') {
throw new InternalServerErrorException(
'Invalid AWS credentials. Please check your AWS configuration.',
);
} else if (error.name === 'ValidationException') {
throw new InternalServerErrorException(
'The provided key structure does not match the table schema. Please check your DynamoDB table configuration.',
);
}
}

Expand Down
Loading