67 lines
1.4 KiB
TypeScript
67 lines
1.4 KiB
TypeScript
// src/app/services/AccessLog.service.ts
|
|
//
|
|
// PURPOSE:
|
|
// Service for handling AccessLog records
|
|
//
|
|
// RULES:
|
|
// - All methods return Promises
|
|
// - Input validation should be done at controller level
|
|
// - Errors should be propagated to caller
|
|
|
|
import type { AccessLog } from '@prisma/client';
|
|
|
|
import prisma from '../lib/prisma';
|
|
|
|
// type CreateAccessLog = {
|
|
// userId?: string;
|
|
// message?: string;
|
|
// metadata?: Record<string, any>;
|
|
// };
|
|
|
|
// type UpdateAccessLog = {
|
|
// status?: number;
|
|
// metadata?: object;
|
|
// };
|
|
|
|
async function listAccessLogs(): Promise<AccessLog[]> {
|
|
return prisma.accessLog.findMany({
|
|
orderBy: { timestamp: 'desc' },
|
|
take: 100,
|
|
});
|
|
}
|
|
|
|
async function getAccessLog(id: string): Promise<AccessLog | null> {
|
|
return prisma.accessLog.findUnique({ where: { id } });
|
|
}
|
|
|
|
async function createAccessLog(userId?: string, message?: string, metadata?: Record<string, any>): Promise<AccessLog> {
|
|
return prisma.accessLog.create({
|
|
data: {
|
|
userId,
|
|
message,
|
|
metadata,
|
|
},
|
|
});
|
|
}
|
|
|
|
// async function update(id: string, data: UpdateAccessLog): Promise<AccessLog> {
|
|
// return prisma.accessLog.update({
|
|
// where: { id },
|
|
// data: {
|
|
// ...data,
|
|
// metadata: data.metadata || {},
|
|
// },
|
|
// });
|
|
// }
|
|
|
|
// async function deleteAccessLog(id: string): Promise<AccessLog> {
|
|
// return prisma.accessLog.delete({ where: { id } });
|
|
// }
|
|
|
|
export {
|
|
//
|
|
getAccessLog,
|
|
listAccessLogs,
|
|
createAccessLog,
|
|
};
|