24 lines
679 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { toggleChatMessageLike, toggleDmLike } from "../../db/chat-rooms";
/** POST /api/chat/like Toggle Like auf Chat-Message oder DM */
export default defineEventHandler(async (event) => {
const user = await requireUser(event);
const body = await readBody(event);
const messageId = body?.messageId;
const type = body?.type; // "chat" | "dm"
if (!messageId || !type) {
throw createError({ statusCode: 400, message: "messageId und type erforderlich" });
}
let liked: boolean;
if (type === "dm") {
liked = await toggleDmLike(user.id, messageId);
} else {
liked = await toggleChatMessageLike(user.id, messageId);
}
return { liked };
});