feat: added v1 projects project-role-router

This commit is contained in:
=
2025-09-16 00:08:39 +05:30
parent ca877cb225
commit d3acc90d6a
6 changed files with 361 additions and 58 deletions
+3 -3
View File
@@ -22,7 +22,7 @@ export const useCreateProjectRole = () => {
mutationFn: async ({ projectId, ...dto }: TCreateProjectRoleDTO) => {
const {
data: { role }
} = await apiRequest.post(`/api/v2/workspace/${projectId}/roles`, dto);
} = await apiRequest.post(`/api/v1/projects/${projectId}/roles`, dto);
return role;
},
onSuccess: (_, { projectId }) => {
@@ -38,7 +38,7 @@ export const useUpdateProjectRole = () => {
mutationFn: async ({ id, projectId, ...dto }: TUpdateProjectRoleDTO) => {
const {
data: { role }
} = await apiRequest.patch(`/api/v2/workspace/${projectId}/roles/${id}`, dto);
} = await apiRequest.patch(`/api/v1/projects/${projectId}/roles/${id}`, dto);
return role;
},
onSuccess: (_, { projectId, slug }) => {
@@ -58,7 +58,7 @@ export const useDeleteProjectRole = () => {
mutationFn: async ({ projectId, id }: TDeleteProjectRoleDTO) => {
const {
data: { role }
} = await apiRequest.delete(`/api/v2/workspace/${projectId}/roles/${id}`);
} = await apiRequest.delete(`/api/v1/projects/${projectId}/roles/${id}`);
return role;
},
onSuccess: (_, { projectId }) => {
+10 -12
View File
@@ -46,13 +46,13 @@ export const roleQueryKeys = {
getOrgRole: (orgId: string, roleId: string) => [{ orgId, roleId }, "org-role"] as const,
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
["user-permissions", { orgId }] as const,
getUserProjectPermissions: ({ workspaceId }: TGetUserProjectPermissionDTO) =>
["user-project-permissions", { workspaceId }] as const
getUserProjectPermissions: ({ projectId }: TGetUserProjectPermissionDTO) =>
["user-project-permissions", { projectId }] as const
};
export const getProjectRoles = async (projectId: string) => {
const { data } = await apiRequest.get<{ roles: Array<Omit<TProjectRole, "permissions">> }>(
`/api/v2/workspace/${projectId}/roles`
`/api/v1/projects/${projectId}/roles`
);
return data.roles;
};
@@ -69,7 +69,7 @@ export const useGetProjectRoleBySlug = (projectId: string, roleSlug: string) =>
queryKey: roleQueryKeys.getProjectRoleBySlug(projectId, roleSlug),
queryFn: async () => {
const { data } = await apiRequest.get<{ role: TProjectRole }>(
`/api/v2/workspace/${projectId}/roles/slug/${roleSlug}`
`/api/v1/projects/${projectId}/roles/slug/${roleSlug}`
);
return data.role;
},
@@ -131,9 +131,7 @@ export const useGetUserOrgPermissions = ({ orgId }: TGetUserOrgPermissionsDTO) =
}
});
export const fetchUserProjectPermissions = async ({
workspaceId
}: TGetUserProjectPermissionDTO) => {
export const fetchUserProjectPermissions = async ({ projectId }: TGetUserProjectPermissionDTO) => {
const { data } = await apiRequest.get<{
data: {
permissions: PackRule<RawRuleOf<MongoAbility<OrgPermissionSet>>>[];
@@ -145,16 +143,16 @@ export const fetchUserProjectPermissions = async ({
actorName: string;
};
};
}>(`/api/v1/workspace/${workspaceId}/permissions`, {});
}>(`/api/v1/projects/${projectId}/permissions`, {});
return data.data;
};
export const useGetUserProjectPermissions = ({ workspaceId }: TGetUserProjectPermissionDTO) =>
export const useGetUserProjectPermissions = ({ projectId }: TGetUserProjectPermissionDTO) =>
useQuery({
queryKey: roleQueryKeys.getUserProjectPermissions({ workspaceId }),
queryFn: () => fetchUserProjectPermissions({ workspaceId }),
enabled: Boolean(workspaceId),
queryKey: roleQueryKeys.getUserProjectPermissions({ projectId }),
queryFn: () => fetchUserProjectPermissions({ projectId }),
enabled: Boolean(projectId),
select: (data) => {
const rule = unpackRules<RawRuleOf<MongoAbility<ProjectPermissionSet>>>(data.permissions);
const negatedRules = groupBy(
+2 -2
View File
@@ -9,7 +9,7 @@ export enum ProjectMembershipRole {
}
export type TGetProjectRolesDTO = {
workspaceId?: string;
projectId?: string;
};
export type TProjectRole = {
@@ -52,7 +52,7 @@ export type TGetUserOrgPermissionsDTO = {
};
export type TGetUserProjectPermissionDTO = {
workspaceId: string;
projectId: string;
};
export type TCreateOrgRoleDTO = {