add last sync time

This commit is contained in:
Daniel Bulant 2026-05-01 02:11:39 +02:00
parent 575374547c
commit a1beff806b
No known key found for this signature in database
4 changed files with 22 additions and 9 deletions

View file

@ -20,6 +20,15 @@ export const defaultSdk = SpotifyApi.withClientCredentials(
);
export const auth = betterAuth({
user: {
additionalFields: {
lastSyncAt: {
type: "date",
required: false,
input: false,
},
},
},
database: drizzleAdapter(db, {
provider: "pg",
schema,

View file

@ -12,6 +12,7 @@ export const user = pgTable("user", {
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
lastSyncAt: timestamp("last_sync_at"),
});
export const session = pgTable(

View file

@ -16,6 +16,7 @@ import {
savedTrack,
topArtist,
topTrack,
user,
} from "../db/schema";
import {
upsertFollowedArtists,
@ -45,6 +46,7 @@ export class SpotifySyncWorkflow extends ConfiguredInstance {
const data = await this.fetchSpotifyData(userId);
console.log("Sync data fetched");
await this.persistSpotifyData(userId, data);
await this.updateSyncTime(userId);
console.log("Synced");
return { ok: true };
}
@ -142,6 +144,14 @@ export class SpotifySyncWorkflow extends ConfiguredInstance {
});
}
@DBOS.step()
private async updateSyncTime(userId: string) {
await db
.update(user)
.set({ lastSyncAt: new Date() })
.where(eq(user.id, userId));
}
@DBOS.step()
private async fetchTopArtists(
userId: string,

View file

@ -1,15 +1,8 @@
import { createServerFn } from "@tanstack/react-start";
import type { User } from "../../../api/src/party-types";
export interface AuthSession {
user: {
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
emailVerified: boolean;
name: string;
image?: string | null | undefined;
};
user: User;
session: {
id: string;
createdAt: Date;