Recurring event fixes (#3030)
* Incorporates recurringEvent into calEvent * Recurrent event fixes * Update event.ts * type fixes * Update zod-utils.ts * Adding more recurringEvent to calEvent and other fixes * Moving away from heavy 3rd party enum * Fixing test * Renaming as suggested and fixes Co-authored-by: Leo Giovanetti <[email protected]>
This commit is contained in:
1 parent
8cd420173c
commit
b11398f551
55 files changed
+315
-333
No files matched your search
@@ -59,7 +59,7 @@ model EventType {
|
||||
periodDays Int?
|
||||
periodCountCalendarDays Boolean?
|
||||
requiresConfirmation Boolean @default(false)
|
||||
/// @zod.custom(imports.recurringEvent)
|
||||
/// @zod.custom(imports.recurringEventType)
|
||||
recurringEvent Json?
|
||||
disableGuests Boolean @default(false)
|
||||
hideCalendarNotes Boolean @default(false)
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { Frequency as RRuleFrequency } from "rrule";
|
||||
import dayjs from "dayjs";
|
||||
import { z } from "zod";
|
||||
|
||||
import { LocationType } from "@calcom/core/location";
|
||||
import { slugify } from "@calcom/lib/slugify";
|
||||
|
||||
// Let's not import 118kb just to get an enum
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
MONTHLY = 1,
|
||||
WEEKLY = 2,
|
||||
DAILY = 3,
|
||||
HOURLY = 4,
|
||||
MINUTELY = 5,
|
||||
SECONDLY = 6,
|
||||
}
|
||||
|
||||
export const eventTypeLocations = z.array(
|
||||
z.object({
|
||||
type: z.nativeEnum(LocationType),
|
||||
@@ -15,15 +26,33 @@ export const eventTypeLocations = z.array(
|
||||
);
|
||||
|
||||
// Matching RRule.Options: rrule/dist/esm/src/types.d.ts
|
||||
export const recurringEvent = z.object({
|
||||
dtstart: z.date().optional(),
|
||||
interval: z.number().optional(),
|
||||
count: z.number().optional(),
|
||||
freq: z.nativeEnum(RRuleFrequency).optional(),
|
||||
until: z.date().optional(),
|
||||
tzid: z.string().optional(),
|
||||
});
|
||||
export const recurringEventType = z
|
||||
.object({
|
||||
dtstart: z.date().optional(),
|
||||
interval: z.number(),
|
||||
count: z.number(),
|
||||
freq: z.nativeEnum(Frequency),
|
||||
until: z.date().optional(),
|
||||
tzid: z.string().optional(),
|
||||
})
|
||||
.nullable();
|
||||
|
||||
export const eventTypeSlug = z.string().transform((val) => slugify(val.trim()));
|
||||
|
||||
export const stringToDate = z.string().transform((a) => new Date(a));
|
||||
export const stringOrNumber = z.union([z.string().transform((v) => parseInt(v, 10)), z.number().int()]);
|
||||
|
||||
export const stringOrNumber = z.union([
|
||||
z.string().transform((v, ctx) => {
|
||||
const parsed = parseInt(v);
|
||||
if (isNaN(parsed)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Not a number",
|
||||
});
|
||||
}
|
||||
return parsed;
|
||||
}),
|
||||
z.number().int(),
|
||||
]);
|
||||
|
||||
export const stringToDayjs = z.string().transform((val) => dayjs(val));
|
||||
Reference in new issue
Block a user