feat: create route to store FCM token

This commit is contained in:
2024-06-14 18:14:10 -04:00
parent 4d3c34579d
commit 231ed4bde4
16 changed files with 650 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ import { eq, sql } from "drizzle-orm";
import type { Env } from "~/types/env";
import { getDb } from "./db";
import { tokenTable } from "./schema";
import { deviceTokensTable } from "./schema";
export function saveToken(
env: Env,
@@ -12,15 +12,15 @@ export function saveToken(
username: string | null,
) {
return getDb(env)
.insert(tokenTable)
.insert(deviceTokensTable)
.values({ deviceId, token, username })
.run();
}
export function updateDeviceLastConnectedAt(env: Env, deviceId: string) {
return getDb(env)
.update(tokenTable)
.update(deviceTokensTable)
.set({ lastConnectedAt: sql`(CURRENT_TIMESTAMP)` })
.where(eq(tokenTable.deviceId, deviceId))
.where(eq(deviceTokensTable.deviceId, deviceId))
.run();
}