mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-13 17:22:37 +02:00
ddd refactor: project-members
This commit is contained in:
parent
f9d2c31238
commit
85adfcd139
8 changed files with 140 additions and 51 deletions
|
|
@ -36,7 +36,7 @@ export class ProjectActionAuthorizationPolicy implements IProjectActionAuthoriza
|
|||
if (!userId) {
|
||||
throw new BadRequestError('User ID is required');
|
||||
}
|
||||
const membership = await this.projectMembersRepository.checkMembership(projectId, userId);
|
||||
const membership = await this.projectMembersRepository.exists(projectId, userId);
|
||||
if (!membership) {
|
||||
throw new NotAuthorizedError('User is not a member of the project');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,39 @@
|
|||
import { ProjectMember } from "@/src/entities/models/project-member";
|
||||
import { PaginatedList } from "@/src/entities/common/paginated-list";
|
||||
import { z } from "zod";
|
||||
|
||||
export const CreateProjectMemberSchema = ProjectMember.pick({
|
||||
userId: true,
|
||||
projectId: true,
|
||||
});
|
||||
|
||||
export interface IProjectMembersRepository {
|
||||
checkMembership(projectId: string, userId: string): Promise<boolean>;
|
||||
/**
|
||||
* Creates a new project member association. If the association already exists, returns the existing member.
|
||||
* @param data - The data required to create a project member (userId and projectId).
|
||||
* @returns A promise that resolves to the created or existing ProjectMember object.
|
||||
*/
|
||||
create(data: z.infer<typeof CreateProjectMemberSchema>): Promise<z.infer<typeof ProjectMember>>;
|
||||
|
||||
/**
|
||||
* Finds all project memberships for a given user, returned as a paginated list.
|
||||
* @param userId - The ID of the user whose project memberships are to be retrieved.
|
||||
* @returns A promise that resolves to a paginated list of ProjectMember objects.
|
||||
*/
|
||||
findByUserId(userId: string, cursor?: string, limit?: number): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ProjectMember>>>>;
|
||||
|
||||
/**
|
||||
* Deletes all project member associations for a given project.
|
||||
* @param projectId - The ID of the project whose member associations should be deleted.
|
||||
* @returns A promise that resolves when the operation is complete.
|
||||
*/
|
||||
deleteByProjectId(projectId: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Checks if a specific membership exists.
|
||||
* @param projectId - The ID of the project.
|
||||
* @param userId - The ID of the user.
|
||||
* @returns A promise that resolves to true if the user is a member of the project, false otherwise.
|
||||
*/
|
||||
exists(projectId: string, userId: string): Promise<boolean>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue