fix: allow team with same slug for diff cases (#24029)
* fix: aalow team with slug for diff cases * addressed review * fix type error * update test * addressed review * fix test * Update team.ts --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
6 files changed
+201
-27
No files matched your search
@@ -4,6 +4,7 @@ import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
|
||||
import { uploadLogo } from "@calcom/lib/server/avatar";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole, RedirectType, RRTimestampBasis } from "@calcom/prisma/enums";
|
||||
@@ -39,12 +40,16 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
}
|
||||
|
||||
if (input.slug) {
|
||||
const userConflict = await prisma.team.findMany({
|
||||
where: {
|
||||
slug: input.slug,
|
||||
},
|
||||
const orgId = ctx.user.organizationId;
|
||||
const teamRepository = new TeamRepository(prisma);
|
||||
const isSlugAvailable = await teamRepository.isSlugAvailableForUpdate({
|
||||
slug: input.slug,
|
||||
teamId: input.id,
|
||||
parentId: orgId,
|
||||
});
|
||||
if (userConflict.some((t) => t.id !== input.id)) return;
|
||||
if (!isSlugAvailable) {
|
||||
throw new TRPCError({ code: "CONFLICT", message: "Slug already in use." });
|
||||
}
|
||||
}
|
||||
|
||||
const prevTeam = await prisma.team.findUnique({
|
||||
|
||||
Reference in new issue
Block a user