diff --git a/package.json b/package.json index ad39aa4..ef959dd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "main": "dist/server.js", "scripts": { - "dev": "ts-node-dev --respawn --transpile-only --exit-child src/server.ts", + "dev": "ts-node-dev --respawn --transpile-only --exit-child -r tsconfig-paths/register src/server.ts", "build": "prisma generate && tsc", "start": "node dist/server.js", "prisma:generate": "prisma generate", @@ -59,6 +59,7 @@ "prettier": "^3.6.2", "prisma": "^6.18.0", "ts-node-dev": "^2.0.0", + "tsconfig-paths": "^4.2.0", "typescript": "^5.9.3", "typescript-eslint": "^8.46.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8500ab9..ba86b56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -116,6 +116,9 @@ importers: ts-node-dev: specifier: ^2.0.0 version: 2.0.0(@types/node@24.9.1)(typescript@5.9.3) + tsconfig-paths: + specifier: ^4.2.0 + version: 4.2.0 typescript: specifier: ^5.9.3 version: 5.9.3 @@ -2421,6 +2424,14 @@ packages: integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==, } + json5@2.2.3: + resolution: + { + integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==, + } + engines: { node: '>=6' } + hasBin: true + jsonparse@1.3.1: resolution: { @@ -3628,6 +3639,13 @@ packages: '@swc/wasm': optional: true + tsconfig-paths@4.2.0: + resolution: + { + integrity: sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==, + } + engines: { node: '>=6' } + tsconfig@7.0.0: resolution: { @@ -5299,6 +5317,8 @@ snapshots: json-stable-stringify-without-jsonify@1.0.1: {} + json5@2.2.3: {} + jsonparse@1.3.1: {} keyv@4.5.4: @@ -5928,6 +5948,12 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + tsconfig-paths@4.2.0: + dependencies: + json5: 2.2.3 + minimist: 1.2.8 + strip-bom: 3.0.0 + tsconfig@7.0.0: dependencies: '@types/strip-bom': 3.0.0 diff --git a/src/routes/auth.ts b/src/routes/auth.ts index ec471f4..c922cc6 100644 --- a/src/routes/auth.ts +++ b/src/routes/auth.ts @@ -1,6 +1,6 @@ import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod' import { z } from 'zod' -import { exchangeCodeForToken, getGithubUser } from '@services/github.service' +import { exchangeCodeForToken, getGithubUser } from '@/services/github.service' import prisma from '@/lib/prisma' import { createResponseSchema, ErrorCode, errorResponse, successResponse } from '@/types/response' @@ -45,15 +45,13 @@ export const authRoutes: FastifyPluginAsyncZod = async (app) => { where: { githubId: String(githubUser.id) }, }) - if (!user) { - user = await prisma.user.create({ - data: { - githubId: String(githubUser.id), - username: githubUser.login, - avatarUrl: githubUser.avatar_url, - }, - }) - } + user ??= await prisma.user.create({ + data: { + githubId: String(githubUser.id), + username: githubUser.login, + avatarUrl: githubUser.avatar_url, + }, + }) // Generate JWT token const token = app.jwt.sign( diff --git a/src/server.ts b/src/server.ts index 79e715e..cc1eeac 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,10 @@ import fastify from 'fastify' import type { ZodTypeProvider } from 'fastify-type-provider-zod' -import { serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod' +import { + jsonSchemaTransform, + serializerCompiler, + validatorCompiler, +} from 'fastify-type-provider-zod' import fastifyJwt from '@fastify/jwt' import fastifyCors from '@fastify/cors' import 'dotenv/config' @@ -43,6 +47,7 @@ async function bootstrap() { // Register Swagger for OpenAPI spec generation await app.register(swagger, { + transform: jsonSchemaTransform, openapi: { info: { title: 'Project Dash API', @@ -123,7 +128,6 @@ GitHub API rate limits apply. Authenticated requests: 5,000/hour. }, }) - app.get('/docs', (_, reply) => { reply.type('text/html').send(` @@ -182,7 +186,7 @@ GitHub API rate limits apply. Authenticated requests: 5,000/hour. } // Start the server -await (async () => { +void (async () => { try { const app = await bootstrap() await app.listen({ port: 3333, host: '0.0.0.0' }) diff --git a/tsconfig.json b/tsconfig.json index df96c31..7c6d495 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,11 +41,11 @@ "baseUrl": ".", "paths": { "@/*": ["src/*"], - "@config/*": ["src/config/*"], - "@routes/*": ["src/routes/*"], - "@services/*": ["src/services/*"], - "@utils/*": ["src/utils/*"], - "@types/*": ["src/types/*"] + "@/config/*": ["src/config/*"], + "@/routes/*": ["src/routes/*"], + "@/services/*": ["src/services/*"], + "@/utils/*": ["src/utils/*"], + "@/types/*": ["src/types/*"] } }, "include": ["src/**/*.ts", "src/**/*.d.ts", "node_modules/@prisma/client"],