mirror of
https://github.com/SrIzan10/helium.git
synced 2026-06-06 00:56:58 +00:00
34 lines
914 B
TypeScript
34 lines
914 B
TypeScript
import { getPresetById, deletePreset } from "~/lib/utils/presetsDb";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { isAuthenticated, userId } = event.context.auth();
|
|
|
|
if (!isAuthenticated || !userId) {
|
|
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
}
|
|
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) {
|
|
throw createError({ statusCode: 400, statusMessage: "Missing preset ID" });
|
|
}
|
|
|
|
// Check if the user is the creator of the preset
|
|
const preset = await getPresetById(id);
|
|
|
|
if (!preset) {
|
|
throw createError({ statusCode: 404, statusMessage: "Preset not found" });
|
|
}
|
|
|
|
if (preset.createdBy !== userId) {
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Forbidden: You can only delete your own presets",
|
|
});
|
|
}
|
|
|
|
// Delete the preset (cascades to presetUsers)
|
|
await deletePreset(id);
|
|
|
|
return { success: true };
|
|
});
|