Merge pull request #90 from calcom/fix-nopick

Fix nopick
pull/9078/head
Agusti Fernandez Pardo 2022-05-20 21:58:20 +02:00 committed by GitHub
commit 5f9eb6fa27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 21 deletions

View File

@ -177,7 +177,7 @@ export type SchedulesResponse = BaseResponse & {
// Webhook
export type WebhookResponse = BaseResponse & {
webhook?: Partial<Webhook>;
webhook?: Partial<Webhook> | null;
};
export type WebhooksResponse = BaseResponse & {
webhooks?: Partial<Webhook>[];

View File

@ -12,25 +12,37 @@ const schemaWebhookBaseBodyParams = Webhook.pick({
payloadTemplate: true,
}).partial();
const schemaWebhookCreateParams = z
.object({
// const schemaWebhookCreateParams = z
// .object({
// id: z.string(),
// subscriberUrl: z.string(),
// })
// .strict();
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(
z.object({
id: z.string(),
subscriberUrl: z.string(),
})
.strict();
);
export const schemaWebhookCreateBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookCreateParams);
// const schemaWebhookEditParams = z
// .object({
// payloadTemplate: z.string().optional(),
// /** @todo: don't use any here and validate eventTriggers proper */
// eventTriggers: z.any(),
// subscriberUrl: z.string().optional(),
// })
// .strict();
const schemaWebhookEditParams = z
.object({
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge(
z.object({
payloadTemplate: z.string().optional(),
/** @todo: don't use any here and validate eventTriggers proper */
eventTriggers: z.any(),
subscriberUrl: z.string().optional(),
})
.strict();
export const schemaWebhookEditBodyParams = schemaWebhookBaseBodyParams.merge(schemaWebhookEditParams);
);
export const schemaWebhookReadPublic = Webhook.pick({
id: true,
@ -38,7 +50,6 @@ export const schemaWebhookReadPublic = Webhook.pick({
eventTypeId: true,
payloadTemplate: true,
eventTriggers: true,
/** @todo: find out why this breaks the api */
// eventType: true,
// app: true,
appId: true,

View File

@ -51,7 +51,7 @@ export async function WebhookById(
case "GET":
await prisma.webhook
.findUnique({ where: { id: safeQuery.data.id } })
.then((data) => schemaWebhookReadPublic.parse(data))
// .then((data) => schemaWebhookReadPublic.parse(data))
.then((webhook) => res.status(200).json({ webhook }))
.catch((error: Error) =>
res.status(404).json({

View File

@ -29,15 +29,13 @@ async function createOrlistAllWebhooks(
* 404:
* description: No webhooks were found
*/
const data = await prisma.webhook.findMany({ where: { userId } });
// const webhooks = data.map((webhook) => schemaWebhookReadPublic.parse(webhook));
if (data) res.status(200).json({ webhooks: data });
else
(error: Error) =>
res.status(404).json({
message: "No Webhooks were found",
error,
});
await prisma.webhook
.findMany({ where: { userId } })
.then((data) => res.status(200).json({ webhooks: data }))
.catch((error) => {
console.log(error);
res.status(404).json({ message: "No webhooks were found", error });
});
} else if (method === "POST") {
/**
* @swagger