mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* migration and init to accept creationSource for new bookings * V1 create booking * V1 user creation * webapp booking + V1 user * user creation in V1, V2 and webapp * booking source V2 and fix for v1 user * fit type * --fix type * add test -- WIP * fix type * fix type * ^ * Need more sleep zzz * -_- * bump libraries platform * adds for v2 recurring booking * fix lint * instant meetings * fix: api v2 creation source * fixup! fix: api v2 creation source * bump libraries * add user * fix test * fixup! fix test * add more source * more source... * fix type & test --1 * fix type & test --2 * typefix * fixup test --------- Co-authored-by: Morgan Vernay <[email protected]>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { MAX_NB_INVITES } from "@calcom/lib/constants";
|
|
import { emailSchema } from "@calcom/lib/emailSchema";
|
|
import { MembershipRole } from "@calcom/prisma/enums";
|
|
import { CreationSource } from "@calcom/prisma/enums";
|
|
|
|
export const ZInviteMemberInputSchema = z.object({
|
|
teamId: z.number(),
|
|
usernameOrEmail: z
|
|
.union([
|
|
z.string(),
|
|
z
|
|
.union([
|
|
z.string(),
|
|
z.object({
|
|
email: emailSchema,
|
|
role: z.nativeEnum(MembershipRole),
|
|
}),
|
|
])
|
|
.array(),
|
|
])
|
|
.transform((usernameOrEmail) => {
|
|
if (typeof usernameOrEmail === "string") {
|
|
return usernameOrEmail.trim().toLowerCase();
|
|
}
|
|
return usernameOrEmail.map((item) => {
|
|
if (typeof item === "string") {
|
|
return item.trim().toLowerCase();
|
|
}
|
|
|
|
return {
|
|
...item,
|
|
email: item.email.trim().toLowerCase(),
|
|
};
|
|
});
|
|
})
|
|
.refine(
|
|
(value) => {
|
|
if (Array.isArray(value)) {
|
|
if (value.length > MAX_NB_INVITES) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
{ message: `You are limited to inviting a maximum of ${MAX_NB_INVITES} users at once.` }
|
|
)
|
|
.refine(
|
|
(value) => {
|
|
if (Array.isArray(value)) {
|
|
return !value.some((email) => !emailSchema.safeParse(email).success);
|
|
}
|
|
return true;
|
|
},
|
|
{ message: "Bulk invitations are restricted to email addresses only." }
|
|
),
|
|
role: z.nativeEnum(MembershipRole).optional(),
|
|
language: z.string(),
|
|
isPlatform: z.boolean().optional(),
|
|
creationSource: z.nativeEnum(CreationSource),
|
|
});
|
|
|
|
export type TInviteMemberInputSchema = z.infer<typeof ZInviteMemberInputSchema>;
|