server/api/api/v1/accounts/:id/pin.ts
Jesse Wierzbinski e3e285571e
Some checks failed
Mirror to Codeberg / Mirror (push) Failing after 0s
refactor(api): 🏷️ Port all /api/v1/accounts to use new schemas
2025-02-13 01:31:15 +01:00

63 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { apiRoute, auth, withUserParam } from "@/api";
import { createRoute, z } from "@hono/zod-openapi";
import { Relationship } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import { Account as AccountSchema } from "~/classes/schemas/account";
import { Relationship as RelationshipSchema } from "~/classes/schemas/relationship";
const route = createRoute({
method: "post",
path: "/api/v1/accounts/{id}/pin",
summary: "Feature account on your profile",
description:
"Add the given account to the users featured profiles. (Featured profiles are currently shown on the users own public profile.)",
externalDocs: {
url: "https://docs.joinmastodon.org/methods/accounts/#pin",
},
tags: ["Accounts"],
middleware: [
auth({
auth: true,
scopes: ["write:accounts"],
permissions: [
RolePermissions.ManageOwnAccount,
RolePermissions.ViewAccounts,
],
}),
withUserParam,
] as const,
request: {
params: z.object({
id: AccountSchema.shape.id,
}),
},
responses: {
200: {
description: "Updated relationship",
content: {
"application/json": {
schema: RelationshipSchema,
},
},
},
},
});
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,
);
await foundRelationship.update({
endorsed: true,
});
return context.json(foundRelationship.toApi(), 200);
}),
);