feat: public workspace
This commit is contained in:
@@ -64,6 +64,29 @@ export const workspaceRouter = createTRPCRouter({
|
||||
code: "NOT_FOUND",
|
||||
});
|
||||
|
||||
return result;
|
||||
}),
|
||||
bySlug: publicProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
summary: "Get a workspace by slug",
|
||||
method: "GET",
|
||||
path: "/workspaces/slug/{workspaceSlug}",
|
||||
description: "Retrieves a workspace by its slug",
|
||||
tags: ["Workspaces"],
|
||||
protect: true,
|
||||
},
|
||||
})
|
||||
.input(z.object({ workspaceSlug: z.string().min(3).max(24) }))
|
||||
.output(
|
||||
z.custom<Awaited<ReturnType<typeof workspaceRepo.getBySlugWithBoards>>>(),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const result = await workspaceRepo.getBySlugWithBoards(
|
||||
ctx.db,
|
||||
input.workspaceSlug,
|
||||
);
|
||||
|
||||
return result;
|
||||
}),
|
||||
create: protectedProcedure
|
||||
|
||||
@@ -101,6 +101,32 @@ export const getByPublicIdWithMembers = async (
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getBySlugWithBoards = async (
|
||||
db: SupabaseClient<Database>,
|
||||
workspaceSlug: string,
|
||||
) => {
|
||||
const { data } = await db
|
||||
.from("workspace")
|
||||
.select(
|
||||
`
|
||||
publicId,
|
||||
name,
|
||||
slug,
|
||||
boards: board (
|
||||
publicId,
|
||||
name
|
||||
)
|
||||
`,
|
||||
)
|
||||
.eq("slug", workspaceSlug)
|
||||
.is("deletedAt", null)
|
||||
.is("boards.deletedAt", null)
|
||||
.limit(1)
|
||||
.single();
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getAllByUserId = async (
|
||||
db: SupabaseClient<Database>,
|
||||
userId: string,
|
||||
|
||||
Reference in New Issue
Block a user