diff --git a/api/api/v1/accounts/id/index.test.ts b/api/api/v1/accounts/id/index.test.ts deleted file mode 100644 index fd446335..00000000 --- a/api/api/v1/accounts/id/index.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { afterAll, describe, expect, test } from "bun:test"; -import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; - -const { users, deleteUsers } = await getTestUsers(5); - -afterAll(async () => { - await deleteUsers(); -}); - -// /api/v1/accounts/id -describe("/api/v1/accounts/id", () => { - test("should correctly get user from username", async () => { - const response = await fakeRequest( - `/api/v1/accounts/id?username=${users[0].data.username}`, - ); - - expect(response.status).toBe(200); - - const data = (await response.json()) as ApiAccount; - - expect(data.id).toBe(users[0].id); - }); - - test("should return 404 for non-existent user", async () => { - const response = await fakeRequest( - "/api/v1/accounts/id?username=nonexistent", - ); - - expect(response.status).toBe(404); - }); -}); diff --git a/api/api/v1/accounts/id/index.ts b/api/api/v1/accounts/id/index.ts deleted file mode 100644 index a973430d..00000000 --- a/api/api/v1/accounts/id/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { accountNotFound, apiRoute, auth, reusedResponses } from "@/api"; -import { createRoute, z } from "@hono/zod-openapi"; -import { Account as AccountSchema } from "@versia/client-ng/schemas"; -import { User } from "@versia/kit/db"; -import { RolePermissions, Users } from "@versia/kit/tables"; -import { and, eq, isNull } from "drizzle-orm"; -import { ApiError } from "~/classes/errors/api-error"; - -const route = createRoute({ - method: "get", - path: "/api/v1/accounts/id", - summary: "Get account by username", - description: "Get an account by username", - tags: ["Accounts"], - middleware: [ - auth({ - auth: false, - permissions: [RolePermissions.Search], - }), - ] as const, - request: { - query: z.object({ - username: AccountSchema.shape.username.transform((v) => - v.toLowerCase(), - ), - }), - }, - responses: { - 200: { - description: "Account", - content: { - "application/json": { - schema: AccountSchema, - }, - }, - }, - 404: accountNotFound, - 422: reusedResponses[422], - }, -}); - -export default apiRoute((app) => - app.openapi(route, async (context) => { - const { username } = context.req.valid("query"); - - const user = await User.fromSql( - and(eq(Users.username, username), isNull(Users.instanceId)), - ); - - if (!user) { - throw new ApiError(404, "User not found"); - } - - return context.json(user.toApi(), 200); - }), -);