-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutations.ts
More file actions
30 lines (25 loc) · 825 Bytes
/
mutations.ts
File metadata and controls
30 lines (25 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { db } from "~/server/db";
import {
type File,
folders_table as folderSchema,
files_table as filesSchema,
} from "~/server/db/schema";
export async function onboardUser(userId: string) {
const [rootFolder] = await db
.insert(folderSchema)
.values({ name: "root", parent: null, ownerId: userId })
.$returningId();
const rootFolderId = rootFolder!.id;
await db.insert(folderSchema).values([
{ name: "Trash", parent: rootFolderId, ownerId: userId },
{ name: "Shared", parent: rootFolderId, ownerId: userId },
{ name: "Documents", parent: rootFolderId, ownerId: userId },
]);
return rootFolderId;
}
export function createFile(
file: Pick<File, "name" | "size" | "url" | "parent">,
userId: string,
) {
return db.insert(filesSchema).values({ ...file, ownerId: userId });
}