diff --git a/services/api/src/resolvers.js b/services/api/src/resolvers.js index f27b71fb0a..5c0972caab 100644 --- a/services/api/src/resolvers.js +++ b/services/api/src/resolvers.js @@ -247,7 +247,7 @@ const { getUsersByOrganizationId, getUserByEmailAndOrganizationId, getGroupRolesByUserIdAndOrganization, - getGroupsByNameAndOrganizationId, + getGroupByNameAndOrganizationId, getOwnersByOrganizationId, getProjectsByOrganizationId, addExistingProjectToOrganization, @@ -538,7 +538,7 @@ const resolvers = { orgProjectByName: getProjectByName, environmentsByKubernetes: getEnvironmentsByKubernetes, groupByName: getGroupByName, - groupByNameAndOrganization: getGroupsByNameAndOrganizationId, + groupByNameAndOrganization: getGroupByNameAndOrganizationId, usersByOrganization: getUsersByOrganizationId, userByEmailAndOrganization: getUserByEmailAndOrganizationId, problemSources: getProblemSources, diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index 7eeeced9a4..01901be5b1 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -2,6 +2,7 @@ import * as R from 'ramda'; import { ResolverFn } from '../'; import { logger } from '../../loggers/logger'; import { query, isPatchEmpty, knex } from '../../util/db'; +import { GroupNotFoundError } from '../../models/group'; import { Helpers as projectHelpers } from '../project/helpers'; import { Helpers} from './helpers'; import { Sql } from './sql'; @@ -489,25 +490,22 @@ export const getGroupRolesByUserIdAndOrganization: ResolverFn =async ( } // list all groups by organization id -export const getGroupsByNameAndOrganizationId: ResolverFn = async ( - root, +export const getGroupByNameAndOrganizationId: ResolverFn = async ( + _, { name, organization }, - { hasPermission, models, keycloakGrant } + { hasPermission, models } ) => { - try { - await hasPermission('organization', 'viewGroup', { - organization: organization, - }); + await hasPermission('organization', 'viewGroup', { + organization: organization, + }); - const group = await models.GroupModel.loadGroupByName(name); - const groupOrg = group.attributes?.['lagoon-organization']?.[0]; - if (groupOrg && toNumber(groupOrg) == organization) { - return group - } - } catch (err) { - return []; + const group = await models.GroupModel.loadGroupByName(name); + const groupOrg = group.attributes?.['lagoon-organization']?.[0]; + if (!groupOrg || toNumber(groupOrg) != organization) { + throw new GroupNotFoundError(`Group not found: ${name}`); } - return []; + + return group; }; export const getGroupCountByOrganizationProject: ResolverFn = async (