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:
parent
5abd33e648
commit
8cbce3f3fa
@ -229,16 +229,29 @@ export class ProjectsService {
|
|||||||
* Get all collaborators for a project
|
* Get all collaborators for a project
|
||||||
*/
|
*/
|
||||||
async getCollaborators(projectId: string) {
|
async getCollaborators(projectId: string) {
|
||||||
// Check if the project exists
|
// Validate projectId
|
||||||
await this.findById(projectId);
|
if (!projectId) {
|
||||||
|
throw new NotFoundException('Project ID is required');
|
||||||
|
}
|
||||||
|
|
||||||
// Get all collaborators for the project
|
try {
|
||||||
return this.db
|
// Check if the project exists
|
||||||
.select({
|
await this.findById(projectId);
|
||||||
user: schema.users,
|
|
||||||
})
|
// Get all collaborators for the project
|
||||||
.from(schema.projectCollaborators)
|
const collaborators = await this.db
|
||||||
.innerJoin(schema.users, eq(schema.projectCollaborators.userId, schema.users.id))
|
.select({
|
||||||
.where(eq(schema.projectCollaborators.projectId, projectId));
|
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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user