"feat: refactor API handlers to use services, add logging, and improve security checks"
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user