2021-04-07 15:03:02 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
import prisma from '../../../lib/prisma';
|
2021-04-21 22:10:48 +00:00
|
|
|
import { getBusyTimes } from '../../../lib/calendarClient';
|
2021-03-22 13:48:48 +00:00
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
const { user } = req.query
|
|
|
|
|
|
|
|
const currentUser = await prisma.user.findFirst({
|
|
|
|
where: {
|
|
|
|
username: user,
|
|
|
|
},
|
|
|
|
select: {
|
2021-04-16 02:09:22 +00:00
|
|
|
credentials: true,
|
|
|
|
timeZone: true
|
2021-03-22 13:48:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-21 22:10:48 +00:00
|
|
|
const availability = await getBusyTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo);
|
|
|
|
res.status(200).json(availability);
|
2021-04-16 02:09:22 +00:00
|
|
|
}
|