cal.pub0.org/pages/api/book/[user].ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-04-11 17:12:18 +00:00
import type { NextApiRequest, NextApiResponse } from 'next';
import prisma from '../../../lib/prisma';
import { createEvent, CalendarEvent } from '../../../lib/calendarClient';
2021-03-22 13:48:48 +00:00
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
2021-04-11 17:12:18 +00:00
const { user } = req.query;
2021-03-22 13:48:48 +00:00
const currentUser = await prisma.user.findFirst({
where: {
username: user,
},
select: {
credentials: true,
timeZone: true,
2021-03-22 13:48:48 +00:00
}
});
const evt: CalendarEvent = {
title: 'Meeting with ' + req.body.name,
description: req.body.notes,
startTime: req.body.start,
endTime: req.body.end,
timeZone: currentUser.timeZone,
attendees: [
{ email: req.body.email, name: req.body.name }
]
};
2021-03-22 13:48:48 +00:00
// TODO: for now, first integration created; primary = obvious todo; ability to change primary.
const result = await createEvent(currentUser.credentials[0], evt);
res.status(200).json(result);
}