Skip to content

Commit

Permalink
feat(teams): Add custom team ID generation on creation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
toyamarinyon committed Dec 26, 2024
1 parent 940f029 commit b5896be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions services/accounts/actions/initialize-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -33,6 +34,7 @@ export const initializeAccount = async (
const [team] = await tx
.insert(teams)
.values({
id: createTeamId(),
name: "default",
type: isEmailFromRoute06(supabaseUserEmail ?? "")
? "internal"
Expand Down
2 changes: 2 additions & 0 deletions services/external/stripe/actions/upsert-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -96,6 +97,7 @@ async function createTeam(
const [team] = await tx
.insert(teams)
.values({
id: createTeamId(),
name: teamName,
})
.returning({ dbid: teams.dbId });
Expand Down

0 comments on commit b5896be

Please sign in to comment.