* zapier and webhook * instructions for zapier * Fix types * fix types * revert adding zap template * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/features/webhooks/lib/scheduleTrigger.ts Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * wip * Fixes from comments, no more sendPayloadNoBooking * fix subscriberOptions teamIds param type * types * Update packages/features/webhooks/lib/sendPayload.ts * Re add zapierPayload to don't break old zaps * instead of metadata use oooEntry inside webhookPayload * undo comment message * Types * reset changes on yarn.lock * review changes * fix types * fix types * tentative fix for types in webhook * type improvements * fix description + clean up * revert yarn.lock changes * allow custom template for ooo entry * type fixes * type fix * fix donwloadLinks in payload * simplify some types * allow array or number for teamId * same payload for test trigger * code clean up * fix no show e2e test * translate text for webhook payload and fix conditional * add test for ooo_created webhooks * reset files * merge fix * fix test data test id * remove unused variable * only trigger for accepted memberships * remove unused variable --------- Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Omar López <zomars@me.com>
77 lines
1.7 KiB
TypeScript
77 lines
1.7 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { listOOOEntries } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
|
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
|
|
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
|
|
|
import { validateAccountOrApiKey } from "../../lib/validateAccountOrApiKey";
|
|
|
|
export const selectOOOEntries = {
|
|
id: true,
|
|
start: true,
|
|
end: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
notes: true,
|
|
reason: {
|
|
select: {
|
|
reason: true,
|
|
emoji: true,
|
|
},
|
|
},
|
|
reasonId: true,
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
timeZone: true,
|
|
},
|
|
},
|
|
toUser: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
timeZone: true,
|
|
},
|
|
},
|
|
uuid: true,
|
|
};
|
|
|
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const { account: authorizedAccount, appApiKey: validKey } = await validateAccountOrApiKey(req, [
|
|
"READ_PROFILE",
|
|
]);
|
|
if (!authorizedAccount && !validKey) {
|
|
res.status(401).json({ message: "Unauthorized" });
|
|
return;
|
|
}
|
|
const oooEntries = await listOOOEntries(validKey, authorizedAccount);
|
|
|
|
if (!oooEntries) {
|
|
res.status(500).json({ message: "Unable to get out of office entries list." });
|
|
return;
|
|
}
|
|
if (oooEntries.length === 0) {
|
|
res.status(200).json([]);
|
|
return;
|
|
}
|
|
// Wrap entries in metadata object
|
|
const response = oooEntries.map((oooEntry) => {
|
|
return {
|
|
createdAt: oooEntry.createdAt,
|
|
triggerEvent: WebhookTriggerEvents.OOO_CREATED,
|
|
payload: {
|
|
oooEntry,
|
|
},
|
|
};
|
|
});
|
|
res.status(200).json(response);
|
|
return;
|
|
}
|
|
|
|
export default defaultHandler({
|
|
GET: Promise.resolve({ default: defaultResponder(handler) }),
|
|
});
|