Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add tests for deleting recurring events #2158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const deleteRecurringEventInstances = async (
{ eventId: { $in: recurringEventInstancesIds } },
{ session },
),

User.updateMany(
{
registeredEvents: { $in: recurringEventInstancesIds },
Expand Down Expand Up @@ -90,21 +91,22 @@ export const deleteRecurringEventInstances = async (
{ session },
),

// delete action items associated to the instances
ActionItem.deleteMany(
{ eventId: { $in: recurringEventInstancesIds } },
{ session },
),
]);

// delete the instances
await Event.deleteMany(
{
_id: { $in: recurringEventInstancesIds },
},
{
session,
},
);
// delete the instances
Event.deleteMany(
{
_id: { $in: recurringEventInstancesIds },
},
{
session,
},
),
]);

// get the instances following the current recurrence rule (if any)
const instancesFollowingCurrentRecurrence = await Event.find(
Expand Down
22 changes: 12 additions & 10 deletions src/helpers/event/deleteEventHelpers/deleteSingleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const deleteSingleEvent = async (
},
{ session },
),

User.updateMany(
{ registeredEvents: eventId },
{
Expand All @@ -36,6 +37,7 @@ export const deleteSingleEvent = async (
},
{ session },
),

AppUserProfile.updateMany(
{
$or: [{ createdEvents: eventId }, { eventAdmin: eventId }],
Expand All @@ -48,16 +50,16 @@ export const deleteSingleEvent = async (
},
{ session },
),

ActionItem.deleteMany({ eventId }, { session }),
]);

// delete the event
await Event.deleteOne(
{
_id: eventId,
},
{
session,
},
);
Event.deleteOne(
{
_id: eventId,
},
{
session,
},
),
]);
};
40 changes: 4 additions & 36 deletions src/resolvers/Mutation/removeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,42 +108,10 @@ export const removeEvent: MutationResolvers["removeEvent"] = async (
);
}

await AppUserProfile.updateMany(
{
createdEvents: event._id,
},
{
$pull: {
createdEvents: event._id,
},
},
);

await AppUserProfile.updateMany(
{
eventAdmin: event._id,
},
{
$pull: {
eventAdmin: event._id,
},
},
);

const updatedEvent = await Event.findOneAndUpdate(
{
_id: event._id,
},
{
status: "DELETED",
},
{
new: true,
},
);

if (updatedEvent !== null) {
await cacheEvents([updatedEvent]);
/* c8 ignore start */
if (session) {
// start a transaction
session.startTransaction();
}

/* c8 ignore stop */
Expand Down
Loading
Loading