Skip to content

Commit 66a607b

Browse files
committed
refactor: Remove findByFilePath method to streamline report retrieval process
1 parent 9095977 commit 66a607b

File tree

1 file changed

+0
-100
lines changed

1 file changed

+0
-100
lines changed

backend/src/reports/reports.service.ts

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -333,106 +333,6 @@ export class ReportsService {
333333
}
334334
}
335335

336-
/**
337-
* Find a report by its filePath
338-
* @param filePath The S3 path of the file
339-
* @param userId User ID for authorization
340-
* @returns Report record if found
341-
*/
342-
async findByFilePath(filePath: string, userId: string): Promise<Report | null> {
343-
if (!filePath) {
344-
throw new NotFoundException('File path is required');
345-
}
346-
347-
if (!userId) {
348-
throw new ForbiddenException('User ID is required');
349-
}
350-
351-
// Log the actual filePath being searched for debugging
352-
this.logger.log(`Searching for report with filePath: "${filePath}" for user ${userId}`);
353-
354-
try {
355-
const command = new QueryCommand({
356-
TableName: this.tableName,
357-
KeyConditionExpression: 'userId = :userId',
358-
FilterExpression: 'filePath = :filePath',
359-
ExpressionAttributeValues: marshall({
360-
':userId': userId,
361-
':filePath': filePath,
362-
}),
363-
Limit: 1, // We only want one record
364-
});
365-
366-
this.logger.log('Executing QueryCommand with params:', {
367-
TableName: this.tableName,
368-
KeyConditionExpression: 'userId = :userId',
369-
FilterExpression: 'filePath = :filePath',
370-
Values: {
371-
userId,
372-
filePath,
373-
},
374-
});
375-
376-
const response = await this.dynamoClient.send(command);
377-
378-
this.logger.log(`Query response received, found ${response.Items?.length || 0} items`);
379-
380-
if (!response.Items || response.Items.length === 0) {
381-
// If no exact match, try with case-insensitive comparison as a fallback
382-
this.logger.log('No exact match found, trying with case-insensitive search');
383-
384-
// Get all items for the user and filter manually for case-insensitive match
385-
const allUserItemsCommand = new QueryCommand({
386-
TableName: this.tableName,
387-
KeyConditionExpression: 'userId = :userId',
388-
ExpressionAttributeValues: marshall({
389-
':userId': userId,
390-
}),
391-
});
392-
393-
const allUserResponse = await this.dynamoClient.send(allUserItemsCommand);
394-
395-
if (!allUserResponse.Items || allUserResponse.Items.length === 0) {
396-
return null;
397-
}
398-
399-
// Convert items and find case-insensitive match
400-
const allReports = allUserResponse.Items.map(item => unmarshall(item) as Report);
401-
const matchingReport = allReports.find(
402-
report => report.filePath.toLowerCase() === filePath.toLowerCase(),
403-
);
404-
405-
if (matchingReport) {
406-
this.logger.log(
407-
`Found case-insensitive match for ${filePath}: ${matchingReport.filePath}`,
408-
);
409-
410-
return matchingReport;
411-
}
412-
413-
return null;
414-
}
415-
416-
const result = unmarshall(response.Items[0]) as Report;
417-
this.logger.log(`Found report with ID ${result.id}`);
418-
419-
return result;
420-
} catch (error: unknown) {
421-
this.logger.error(`Error finding report with filePath ${filePath}:`);
422-
this.logger.error(error);
423-
424-
if (error instanceof DynamoDBServiceException) {
425-
if (error.name === 'ResourceNotFoundException') {
426-
throw new InternalServerErrorException(
427-
`Table "${this.tableName}" not found. Please check your database configuration.`,
428-
);
429-
}
430-
}
431-
432-
throw new InternalServerErrorException(`Failed to fetch report with filePath ${filePath}`);
433-
}
434-
}
435-
436336
/**
437337
* Update a report with new data
438338
* @param report Updated report object

0 commit comments

Comments
 (0)