Skip to content

Commit

Permalink
🚚: try to fix type check
Browse files Browse the repository at this point in the history
  • Loading branch information
ShashankGupta10 committed Dec 31, 2024
1 parent ad4310e commit 497e0b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/app-store/deel/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import z from "zod";

export const deelCredentialKeysSchema = z.object({
deel_api_key: z.string(),
hris_profile_id: z.string(),
});
13 changes: 11 additions & 2 deletions packages/trpc/server/routers/loggedInViewer/outOfOffice.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Prisma } from "@prisma/client";
import { v4 as uuidv4 } from "uuid";

import { deelCredentialKeysSchema } from "@calcom/app-store/deel/lib";
import { selectOOOEntries } from "@calcom/app-store/zapier/api/subscriptions/listOOOEntries";
import dayjs from "@calcom/dayjs";
import { sendBookingRedirectNotification } from "@calcom/emails";
Expand Down Expand Up @@ -169,11 +170,19 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
},
});

if (!deelCredentials) {
throw new Error("No credentials found");
}
const parsedCredentials = deelCredentialKeysSchema.safeParse(deelCredentials?.key);
if (!parsedCredentials.success) {
throw new Error("Credentials malformed");
}

const deelOOOPayload = {
start_date: startTimeUtc.toISOString(),
end_date: endTimeUtc.toISOString(),
time_off_type_id: input.reasonId.toString(),
recipient_profile_id: deelCredentials.key.hris_profile_id,
recipient_profile_id: parsedCredentials.data.hris_profile_id,
reason: input.notes,
};
const url = "https://api.letsdeel.com/rest/v2/time_offs";
Expand All @@ -182,7 +191,7 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
headers: {
accept: "application/json",
"content-type": "application/json",
authorization: `Bearer ${deelCredentials.key.deel_api_key}`,
authorization: `Bearer ${parsedCredentials.data.deel_api_key}`,
},
body: JSON.stringify({ data: deelOOOPayload }),
};
Expand Down

0 comments on commit 497e0b0

Please sign in to comment.