Merge branch 'main' into feature/zoom-integration
# Conflicts: # lib/calendarClient.ts # lib/emails/new-event.ts # pages/[user]/book.tsx # pages/api/availability/[user].ts # pages/api/book/[user].ts # pages/integrations/index.tsx
This commit is contained in:
commit
ebc42f0c96
25 files changed
+752
-250
No files matched your search
@@ -2,6 +2,7 @@ import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import prisma from '../../../lib/prisma';
|
||||
import {getBusyCalendarTimes} from '../../../lib/calendarClient';
|
||||
import {getBusyVideoTimes} from '../../../lib/videoClient';
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { user } = req.query
|
||||
@@ -12,14 +13,21 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
select: {
|
||||
credentials: true,
|
||||
timeZone: true
|
||||
timeZone: true,
|
||||
bufferTime: true
|
||||
}
|
||||
});
|
||||
|
||||
const selectedCalendars = (await prisma.selectedCalendar.findMany({
|
||||
where: {
|
||||
userId: currentUser.id
|
||||
}
|
||||
}));
|
||||
|
||||
const hasCalendarIntegrations = currentUser.credentials.filter((cred) => cred.type.endsWith('_calendar')).length > 0;
|
||||
const hasVideoIntegrations = currentUser.credentials.filter((cred) => cred.type.endsWith('_video')).length > 0;
|
||||
|
||||
const calendarAvailability = await getBusyCalendarTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo);
|
||||
const calendarAvailability = await getBusyCalendarTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo, selectedCalendars);
|
||||
const videoAvailability = await getBusyVideoTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo);
|
||||
|
||||
let commonAvailability = [];
|
||||
@@ -32,5 +40,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
commonAvailability = calendarAvailability;
|
||||
}
|
||||
|
||||
commonAvailability = commonAvailability.map(a => ({
|
||||
start: dayjs(a.start).subtract(currentUser.bufferTime, 'minute').toString(),
|
||||
end: dayjs(a.end).add(currentUser.bufferTime, 'minute').toString()
|
||||
}));
|
||||
|
||||
res.status(200).json(commonAvailability);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import {getSession} from 'next-auth/client';
|
||||
import prisma from '../../../lib/prisma';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -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'});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import {getSession} from 'next-auth/client';
|
||||
import prisma from '../../../lib/prisma';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -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
|
||||
};
|
||||
|
||||
if (req.method == "POST") {
|
||||
@@ -50,4 +51,4 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
res.status(200).json({message: 'Event deleted successfully'});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user