feat: premium workspace usernames

This commit is contained in:
Henry
2025-01-02 20:40:29 +00:00
parent b5dc9433db
commit 67e714b8b0
41 changed files with 1767 additions and 9088 deletions

View File

@@ -5,7 +5,7 @@ import type { Database } from "@kan/db/types/database.types";
export const getById = async (db: SupabaseClient<Database>, userId: string) => {
const { data } = await db
.from("user")
.select(`id, name, email`)
.select(`id, name, email, stripeCustomerId`)
.eq("id", userId)
.limit(1)
.single();
@@ -29,11 +29,15 @@ export const getByEmail = async (
export const create = async (
db: SupabaseClient<Database>,
user: { id: string; email: string },
user: { id: string; email: string; stripeCustomerId: string },
) => {
const { data } = await db
.from("user")
.insert({ id: user.id, email: user.email })
.insert({
id: user.id,
email: user.email,
stripeCustomerId: user.stripeCustomerId,
})
.select()
.limit(1)
.single();

View File

@@ -159,3 +159,18 @@ export const hardDelete = async (
return result;
};
export const isWorkspaceSlugAvailable = async (
db: SupabaseClient<Database>,
workspaceSlug: string,
) => {
const { data } = await db
.from("workspace")
.select("id")
.eq("slug", workspaceSlug)
.is("deletedAt", null)
.limit(1)
.single();
return data === null;
};

View File

@@ -0,0 +1,16 @@
import type { SupabaseClient } from "@supabase/supabase-js";
import type { Database } from "@kan/db/types/database.types";
export const getWorkspaceSlug = async (
db: SupabaseClient<Database>,
slug: string,
) => {
const { data } = await db
.from("workspace_slugs")
.select(`slug, type`)
.eq("slug", slug)
.single();
return data;
};