Skip to content

Commit

Permalink
add functionality for updating this and following recurring event ins…
Browse files Browse the repository at this point in the history
…tances
  • Loading branch information
meetulr committed Feb 21, 2024
1 parent 8dde560 commit 81a3625
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 113 deletions.
36 changes: 21 additions & 15 deletions src/helpers/event/createEventHelpers/createRecurringEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const createRecurringEvent = async (
creatorId: string,
organizationId: string,
session: mongoose.ClientSession,
baseRecurringEventId: string | null = null,
generateAhead: boolean = false,
): Promise<InterfaceEvent> => {
const { data } = args;
Expand All @@ -52,19 +53,24 @@ export const createRecurringEvent = async (

// create a base recurring event first, based on which all the
// recurring instances would be dynamically generated
const baseRecurringEvent = await Event.create(
[
{
...data,
recurring: true,
isBaseRecurringEvent: true,
creatorId,
admins: [creatorId],
organization: organizationId,
},
],
{ session },
);

if (!baseRecurringEventId) {
const baseRecurringEvent = await Event.create(
[
{
...data,
recurring: true,
isBaseRecurringEvent: true,
creatorId,
admins: [creatorId],
organization: organizationId,
},
],
{ session },
);

baseRecurringEventId = baseRecurringEvent[0]._id.toString();
}

// get the dates for the recurringInstances, and the date of the last instance
// to be generated in this operation (rest would be generated dynamically during query)
Expand All @@ -84,15 +90,15 @@ export const createRecurringEvent = async (
data.startDate,
data.endDate,
organizationId,
baseRecurringEvent[0]?._id.toString(),
baseRecurringEventId as string,
latestInstanceDate,
session,
);

// generate the recurring instances and get an instance back
const recurringEventInstance = await generateRecurringEventInstances({
data,
baseRecurringEventId: baseRecurringEvent[0]?._id.toString(),
baseRecurringEventId: baseRecurringEventId as string,
recurrenceRuleId: recurrenceRule?._id.toString(),
recurringInstanceDates,
creatorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Event, InterfaceEvent } from "../../../models";
import { MutationUpdateEventArgs } from "../../../types/generatedGraphQLTypes";
import { RecurrenceRule } from "../../../models/RecurrenceRule";

export const updateAllRecurringInstances = async (
export const updateAllInstances = async (
args: MutationUpdateEventArgs,
event: InterfaceEvent,
session: mongoose.ClientSession,
Expand All @@ -26,7 +26,8 @@ export const updateAllRecurringInstances = async (
(recurrenceRule.endDate === null && baseRecurringEvent.endDate === null) ||
(recurrenceRule.endDate &&
baseRecurringEvent.endDate &&
recurrenceRule.endDate.toISOString() === baseRecurringEvent.endDate)
recurrenceRule.endDate.toString() ===
baseRecurringEvent.endDate.toString())
) {
await Event.updateOne(
{
Expand All @@ -41,8 +42,6 @@ export const updateAllRecurringInstances = async (
);
}

console.log("here");

await Event.updateMany(
{
recurrenceRuleId,
Expand Down

This file was deleted.

This file was deleted.

20 changes: 8 additions & 12 deletions src/helpers/event/updateEventHelpers/updateRecurringEvent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type mongoose from "mongoose";
import { InterfaceEvent } from "../../../models";
import { MutationUpdateEventArgs } from "../../../types/generatedGraphQLTypes";
import { updateCurrentRecurringInstance } from "./updateCurrentRecurringInstance";
import { updateAllRecurringInstances } from "./updateAllRecurringInstances";
import { updateCurrentAndFollowingInstances } from "./updateCurrentAndFollowingInstances";
import { updateThisInstance } from "./updateThisInstance";
import { updateAllInstances } from "./updateAllInstances";
import { updateThisAndFollowingInstances } from "./updateThisAndFollowingInstances";

export const updateRecurringEvent = async (
args: MutationUpdateEventArgs,
Expand All @@ -16,19 +16,15 @@ export const updateRecurringEvent = async (
(args.data?.isRecurringEventException &&
args.data?.isRecurringEventException !==
event.isRecurringEventException) ||
args.recurringEventUpdateType === "ThisEvent"
args.recurringEventUpdateType === "ThisInstance"
) {
updatedEvent = await updateCurrentRecurringInstance(args, event, session);
} else if (args.recurringEventUpdateType === "AllEvents") {
updatedEvent = await updateThisInstance(args, event, session);
} else if (args.recurringEventUpdateType === "AllInstances") {
// perform a regular bulk update on all the instances
updatedEvent = await updateAllRecurringInstances(args, event, session);
updatedEvent = await updateAllInstances(args, event, session);
} else {
// update current and following events
updatedEvent = await updateCurrentAndFollowingInstances(
event,
// args,
// session,
);
updatedEvent = await updateThisAndFollowingInstances(args, event, session);
}

return updatedEvent;
Expand Down
1 change: 1 addition & 0 deletions src/helpers/event/updateEventHelpers/updateSingleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const updateSingleEvent = async (
creatorId,
organizationId,
session,
null,
true,
);

Expand Down
Loading

0 comments on commit 81a3625

Please sign in to comment.