"feat: refactor API handlers to use services, add logging, and improve security checks"

This commit is contained in:
louiscklaw
2025-06-04 02:35:05 +08:00
parent ef0c0ab389
commit 99239c32a5
20 changed files with 303 additions and 42 deletions

View File

@@ -10,7 +10,11 @@ import type { NextRequest } from 'next/server';
import { STATUS, response, handleError } from 'src/utils/response';
import { L_INFO, L_ERROR } from 'src/constants';
import { createAppLog } from 'src/app/services/AppLog.service';
import prisma from '../../../lib/prisma';
import { flattenNextjsRequest } from '../../auth/sign-in/flattenNextjsRequest';
// ----------------------------------------------------------------------
@@ -21,6 +25,8 @@ import prisma from '../../../lib/prisma';
*/
export async function GET(req: NextRequest) {
// Original user details functionality
const debug = { 'req.headers': flattenNextjsRequest(req) };
try {
const { searchParams } = req.nextUrl;
@@ -32,8 +38,12 @@ export async function GET(req: NextRequest) {
if (!helloworld) return response({ message: 'User not found!' }, STATUS.NOT_FOUND);
createAppLog(L_INFO, 'Get OK', debug);
return response({ helloworld }, STATUS.OK);
} catch (error) {
createAppLog(L_ERROR, 'Get error', debug);
return handleError('Product - Get details', error);
}
}