feat: premium workspace usernames
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
16
packages/db/src/repository/workspaceSlug.repo.ts
Normal file
16
packages/db/src/repository/workspaceSlug.repo.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user