import type { NextRequest, NextResponse } from 'next/server'; import { STATUS, response, handleError } from 'src/utils/response'; import { listAppLogs, deleteAppLog, updateAppLog, createNewAppLog } from 'src/app/services/AppLog.service'; // import prisma from '../../lib/prisma'; export async function GET(req: NextRequest, res: NextResponse) { try { const result = await listAppLogs(); return response(result, STATUS.OK); } catch (error) { return handleError('Post - Get latest', error); } } /** *************************************** * POST - create AppLog *************************************** */ export async function POST(req: NextRequest) { const { data } = await req.json(); try { // TODO: obsolete createNewAppLog const createResult = await createNewAppLog(data); return response(createResult, STATUS.OK); } catch (error) { return handleError('AppLog - Create', error); } } /** *************************************** * PUT - update AppLog *************************************** */ export async function PUT(req: NextRequest) { const { searchParams } = req.nextUrl; const appLogId = searchParams.get('appLogId'); const { data } = await req.json(); try { if (!appLogId) throw new Error('appLogId cannot null'); const id: number = parseInt(appLogId); const updateResult = await updateAppLog(id, data); return response(updateResult, STATUS.OK); } catch (error) { return handleError('AppLog - Update', error); } } /** *************************************** * DELETE - update AppLog *************************************** */ export async function DELETE(req: NextRequest) { const { searchParams } = req.nextUrl; const appLogId = searchParams.get('appLogId'); const { data } = await req.json(); try { if (!appLogId) throw new Error('appLogId cannot null'); const id: number = parseInt(appLogId); const deleteResult = await deleteAppLog(id); return response(deleteResult, STATUS.OK); } catch (error) { return handleError('AppLog - Update', error); } }