mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import {
|
|
accountNotFound,
|
|
apiRoute,
|
|
auth,
|
|
reusedResponses,
|
|
withUserParam,
|
|
} from "@/api";
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
|
import {
|
|
Account as AccountSchema,
|
|
Relationship as RelationshipSchema,
|
|
} from "@versia/client/schemas";
|
|
import { RolePermission } from "@versia/client/schemas";
|
|
import { Relationship } from "@versia/kit/db";
|
|
|
|
const route = createRoute({
|
|
method: "post",
|
|
path: "/api/v1/accounts/{id}/unblock",
|
|
summary: "Unblock account",
|
|
description: "Unblock the given account.",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/methods/accounts/#unblock",
|
|
},
|
|
tags: ["Accounts"],
|
|
middleware: [
|
|
auth({
|
|
auth: true,
|
|
scopes: ["write:blocks"],
|
|
permissions: [
|
|
RolePermission.ManageOwnBlocks,
|
|
RolePermission.ViewAccounts,
|
|
],
|
|
}),
|
|
withUserParam,
|
|
] as const,
|
|
request: {
|
|
params: z.object({
|
|
id: AccountSchema.shape.id,
|
|
}),
|
|
},
|
|
responses: {
|
|
200: {
|
|
description:
|
|
"Successfully unblocked, or account was already not blocked",
|
|
content: {
|
|
"application/json": {
|
|
schema: RelationshipSchema,
|
|
},
|
|
},
|
|
},
|
|
404: accountNotFound,
|
|
...reusedResponses,
|
|
},
|
|
});
|
|
|
|
export default apiRoute((app) =>
|
|
app.openapi(route, async (context) => {
|
|
const { user } = context.get("auth");
|
|
const otherUser = context.get("user");
|
|
|
|
const foundRelationship = await Relationship.fromOwnerAndSubject(
|
|
user,
|
|
otherUser,
|
|
);
|
|
|
|
if (foundRelationship.data.blocking) {
|
|
await foundRelationship.update({
|
|
blocking: false,
|
|
});
|
|
}
|
|
|
|
return context.json(foundRelationship.toApi(), 200);
|
|
}),
|
|
);
|