fix: fix some bugs

This commit is contained in:
grtsinry43 2025-10-27 05:13:22 +00:00
parent 5904ade3db
commit 89e7e5794a
5 changed files with 48 additions and 19 deletions

View File

@ -5,7 +5,7 @@
"private": true, "private": true,
"main": "dist/server.js", "main": "dist/server.js",
"scripts": { "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", "build": "prisma generate && tsc",
"start": "node dist/server.js", "start": "node dist/server.js",
"prisma:generate": "prisma generate", "prisma:generate": "prisma generate",
@ -59,6 +59,7 @@
"prettier": "^3.6.2", "prettier": "^3.6.2",
"prisma": "^6.18.0", "prisma": "^6.18.0",
"ts-node-dev": "^2.0.0", "ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"typescript-eslint": "^8.46.2" "typescript-eslint": "^8.46.2"
}, },

26
pnpm-lock.yaml generated
View File

@ -116,6 +116,9 @@ importers:
ts-node-dev: ts-node-dev:
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.0(@types/node@24.9.1)(typescript@5.9.3) version: 2.0.0(@types/node@24.9.1)(typescript@5.9.3)
tsconfig-paths:
specifier: ^4.2.0
version: 4.2.0
typescript: typescript:
specifier: ^5.9.3 specifier: ^5.9.3
version: 5.9.3 version: 5.9.3
@ -2421,6 +2424,14 @@ packages:
integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==, 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: jsonparse@1.3.1:
resolution: resolution:
{ {
@ -3628,6 +3639,13 @@ packages:
'@swc/wasm': '@swc/wasm':
optional: true optional: true
tsconfig-paths@4.2.0:
resolution:
{
integrity: sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==,
}
engines: { node: '>=6' }
tsconfig@7.0.0: tsconfig@7.0.0:
resolution: resolution:
{ {
@ -5299,6 +5317,8 @@ snapshots:
json-stable-stringify-without-jsonify@1.0.1: {} json-stable-stringify-without-jsonify@1.0.1: {}
json5@2.2.3: {}
jsonparse@1.3.1: {} jsonparse@1.3.1: {}
keyv@4.5.4: keyv@4.5.4:
@ -5928,6 +5948,12 @@ snapshots:
v8-compile-cache-lib: 3.0.1 v8-compile-cache-lib: 3.0.1
yn: 3.1.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: tsconfig@7.0.0:
dependencies: dependencies:
'@types/strip-bom': 3.0.0 '@types/strip-bom': 3.0.0

View File

@ -1,6 +1,6 @@
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod' import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod'
import { z } from '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 prisma from '@/lib/prisma'
import { createResponseSchema, ErrorCode, errorResponse, successResponse } from '@/types/response' import { createResponseSchema, ErrorCode, errorResponse, successResponse } from '@/types/response'
@ -45,15 +45,13 @@ export const authRoutes: FastifyPluginAsyncZod = async (app) => {
where: { githubId: String(githubUser.id) }, where: { githubId: String(githubUser.id) },
}) })
if (!user) { user ??= await prisma.user.create({
user = await prisma.user.create({ data: {
data: { githubId: String(githubUser.id),
githubId: String(githubUser.id), username: githubUser.login,
username: githubUser.login, avatarUrl: githubUser.avatar_url,
avatarUrl: githubUser.avatar_url, },
}, })
})
}
// Generate JWT token // Generate JWT token
const token = app.jwt.sign( const token = app.jwt.sign(

View File

@ -1,6 +1,10 @@
import fastify from 'fastify' import fastify from 'fastify'
import type { ZodTypeProvider } from 'fastify-type-provider-zod' 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 fastifyJwt from '@fastify/jwt'
import fastifyCors from '@fastify/cors' import fastifyCors from '@fastify/cors'
import 'dotenv/config' import 'dotenv/config'
@ -43,6 +47,7 @@ async function bootstrap() {
// Register Swagger for OpenAPI spec generation // Register Swagger for OpenAPI spec generation
await app.register(swagger, { await app.register(swagger, {
transform: jsonSchemaTransform,
openapi: { openapi: {
info: { info: {
title: 'Project Dash API', title: 'Project Dash API',
@ -123,7 +128,6 @@ GitHub API rate limits apply. Authenticated requests: 5,000/hour.
}, },
}) })
app.get('/docs', (_, reply) => { app.get('/docs', (_, reply) => {
reply.type('text/html').send(` reply.type('text/html').send(`
<!doctype html> <!doctype html>
@ -182,7 +186,7 @@ GitHub API rate limits apply. Authenticated requests: 5,000/hour.
} }
// Start the server // Start the server
await (async () => { void (async () => {
try { try {
const app = await bootstrap() const app = await bootstrap()
await app.listen({ port: 3333, host: '0.0.0.0' }) await app.listen({ port: 3333, host: '0.0.0.0' })

View File

@ -41,11 +41,11 @@
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@/*": ["src/*"], "@/*": ["src/*"],
"@config/*": ["src/config/*"], "@/config/*": ["src/config/*"],
"@routes/*": ["src/routes/*"], "@/routes/*": ["src/routes/*"],
"@services/*": ["src/services/*"], "@/services/*": ["src/services/*"],
"@utils/*": ["src/utils/*"], "@/utils/*": ["src/utils/*"],
"@types/*": ["src/types/*"] "@/types/*": ["src/types/*"]
} }
}, },
"include": ["src/**/*.ts", "src/**/*.d.ts", "node_modules/@prisma/client"], "include": ["src/**/*.ts", "src/**/*.d.ts", "node_modules/@prisma/client"],