add last sync time
This commit is contained in:
parent
575374547c
commit
a1beff806b
4 changed files with 22 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const user = pgTable("user", {
|
|||
.defaultNow()
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
lastSyncAt: timestamp("last_sync_at"),
|
||||
});
|
||||
|
||||
export const session = pgTable(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue