fix: prevent creating multiple platform orgs (#16629)

* set error messages to know whats wrong

* trying to find if org with same owner already exists

* ensure a user cannot create more than one platform team

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
Rajiv SahalandAnik Dhabal Babu authored and GitHub committed 2024-09-13 23:37:48 +01:00
1 parent e3e2bc804a
commit a775e42e85
2 files changed
+12

No files matched your search

@@ -104,6 +104,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
team: {
select: {
slug: true,
isOrganization: true,
isPlatform: true,
},
},
},
@@ -160,6 +162,14 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
if (hasAnOrgWithSameSlug || RESERVED_SUBDOMAINS.includes(slug))
throw new TRPCError({ code: "BAD_REQUEST", message: "organization_url_taken" });
const hasExistingPlatformOrOrgTeam = loggedInUser?.teams.find((team) => {
return team.team.isPlatform || team.team.isOrganization;
});
if (!!hasExistingPlatformOrOrgTeam?.team && isPlatform) {
throw new TRPCError({ code: "BAD_REQUEST", message: "User is already part of a team" });
}
const availability = getAvailabilityFromSchedule(DEFAULT_SCHEDULE);
const isOrganizationConfigured = isPlatform ? true : await createDomain(slug);