sharing logic

This commit is contained in:
Ishaan Dey
2024-05-01 01:53:49 -04:00
parent 66a76eb0f9
commit 5ba1c03030
8 changed files with 90 additions and 38 deletions

View File

@ -36,6 +36,9 @@ export default {
const id = params.get("id") as string;
const res = await db.query.sandbox.findFirst({
where: (sandbox, { eq }) => eq(sandbox.id, id),
with: {
usersToSandboxes: true,
},
});
return json(res ?? {});
} else {
@ -99,9 +102,18 @@ export default {
const user = await db.query.user.findFirst({
where: (user, { eq }) => eq(user.email, email),
with: {
usersToSandboxes: true,
},
});
if (!user) return invalidRequest;
if (!user) {
return new Response("No user associated with email.", { status: 400 });
}
if (user.usersToSandboxes.find((uts) => uts.sandboxId === sandboxId)) {
return new Response("User already has access.", { status: 400 });
}
await db.insert(usersToSandboxes).values({ userId: user.id, sandboxId }).get();

View File

@ -5,6 +5,10 @@ export type User = {
name: string
email: string
sandbox: Sandbox[]
usersToSandboxes: {
userId: string
sandboxId: string
}[]
}
export type Sandbox = {
@ -13,6 +17,10 @@ export type Sandbox = {
type: "react" | "node"
visibility: "public" | "private"
userId: string
usersToSandboxes: {
userId: string
sandboxId: string
}[]
}
export type TFolder = {