Skip to content

Commit

Permalink
Merge pull request #3554 from uselagoon/feature/getOrganizationByName
Browse files Browse the repository at this point in the history
Feature/OrganizationByName resolver
  • Loading branch information
tobybellwood authored Oct 10, 2023
2 parents 05d1505 + 53c9f39 commit e5fc509
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const {
updateOrganization,
deleteOrganization,
getOrganizationById,
getOrganizationByName,
addDeployTargetToOrganization,
removeDeployTargetFromOrganization,
getDeployTargetsByOrganizationId,
Expand Down Expand Up @@ -577,6 +578,7 @@ const resolvers = {
deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget,
allOrganizations: getAllOrganizations,
organizationById: getOrganizationById,
organizationByName: getOrganizationByName,
getGroupProjectOrganizationAssociation,
getProjectGroupOrganizationAssociation,
getEnvVariablesByProjectEnvironmentName,
Expand Down
24 changes: 24 additions & 0 deletions services/api/src/resources/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ export const getOrganizationById: ResolverFn = async (
return orgResult;
};

export const getOrganizationByName: ResolverFn = async (
name,
args,
{ sqlClientPool, hasPermission }
) => {
let orgName = args.name;
if (name) {
orgName = name;
}

const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName));
const orgResult = rows[0];

if (!orgResult) {
return null;
}

await hasPermission('organization', 'view', {
organization: orgResult.id,
});

return orgResult;
};

export const getAllOrganizations: ResolverFn = async (
root,
args,
Expand Down
4 changes: 4 additions & 0 deletions services/api/src/resources/organization/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const Sql = {
knex('organization')
.where('id', '=', id)
.toString(),
selectOrganizationByName: (name: string) =>
knex('organization')
.where('name', '=', name)
.toString(),
selectOrganizationProjects: (id: number) =>
knex('project')
.where('organization', '=', id)
Expand Down
1 change: 1 addition & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ const typeDefs = gql`
Get an organization by its ID
"""
organizationById(organization: Int!): Organization
organizationByName(name: String!): Organization
getGroupProjectOrganizationAssociation(input: AddGroupInput!): String
getProjectGroupOrganizationAssociation(input: ProjectOrgGroupsInput!): String
getEnvVariablesByProjectEnvironmentName(input: EnvVariableByProjectEnvironmentNameInput!): [EnvKeyValue]
Expand Down

0 comments on commit e5fc509

Please sign in to comment.