30 lines
927 B
TypeScript
30 lines
927 B
TypeScript
import { prisma } from "../utils/prisma";
|
|
import { getAuthContext } from "../utils/auth";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const auth = await getAuthContext(event);
|
|
const query = getQuery(event) as any;
|
|
|
|
const from = query.from ? new Date(String(query.from)) : new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
|
|
const to = query.to ? new Date(String(query.to)) : new Date(Date.now() + 1000 * 60 * 60 * 24 * 60);
|
|
|
|
const items = await prisma.calendarEvent.findMany({
|
|
where: { teamId: auth.teamId, startsAt: { gte: from, lte: to } },
|
|
include: { contact: { select: { name: true } } },
|
|
orderBy: { startsAt: "asc" },
|
|
take: 500,
|
|
});
|
|
|
|
return {
|
|
items: items.map((e) => ({
|
|
id: e.id,
|
|
title: e.title,
|
|
start: e.startsAt.toISOString(),
|
|
end: (e.endsAt ?? e.startsAt).toISOString(),
|
|
contact: e.contact?.name ?? "",
|
|
note: e.note ?? "",
|
|
})),
|
|
};
|
|
});
|
|
|