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 Variable module #342

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

API: Add pagination metadata to Variable module #342

rajdip-b opened this issue Jul 10, 2024 · 2 comments · Fixed by #390
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 getAllVariablesOfProject(
    user: User,
    projectId: Project['id'],
    page: number,
    limit: number,
    sort: string,
    order: string,
    search: string
    ) {
    // Check if the user has the required authorities in the project
    await this.authorityCheckerService.checkAuthorityOverProject({
    userId: user.id,
    entity: { id: projectId },
    authority: Authority.READ_VARIABLE,
    prisma: this.prisma
    })
    const variables = await this.prisma.variable.findMany({
    where: {
    projectId,
    name: {
    contains: search
    }
    },
    include: {
    lastUpdatedBy: {
    select: {
    id: true,
    name: true
    }
    }
    },
    skip: page * limit,
    take: limit,
    orderBy: {
    [sort]: order
    }
    })
    const variablesWithEnvironmentalValues = new Map<
    Variable['id'],
    {
    variable: Variable
    values: {
    environment: {
    name: Environment['name']
    id: Environment['id']
    }
    value: VariableVersion['value']
    version: VariableVersion['version']
    }[]
    }
    >()
    // Find all the environments for this project
    const environments = await this.prisma.environment.findMany({
    where: {
    projectId
    }
    })
    const environmentIds = new Map(
    environments.map((env) => [env.id, env.name])
    )
    for (const variable of variables) {
    // Make a copy of the environment IDs
    const envIds = new Map(environmentIds)
    let iterations = envIds.size
    // Find the latest version for each environment
    while (iterations--) {
    const latestVersion = await this.prisma.variableVersion.findFirst({
    where: {
    variableId: variable.id,
    environmentId: {
    in: Array.from(envIds.keys())
    }
    },
    orderBy: {
    version: 'desc'
    }
    })
    if (!latestVersion) continue
    if (variablesWithEnvironmentalValues.has(variable.id)) {
    variablesWithEnvironmentalValues.get(variable.id).values.push({
    environment: {
    id: latestVersion.environmentId,
    name: envIds.get(latestVersion.environmentId)
    },
    value: latestVersion.value,
    version: latestVersion.version
    })
    } else {
    variablesWithEnvironmentalValues.set(variable.id, {
    variable,
    values: [
    {
    environment: {
    id: latestVersion.environmentId,
    name: envIds.get(latestVersion.environmentId)
    },
    value: latestVersion.value,
    version: latestVersion.version
    }
    ]
    })
    }
    envIds.delete(latestVersion.environmentId)
    }
    }
    return Array.from(variablesWithEnvironmentalValues.values())
    }
@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