mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
Complete migration to Prisma, all tests passing
This commit is contained in:
parent
dc0ec47543
commit
3884763235
18 changed files with 74 additions and 39 deletions
|
|
@ -102,5 +102,5 @@ export default async (
|
|||
},
|
||||
});
|
||||
|
||||
return jsonResponse(relationshipToAPI(relationship));
|
||||
return jsonResponse(await relationshipToAPI(relationship));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ export default async (
|
|||
include: statusAndUserRelations,
|
||||
take: limit ?? 20,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export default async (
|
|||
},
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ export default async (
|
|||
},
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export default async (req: Request): Promise<Response> => {
|
|||
include: statusAndUserRelations,
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export default async (req: Request): Promise<Response> => {
|
|||
include: statusAndUserRelations,
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: "desc",
|
||||
id: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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("+", " "),
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue