This commit is contained in:
Your Name
2026-07-08 15:10:29 +00:00
parent d63ed3e7ef
commit 8f0f0cd36e
22 changed files with 1129 additions and 1032 deletions
+17 -3
View File
@@ -1,7 +1,16 @@
import type { FastifyInstance } from 'fastify'
import type { TrueApiEnv } from '../config.js'
import { checkCodesPublic, checkCodesAuth, AppError } from '../services/cises-service.js'
import type { CheckCodesRequest } from '../types/index.js'
const VALID_ENVS = ['sandbox', 'prod']
function parseEnv(query: Record<string, string>): TrueApiEnv {
const env = query.env
if (env && VALID_ENVS.includes(env)) return env as TrueApiEnv
return 'sandbox'
}
const checkCodesSchema = {
body: {
type: 'object',
@@ -19,15 +28,20 @@ const checkCodesSchema = {
export async function cisesRoutes(app: FastifyInstance): Promise<void> {
app.post<{ Body: CheckCodesRequest }>('/api/check-codes/public', { schema: checkCodesSchema }, async (request) => {
return checkCodesPublic(request.body)
const env = parseEnv(request.query as Record<string, string>)
return checkCodesPublic(env, request.body)
})
app.post<{ Body: CheckCodesRequest }>('/api/check-codes/auth', { schema: checkCodesSchema }, async (request, reply) => {
const env = parseEnv(request.query as Record<string, string>)
try {
return await checkCodesAuth(request.body)
return await checkCodesAuth(env, request.body)
} catch (err) {
if (err instanceof AppError) {
return reply.status(err.statusCode).send({ error: err.message })
return reply.status(err.statusCode).send({
error: err.message,
debugInfo: err.debugInfo,
})
}
throw err
}