31 lines
805 B
TypeScript

import SQL from 'sql-template-strings';
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('sources')) {
throw createError({
status: 401,
statusMessage: 'Unauthorised',
});
}
const id = getRouterParam(event, 'id');
const db = useDatabase();
await db.get(SQL`
UPDATE sources
SET deleted=1
WHERE id = ${id}
`);
await invalidateCacheKind('sources', locale);
await auditLog({ user }, 'sources/removed', { id });
});