aboutsummaryrefslogtreecommitdiffstats
path: root/server/db/groups.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/db/groups.ts')
-rw-r--r--server/db/groups.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/server/db/groups.ts b/server/db/groups.ts
new file mode 100644
index 0000000..1060501
--- /dev/null
+++ b/server/db/groups.ts
@@ -0,0 +1,27 @@
+import { db } from "./index";
+import crypto from "node:crypto";
+
+export function createGroup(name: string) {
+ const id = crypto.randomUUID();
+ const joinCode = crypto
+ .randomBytes(3)
+ .toString("hex")
+ .toUpperCase();
+
+ db.prepare(`
+ INSERT INTO groups
+ (id, name, join_code, created_at)
+ VALUES (?, ?, ?, ?)
+ `).run(
+ id,
+ name,
+ joinCode,
+ Date.now()
+ );
+
+ return {
+ id,
+ name,
+ joinCode
+ };
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage