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({
|
export const auth = betterAuth({
|
||||||
|
user: {
|
||||||
|
additionalFields: {
|
||||||
|
lastSyncAt: {
|
||||||
|
type: "date",
|
||||||
|
required: false,
|
||||||
|
input: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
database: drizzleAdapter(db, {
|
database: drizzleAdapter(db, {
|
||||||
provider: "pg",
|
provider: "pg",
|
||||||
schema,
|
schema,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export const user = pgTable("user", {
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||||
.notNull(),
|
.notNull(),
|
||||||
|
lastSyncAt: timestamp("last_sync_at"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const session = pgTable(
|
export const session = pgTable(
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
savedTrack,
|
savedTrack,
|
||||||
topArtist,
|
topArtist,
|
||||||
topTrack,
|
topTrack,
|
||||||
|
user,
|
||||||
} from "../db/schema";
|
} from "../db/schema";
|
||||||
import {
|
import {
|
||||||
upsertFollowedArtists,
|
upsertFollowedArtists,
|
||||||
|
|
@ -45,6 +46,7 @@ export class SpotifySyncWorkflow extends ConfiguredInstance {
|
||||||
const data = await this.fetchSpotifyData(userId);
|
const data = await this.fetchSpotifyData(userId);
|
||||||
console.log("Sync data fetched");
|
console.log("Sync data fetched");
|
||||||
await this.persistSpotifyData(userId, data);
|
await this.persistSpotifyData(userId, data);
|
||||||
|
await this.updateSyncTime(userId);
|
||||||
console.log("Synced");
|
console.log("Synced");
|
||||||
return { ok: true };
|
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()
|
@DBOS.step()
|
||||||
private async fetchTopArtists(
|
private async fetchTopArtists(
|
||||||
userId: string,
|
userId: string,
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,8 @@
|
||||||
import { createServerFn } from "@tanstack/react-start";
|
import { createServerFn } from "@tanstack/react-start";
|
||||||
|
import type { User } from "../../../api/src/party-types";
|
||||||
|
|
||||||
export interface AuthSession {
|
export interface AuthSession {
|
||||||
user: {
|
user: User;
|
||||||
id: string;
|
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
email: string;
|
|
||||||
emailVerified: boolean;
|
|
||||||
name: string;
|
|
||||||
image?: string | null | undefined;
|
|
||||||
};
|
|
||||||
session: {
|
session: {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue