fix: sandboxes now linked to specific users
This commit is contained in:
parent
e7dd3238df
commit
2994a4d291
@ -110,11 +110,16 @@ export default {
|
||||
const body = await request.json()
|
||||
const { type, name, userId, visibility } = initSchema.parse(body)
|
||||
|
||||
const allSandboxes = await db.select().from(sandbox).all()
|
||||
if (allSandboxes.length >= 8) {
|
||||
const userSandboxes = await db
|
||||
.select()
|
||||
.from(sandbox)
|
||||
.where(eq(sandbox.userId, userId))
|
||||
.all();
|
||||
|
||||
if (userSandboxes.length >= 8) {
|
||||
return new Response("You reached the maximum # of sandboxes.", {
|
||||
status: 400,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
const sb = await db
|
||||
@ -123,6 +128,12 @@ export default {
|
||||
.returning()
|
||||
.get()
|
||||
|
||||
// Create a new association record in the users_to_sandboxes table
|
||||
await db
|
||||
.insert(usersToSandboxes)
|
||||
.values({ userId, sandboxId: sb.id, sharedOn: new Date() })
|
||||
.get();
|
||||
|
||||
const initStorageRequest = new Request(
|
||||
`${env.STORAGE_WORKER_URL}/api/init`,
|
||||
{
|
||||
|
@ -31,8 +31,8 @@ export const sandbox = sqliteTable("sandbox", {
|
||||
createdAt: integer("createdAt", { mode: "timestamp_ms" }),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
});
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
});
|
||||
|
||||
export type Sandbox = typeof sandbox.$inferSelect;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user