Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add pagination metadata to Integration module #343

Closed
rajdip-b opened this issue Jul 10, 2024 · 2 comments · Fixed by #391
Closed

API: Add pagination metadata to Integration module #343

rajdip-b opened this issue Jul 10, 2024 · 2 comments · Fixed by #391
Assignees
Labels
difficulty: 1 foss hack Clustering all the curated issues for Foss Hack 2024 good first issue Good for newcomers help wanted Extra attention is needed priority: high scope: api Everything related to the API type: enhancement New feature or request

Comments

@rajdip-b
Copy link
Member

Description

Refer to #336

Scope of change

  • async getAllIntegrationsOfWorkspace(
    user: User,
    workspaceId: Workspace['id'],
    page: number,
    limit: number,
    sort: string,
    order: string,
    search: string
    ) {
    // Check if the user has READ authority over the workspace
    await this.authorityCheckerService.checkAuthorityOverWorkspace({
    userId: user.id,
    entity: { id: workspaceId },
    authority: Authority.READ_INTEGRATION,
    prisma: this.prisma
    })
    // We need to return only those integrations that have the following properties:
    // - belong to the workspace
    // - does not belong to any project
    // - does not belong to any project where the user does not have READ authority
    // Get the projects the user has READ authority over
    const membership = await this.prisma.workspaceMember.findUnique({
    where: {
    workspaceId_userId: {
    userId: user.id,
    workspaceId
    }
    }
    })
    const workspaceRoles = await this.prisma.workspaceRole.findMany({
    where: {
    workspaceId,
    workspaceMembers: {
    some: {
    workspaceMemberId: membership.id
    }
    }
    },
    include: {
    projects: {
    include: {
    project: true
    }
    }
    }
    })
    const projectIds =
    workspaceRoles
    .map((role) => role.projects.map((p) => p.projectId))
    .flat() || []
    // Get all integrations in the workspace
    const integrations = await this.prisma.integration.findMany({
    where: {
    name: {
    contains: search
    },
    workspaceId,
    OR: [
    {
    projectId: null
    },
    {
    projectId: {
    in: projectIds
    }
    }
    ]
    },
    skip: page * limit,
    take: limit,
    orderBy: {
    [sort]: order
    }
    })
    return integrations
    }
@rajdip-b rajdip-b added type: enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed scope: api Everything related to the API priority: high foss hack Clustering all the curated issues for Foss Hack 2024 difficulty: 1 labels Jul 10, 2024
@rajdip-b rajdip-b moved this to Todo in keyshade-api Jul 10, 2024
@muntaxir4
Copy link
Contributor

/attempt i am assigned the parent issue #336

Copy link

Assigned the issue to @muntaxir4!

@github-project-automation github-project-automation bot moved this from Todo to Done in keyshade-api Jul 29, 2024
@rajdip-b rajdip-b moved this from Done to Queued for release in keyshade-api Jul 29, 2024
@rajdip-b rajdip-b moved this from Queued for release to Done in keyshade-api Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: 1 foss hack Clustering all the curated issues for Foss Hack 2024 good first issue Good for newcomers help wanted Extra attention is needed priority: high scope: api Everything related to the API type: enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants