Improves Zapier response and payload (#3892)

* improve listBookings API call

* improve payload for zapier call

* use more readable location for integrations

* remove cancellation reason

* convert location to readbale string

* code clean up

* code clean up

* updated expected webhook response for e2e tests

* fix failing e2e

* revert webhook response

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-09-08 13:18:00 -06:00
1 parent 0b8eb3b8ec
commit bb24539731
5 files changed
+116 -14

No files matched your search

@@ -1,8 +1,9 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getHumanReadableLocationValue } from "@calcom/core/location";
import findValidApiKey from "@calcom/features/ee/api-keys/lib/findValidApiKey";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import { defaultHandler, defaultResponder, getTranslation } from "@calcom/lib/server";
import prisma from "@calcom/prisma";
async function handler(req: NextApiRequest, res: NextApiResponse) {
const apiKey = req.query.apiKey as string;
@@ -24,8 +25,25 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
userId: validKey.userId,
},
select: {
...bookingMinimalSelect,
title: true,
description: true,
customInputs: true,
startTime: true,
endTime: true,
location: true,
cancellationReason: true,
status: true,
user: true,
eventType: {
select: {
title: true,
description: true,
requiresConfirmation: true,
price: true,
currency: true,
length: true,
},
},
attendees: {
select: {
name: true,
@@ -36,7 +54,13 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
},
});
res.status(201).json(bookings);
const t = await getTranslation(bookings[0].user?.locale ?? "en", "common");
const updatedBookings = bookings.map((booking) => {
return { ...booking, location: getHumanReadableLocationValue(booking.location || "", t) };
});
res.status(201).json(updatedBookings);
} catch (error) {
console.error(error);
return res.status(500).json({ message: "Unable to get bookings." });