feat: create route to store FCM token
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user