fix(api): 🐛 Correctly calculate user based on token

This commit is contained in:
Jesse Wierzbinski 2025-01-02 03:36:54 +01:00
parent 8706c7b405
commit 59cf4e384a
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ import type {
PushSubscription as ApiPushSubscription, PushSubscription as ApiPushSubscription,
} from "@versia/client/types"; } from "@versia/client/types";
import { type Token, type User, db } from "@versia/kit/db"; import { type Token, type User, db } from "@versia/kit/db";
import { PushSubscriptions, Users } from "@versia/kit/tables"; import { PushSubscriptions, Tokens } from "@versia/kit/tables";
import { import {
type InferInsertModel, type InferInsertModel,
type InferSelectModel, type InferSelectModel,
@ -141,20 +141,15 @@ export class PushSubscription extends BaseInterface<
limit?: number, limit?: number,
offset?: number, offset?: number,
): Promise<PushSubscription[]> { ): Promise<PushSubscription[]> {
const found = await db.query.PushSubscriptions.findMany({ const found = await db
where: (): SQL => eq(Users.id, user.id), .select()
limit, .from(PushSubscriptions)
offset, .leftJoin(Tokens, eq(Tokens.id, PushSubscriptions.tokenId))
with: { .where(eq(Tokens.userId, user.id))
token: { .limit(limit ?? 9e10)
with: { .offset(offset ?? 0);
user: true,
},
},
},
});
return found.map((s) => new PushSubscription(s)); return found.map((s) => new PushSubscription(s.PushSubscriptions));
} }
public static async fromSql( public static async fromSql(