32 lines
877 B
TypeScript

import SQL from 'sql-template-strings';
import { PermissionAreas } from '#shared/helpers.ts';
import { auditLog } from '~~/server/audit.ts';
import { getLocale, loadConfig } from '~~/server/data.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 db.get(SQL`
UPDATE sources
SET approved = 0
WHERE id = ${id}
`);
await invalidateCacheKind('sources', locale);
await auditLog({ user }, 'sources/hidden', { id });
});