fix: reenable member invites

This commit is contained in:
Henry
2025-05-22 12:18:56 +01:00
parent 82ec18e95e
commit 71c92eea27
16 changed files with 2183 additions and 231 deletions

View File

@@ -8,7 +8,8 @@ import { generateUID } from "@kan/shared/utils";
export const create = async (
db: dbClient,
memberInput: {
userId: string;
userId: string | null;
email: string;
workspaceId: number;
createdBy: string;
role: MemberRole;
@@ -19,6 +20,7 @@ export const create = async (
.insert(workspaceMembers)
.values({
publicId: generateUID(),
email: memberInput.email,
userId: memberInput.userId,
workspaceId: memberInput.workspaceId,
createdBy: memberInput.createdBy,
@@ -39,11 +41,14 @@ export const getByPublicId = async (db: dbClient, publicId: string) => {
});
};
export const acceptInvite = async (db: dbClient, id: number) => {
export const acceptInvite = async (
db: dbClient,
args: { memberId: number; userId: string },
) => {
const [result] = await db
.update(workspaceMembers)
.set({ status: "active" })
.where(eq(workspaceMembers.id, id))
.set({ status: "active", userId: args.userId })
.where(eq(workspaceMembers.id, args.memberId))
.returning({
id: workspaceMembers.id,
publicId: workspaceMembers.publicId,

View File

@@ -1,4 +1,5 @@
import { eq } from "drizzle-orm";
import { v4 as uuidv4 } from "uuid";
import type { dbClient } from "@kan/db/client";
import { users } from "@kan/db/schema";
@@ -29,12 +30,12 @@ export const getByEmail = (db: dbClient, email: string) => {
export const create = async (
db: dbClient,
user: { id: string; email: string; stripeCustomerId: string },
user: { id?: string; email: string; stripeCustomerId?: string },
) => {
const [result] = await db
.insert(users)
.values({
id: user.id,
id: user.id ?? uuidv4(),
email: user.email,
stripeCustomerId: user.stripeCustomerId,
emailVerified: false,

View File

@@ -11,6 +11,7 @@ export const create = async (
name: string;
slug: string;
createdBy: string;
createdByEmail: string;
},
) => {
const [workspace] = await db
@@ -34,6 +35,7 @@ export const create = async (
await db.insert(workspaceMembers).values({
publicId: generateUID(),
userId: workspaceInput.createdBy,
email: workspaceInput.createdByEmail,
workspaceId: workspace.id,
createdBy: workspaceInput.createdBy,
role: "admin",
@@ -103,6 +105,7 @@ export const getByPublicIdWithMembers = (
members: {
columns: {
publicId: true,
email: true,
role: true,
status: true,
},
@@ -171,6 +174,7 @@ export const getAllByUserId = (db: dbClient, userId: string) => {
},
where: and(
eq(workspaceMembers.userId, userId),
eq(workspaceMembers.status, "active"),
isNull(workspaceMembers.deletedAt),
),
});

View File

@@ -54,9 +54,8 @@ export const workspaceRelations = relations(workspaces, ({ one, many }) => ({
export const workspaceMembers = pgTable("workspace_members", {
id: bigserial("id", { mode: "number" }).primaryKey(),
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
userId: uuid("userId")
.notNull()
.references(() => users.id),
email: varchar("email", { length: 255 }).notNull(),
userId: uuid("userId").references(() => users.id),
workspaceId: bigint("workspaceId", { mode: "number" })
.notNull()
.references(() => workspaces.id, { onDelete: "cascade" }),