Merge branch 'main' into feature/custom-fields-on-the-booking-page
# Conflicts: # pages/api/availability/eventtype.ts # pages/availability/event/[type].tsx
This commit is contained in:
commit
543482ca52
24 files changed
+603
-121
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import prisma from '../../../lib/prisma';
|
||||
import { getBusyTimes } from '../../../lib/calendarClient';
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { user } = req.query
|
||||
@@ -11,10 +12,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
select: {
|
||||
credentials: true,
|
||||
timeZone: true
|
||||
timeZone: true,
|
||||
bufferTime: true
|
||||
}
|
||||
});
|
||||
|
||||
const availability = await getBusyTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo);
|
||||
const selectedCalendars = (await prisma.selectedCalendar.findMany({
|
||||
where: {
|
||||
userId: currentUser.id
|
||||
}
|
||||
}));
|
||||
|
||||
let availability = await getBusyTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo, selectedCalendars);
|
||||
|
||||
availability = availability.map(a => ({
|
||||
start: dayjs(a.start).subtract(currentUser.bufferTime, 'minute').toString(),
|
||||
end: dayjs(a.end).add(currentUser.bufferTime, 'minute').toString()
|
||||
}));
|
||||
|
||||
res.status(200).json(availability);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import prisma from '../../../lib/prisma';
|
||||
import {IntegrationCalendar, listCalendars} from "../../../lib/calendarClient";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({req: req});
|
||||
|
||||
if (!session) {
|
||||
res.status(401).json({message: "Not authenticated"});
|
||||
return;
|
||||
}
|
||||
|
||||
const currentUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
},
|
||||
select: {
|
||||
credentials: true,
|
||||
timeZone: true,
|
||||
id: true
|
||||
}
|
||||
});
|
||||
|
||||
if (req.method == "POST") {
|
||||
await prisma.selectedCalendar.create({
|
||||
data: {
|
||||
user: {
|
||||
connect: {
|
||||
id: currentUser.id
|
||||
}
|
||||
},
|
||||
integration: req.body.integration,
|
||||
externalId: req.body.externalId
|
||||
}
|
||||
});
|
||||
res.status(200).json({message: "Calendar Selection Saved"});
|
||||
|
||||
}
|
||||
|
||||
if (req.method == "DELETE") {
|
||||
await prisma.selectedCalendar.delete({
|
||||
where: {
|
||||
userId_integration_externalId: {
|
||||
userId: currentUser.id,
|
||||
externalId: req.body.externalId,
|
||||
integration: req.body.integration
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
res.status(200).json({message: "Calendar Selection Saved"});
|
||||
}
|
||||
|
||||
if (req.method == "GET") {
|
||||
const selectedCalendarIds = await prisma.selectedCalendar.findMany({
|
||||
where: {
|
||||
userId: currentUser.id
|
||||
},
|
||||
select: {
|
||||
externalId: true
|
||||
}
|
||||
});
|
||||
|
||||
const calendars: IntegrationCalendar[] = await listCalendars(currentUser.credentials);
|
||||
const selectableCalendars = calendars.map(cal => {return {selected: selectedCalendarIds.findIndex(s => s.externalId === cal.externalId) > -1, ...cal}});
|
||||
res.status(200).json(selectableCalendars);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
if (req.method == "PATCH") {
|
||||
const startMins = req.body.start;
|
||||
const endMins = req.body.end;
|
||||
const bufferMins = req.body.buffer;
|
||||
|
||||
const updateDay = await prisma.user.update({
|
||||
where: {
|
||||
@@ -20,10 +21,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
data: {
|
||||
startTime: startMins,
|
||||
endTime: endMins
|
||||
endTime: endMins,
|
||||
bufferTime: bufferMins
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json({message: 'Start and end times updated successfully'});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
length: parseInt(req.body.length),
|
||||
hidden: req.body.hidden,
|
||||
locations: req.body.locations,
|
||||
eventName: req.body.eventName,
|
||||
customInputs: !req.body.customInputs
|
||||
? undefined
|
||||
: {
|
||||
|
||||
Reference in new issue
Block a user