From 2169d29c17deec0f9c25012c7ee21b801422c2fa Mon Sep 17 00:00:00 2001 From: Lars Hampe Date: Thu, 24 Oct 2024 21:53:42 +0200 Subject: [PATCH] chore: remove unused code --- apps/api/src/changelog/public/byId.ts | 55 -------------------------- apps/api/src/changelog/public/index.ts | 27 ------------- apps/api/src/index.ts | 2 - 3 files changed, 84 deletions(-) delete mode 100644 apps/api/src/changelog/public/byId.ts delete mode 100644 apps/api/src/changelog/public/index.ts diff --git a/apps/api/src/changelog/public/byId.ts b/apps/api/src/changelog/public/byId.ts deleted file mode 100644 index 24d3fb9..0000000 --- a/apps/api/src/changelog/public/byId.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { changelog, changelog_version, db } from '@boring.tools/database' -import { ChangelogByIdParams, ChangelogOutput } from '@boring.tools/schema' -import { createRoute } from '@hono/zod-openapi' -import { and, eq } from 'drizzle-orm' -import { HTTPException } from 'hono/http-exception' - -export const route = createRoute({ - method: 'get', - path: '/:id', - request: { - params: ChangelogByIdParams, - }, - responses: { - 200: { - content: { - 'application/json': { - schema: ChangelogOutput, - }, - }, - description: 'Return changelog by id', - }, - 400: { - description: 'Bad Request', - }, - 500: { - description: 'Internal Server Error', - }, - }, -}) - -export const func = async ({ id }: { id: string }) => { - const result = await db.query.changelog.findFirst({ - where: and(eq(changelog.id, id)), - with: { - versions: { - where: eq(changelog_version.status, 'published'), - orderBy: (changelog_version, { desc }) => [ - desc(changelog_version.createdAt), - ], - }, - }, - }) - - if (!result) { - throw new HTTPException(404, { message: 'Not found' }) - } - - const { userId, createdAt, ...rest } = result - return rest -} - -export default { - route, - func, -} diff --git a/apps/api/src/changelog/public/index.ts b/apps/api/src/changelog/public/index.ts deleted file mode 100644 index fc04ac9..0000000 --- a/apps/api/src/changelog/public/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { OpenAPIHono } from '@hono/zod-openapi' -import type { Variables } from '../..' -import { type ContextModule, captureSentry } from '../../utils/sentry' -import ById from './byId' - -const app = new OpenAPIHono<{ Variables: Variables }>() - -const module: ContextModule = { - name: 'changelog', - sub_module: 'public', -} - -app.openapi(ById.route, async (c) => { - try { - const id = c.req.param('id') - const result = await ById.func({ id }) - return c.json(result, 200) - } catch (error) { - return captureSentry({ - c, - error, - module, - }) - } -}) - -export default app diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index aec52d6..b7b65bc 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -5,7 +5,6 @@ import { apiReference } from '@scalar/hono-api-reference' import { cors } from 'hono/cors' import changelog from './changelog' -import changelogPublic from './changelog/public' import version from './changelog/version' import user from './user' @@ -38,7 +37,6 @@ app.route('/v1/user', user) app.route('/v1/changelog', changelog) app.route('/v1/changelog/version', version) app.route('/v1/page', pageApi) -app.route('/v1/changelog/public', changelogPublic) app.doc('/openapi.json', { openapi: '3.0.0',