24 lines
719 B
TypeScript

import { auditLog } from '~/server/audit.ts';
import { getLocale, loadConfig } from '~/server/data.ts';
import { approveSourceEntry } from '~/server/sources.ts';
export default defineEventHandler(async (event) => {
const locale = getLocale(event);
checkIsConfigEnabledOr404(await loadConfig(locale), 'sources');
const { user, isGranted } = await useAuthentication(event);
if (!isGranted('sources')) {
throw createError({
status: 401,
statusMessage: 'Unauthorised',
});
}
const id = getRouterParam(event, 'id')!;
const db = useDatabase();
await approveSourceEntry(db, id, locale);
await auditLog({ user }, 'sources/approved', { id });
});