Files
HKSingleParty/03_source/cms_backend/src/app/api/AppLog/route.ts
louiscklaw b7cd25b614 build ok,
2025-06-15 11:28:24 +08:00

83 lines
2.1 KiB
TypeScript

import type { NextRequest, NextResponse } from 'next/server';
import { STATUS, response, handleError } from 'src/utils/response';
import { listAppLogs, deleteAppLog, createNewAppLog } from 'src/app/services/app-log.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);
}
}
// TODO: delete `update AppLog`
// /**
// ***************************************
// * 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.toString());
return response(deleteResult, STATUS.OK);
} catch (error) {
return handleError('AppLog - Update', error);
}
}