mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
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 user’s featured profiles. (Featured profiles are currently shown on the user’s 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);
|
||
}),
|
||
);
|