Complete migration to Prisma, all tests passing

This commit is contained in:
Jesse Wierzbinski 2023-11-11 20:39:59 -10:00
parent dc0ec47543
commit 3884763235
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
18 changed files with 74 additions and 39 deletions

View file

@ -102,5 +102,5 @@ export default async (
},
});
return jsonResponse(relationshipToAPI(relationship));
return jsonResponse(await relationshipToAPI(relationship));
};

View file

@ -85,8 +85,7 @@ export default async (
if (user.instanceId === null) {
// Also remove from followers list
await client.relationship.update({
// @ts-expect-error Idk why there's this error
await client.relationship.updateMany({
where: {
ownerId: user.id,
subjectId: self.id,

View file

@ -67,7 +67,7 @@ export default async (
include: statusAndUserRelations,
take: limit ?? 20,
orderBy: {
id: "desc",
id: "asc",
},
});

View file

@ -57,7 +57,7 @@ export default async (req: Request): Promise<Response> => {
some: {
ownerId: self.id,
subjectId: {
in: followersOfIds.map(u => u.id),
in: followersOfIds.map(f => f.id),
},
following: true,
},

View file

@ -238,11 +238,7 @@ export default async (req: Request): Promise<Response> => {
id: e.id,
})),
},
source: user.source
? {
update: user.source,
}
: undefined,
source: user.source || undefined,
},
});

View file

@ -22,8 +22,7 @@ export default async (req: Request): Promise<Response> => {
if (!user) return errorResponse("Unauthorized", 401);
return jsonResponse({
...(await userToAPI(user)),
source: user.source,
...(await userToAPI(user, true)),
// TODO: Add role support
role: {
id: 0,

View file

@ -86,7 +86,7 @@ export default async (
},
take: limit,
orderBy: {
id: "desc",
id: "asc",
},
});

View file

@ -40,7 +40,7 @@ export default async (
});
// Check if user is authorized to view this status (if it's private)
if (!status || isViewableByUser(status, user))
if (!status || !isViewableByUser(status, user))
return errorResponse("Record not found", 404);
if (req.method === "GET") {

View file

@ -87,7 +87,7 @@ export default async (
},
take: limit,
orderBy: {
id: "desc",
id: "asc",
},
});

View file

@ -62,7 +62,7 @@ export default async (req: Request): Promise<Response> => {
include: statusAndUserRelations,
take: limit,
orderBy: {
id: "desc",
id: "asc",
},
});

View file

@ -62,7 +62,7 @@ export default async (req: Request): Promise<Response> => {
include: statusAndUserRelations,
take: limit,
orderBy: {
id: "desc",
id: "asc",
},
});

View file

@ -3,6 +3,7 @@ import { errorResponse } from "@response";
import { MatchedRoute } from "bun";
import { randomBytes } from "crypto";
import { client } from "~database/datasource";
import { TokenType } from "~database/entities/Token";
import { userRelations } from "~database/entities/User";
import { APIRouteMeta } from "~types/api";
@ -63,15 +64,17 @@ export default async (
if (!application) return errorResponse("Invalid client_id", 404);
const token = await client.application.update({
const code = randomBytes(32).toString("hex");
await client.application.update({
where: { id: application.id },
data: {
tokens: {
create: {
access_token: randomBytes(64).toString("base64url"),
code: randomBytes(32).toString("hex"),
code: code,
scope: scopes.join(" "),
token_type: "bearer",
token_type: TokenType.BEARER,
user: {
connect: {
id: user.id,
@ -83,5 +86,5 @@ export default async (
});
// Redirect back to application
return Response.redirect(`${redirect_uri}?code=${token.secret}`, 302);
return Response.redirect(`${redirect_uri}?code=${code}`, 302);
};

View file

@ -43,6 +43,7 @@ export default async (req: Request): Promise<Response> => {
client_id,
secret: client_secret,
redirect_uris: redirect_uri,
scopes: scope?.replaceAll("+", " "),
},
scope: scope?.replaceAll("+", " "),
},