mirror of
https://github.com/versia-pub/server.git
synced 2026-01-26 12:16:01 +01:00
fix(api): 🐛 Correctly calculate user based on token
This commit is contained in:
parent
8706c7b405
commit
59cf4e384a
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue