From b5896be5f22364441081f36237f59244fc712efa Mon Sep 17 00:00:00 2001 From: satoshi toyama Date: Thu, 26 Dec 2024 17:09:29 +0900 Subject: [PATCH] feat(teams): Add custom team ID generation on creation Add createTeamId() function usage when initializing new teams to ensure consistent ID format and uniqueness. This change affects both regular account initialization and Stripe subscription team creation flows. The custom team IDs provide: - Better readability and consistency across the system - Guaranteed uniqueness through the createTeamId utility - Improved traceability of team creation source --- services/accounts/actions/initialize-account.ts | 2 ++ services/external/stripe/actions/upsert-subscription.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/services/accounts/actions/initialize-account.ts b/services/accounts/actions/initialize-account.ts index 7727a8b6..7663843c 100644 --- a/services/accounts/actions/initialize-account.ts +++ b/services/accounts/actions/initialize-account.ts @@ -8,6 +8,7 @@ import { users, } from "@/drizzle"; import { isEmailFromRoute06 } from "@/lib/utils"; +import { createTeamId } from "@/services/teams/utils"; import { createId } from "@paralleldrive/cuid2"; import type { User } from "@supabase/auth-js"; @@ -33,6 +34,7 @@ export const initializeAccount = async ( const [team] = await tx .insert(teams) .values({ + id: createTeamId(), name: "default", type: isEmailFromRoute06(supabaseUserEmail ?? "") ? "internal" diff --git a/services/external/stripe/actions/upsert-subscription.ts b/services/external/stripe/actions/upsert-subscription.ts index 33f23729..c9832c01 100644 --- a/services/external/stripe/actions/upsert-subscription.ts +++ b/services/external/stripe/actions/upsert-subscription.ts @@ -4,6 +4,7 @@ import { DRAFT_TEAM_USER_DB_ID_METADATA_KEY, UPGRADING_TEAM_DB_ID_KEY, } from "@/services/teams/constants"; +import { createTeamId } from "@/services/teams/utils"; import { eq } from "drizzle-orm"; import type Stripe from "stripe"; import { stripe } from "../config"; @@ -96,6 +97,7 @@ async function createTeam( const [team] = await tx .insert(teams) .values({ + id: createTeamId(), name: teamName, }) .returning({ dbid: teams.dbId });