25 lines
790 B
TypeScript

import { PermissionAreas } from '#shared/helpers.ts';
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(PermissionAreas.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 });
});