feat(tags): add input validation for tag and entity operations

Added validation checks for tagId, personId, and projectId across tag-related operations. Introduced `BadRequestException` for invalid or missing inputs. Replaced generic errors with more descriptive exceptions.
This commit is contained in:
Mathis HERRIOT 2025-05-16 23:52:39 +02:00
parent 5abd33e648
commit 8cbce3f3fa
No known key found for this signature in database
GPG Key ID: E7EB4A211D8D4907

View File

@ -229,16 +229,29 @@ export class ProjectsService {
* Get all collaborators for a project
*/
async getCollaborators(projectId: string) {
// Check if the project exists
await this.findById(projectId);
// Validate projectId
if (!projectId) {
throw new NotFoundException('Project ID is required');
}
// Get all collaborators for the project
return this.db
.select({
user: schema.users,
})
.from(schema.projectCollaborators)
.innerJoin(schema.users, eq(schema.projectCollaborators.userId, schema.users.id))
.where(eq(schema.projectCollaborators.projectId, projectId));
try {
// Check if the project exists
await this.findById(projectId);
// Get all collaborators for the project
const collaborators = await this.db
.select({
user: schema.users,
})
.from(schema.projectCollaborators)
.innerJoin(schema.users, eq(schema.projectCollaborators.userId, schema.users.id))
.where(eq(schema.projectCollaborators.projectId, projectId));
// Map the results to extract just the user objects
return collaborators.map(collaborator => collaborator.user);
} catch (error) {
// If there's a database error (like invalid UUID format), throw a NotFoundException
throw new NotFoundException(`Failed to get collaborators for project: ${error.message}`);
}
}
}