Skip to content

Commit

Permalink
Merge pull request #3576 from uselagoon/add-org-error
Browse files Browse the repository at this point in the history
chore: duplicate organization name error
  • Loading branch information
tobybellwood authored Oct 30, 2023
2 parents 35965a8 + 3a2ee63 commit 32811ba
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions services/api/src/resources/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const addOrganization: ResolverFn = async (
isValidName(input.name)

try {
await hasPermission('organization', 'add');
await hasPermission('organization', 'add');
const org = await query(sqlClientPool, Sql.selectOrganizationByName(input.name));
// if no organization found, create it
if (R.length(org) == 0) {
const { insertId } = await query(sqlClientPool, Sql.insertOrganization(input));
const rows = await query(sqlClientPool, Sql.selectOrganization(insertId));

Expand All @@ -49,8 +52,11 @@ export const addOrganization: ResolverFn = async (
});

return R.prop(0, rows);
} else {
throw new Error(`There was an error creating the organization, ${input.name} already exists`);
}
} catch (err) {
throw new Error(`There was an error creating the organization ${input.name} ${err}`);
throw new Error(`There was an error creating the organization ${input.name} ${err}`);
}
};

Expand Down

0 comments on commit 32811ba

Please sign in to comment.