Files
clientsflow/Frontend/server/api/communications.get.ts
2026-02-18 13:56:35 +07:00

41 lines
1.2 KiB
TypeScript

import { prisma } from "../utils/prisma";
import { getAuthContext } from "../utils/auth";
export default defineEventHandler(async (event) => {
const auth = await getAuthContext(event);
const items = await prisma.contactMessage.findMany({
where: { contact: { teamId: auth.teamId } },
orderBy: { occurredAt: "asc" },
take: 2000,
include: {
contact: { select: { id: true, name: true } },
},
});
return {
items: items.map((m) => ({
id: m.id,
at: m.occurredAt.toISOString(),
contactId: m.contactId,
contact: m.contact.name,
channel:
m.channel === "TELEGRAM"
? "Telegram"
: m.channel === "WHATSAPP"
? "WhatsApp"
: m.channel === "INSTAGRAM"
? "Instagram"
: m.channel === "EMAIL"
? "Email"
: "Phone",
kind: m.kind === "CALL" ? "call" : "message",
direction: m.direction === "IN" ? "in" : "out",
text: m.content,
duration: m.durationSec ? new Date(m.durationSec * 1000).toISOString().slice(14, 19) : undefined,
transcript: Array.isArray(m.transcriptJson) ? (m.transcriptJson as any) : undefined,
})),
};
});