refactor: remove redundant isRecurring property, use recurrenceRule instead
isRecurring was redundant since recurrenceRule as truthy/falsy check suffices. Removed from shared CalendarEvent type, Mongoose virtual, and all usages.
This commit is contained in:
@@ -2,22 +2,18 @@ import mongoose, { Schema, Document, Model } from "mongoose";
|
||||
import { CalendarEvent } from "@calchat/shared";
|
||||
import { IdVirtual } from "./types";
|
||||
|
||||
interface EventVirtuals extends IdVirtual {
|
||||
isRecurring: boolean;
|
||||
}
|
||||
|
||||
export interface EventDocument
|
||||
extends Omit<CalendarEvent, "id" | "isRecurring">,
|
||||
extends Omit<CalendarEvent, "id">,
|
||||
Document {
|
||||
toJSON(): CalendarEvent;
|
||||
}
|
||||
|
||||
const EventSchema = new Schema<
|
||||
EventDocument,
|
||||
Model<EventDocument, {}, {}, EventVirtuals>,
|
||||
Model<EventDocument, {}, {}, IdVirtual>,
|
||||
{},
|
||||
{},
|
||||
EventVirtuals
|
||||
IdVirtual
|
||||
>(
|
||||
{
|
||||
userId: {
|
||||
@@ -61,11 +57,6 @@ const EventSchema = new Schema<
|
||||
return this._id.toString();
|
||||
},
|
||||
},
|
||||
isRecurring: {
|
||||
get() {
|
||||
return !!this.recurrenceRule;
|
||||
},
|
||||
},
|
||||
},
|
||||
toJSON: {
|
||||
virtuals: true,
|
||||
|
||||
@@ -37,8 +37,8 @@ export class EventService {
|
||||
const allEvents = await this.eventRepo.findByUserId(userId);
|
||||
|
||||
// Separate recurring and non-recurring events
|
||||
const recurringEvents = allEvents.filter((e) => e.isRecurring);
|
||||
const nonRecurringEvents = allEvents.filter((e) => !e.isRecurring);
|
||||
const recurringEvents = allEvents.filter((e) => e.recurrenceRule);
|
||||
const nonRecurringEvents = allEvents.filter((e) => !e.recurrenceRule);
|
||||
|
||||
// Expand all events (recurring get multiple instances, non-recurring stay as-is)
|
||||
const expanded = expandRecurringEvents(
|
||||
@@ -90,7 +90,7 @@ export class EventService {
|
||||
}
|
||||
|
||||
// For non-recurring events, always delete completely
|
||||
if (!event.isRecurring || !event.recurrenceRule) {
|
||||
if (!event.recurrenceRule) {
|
||||
await this.eventRepo.delete(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function expandRecurringEvents(
|
||||
// to find events that start before rangeStart but extend into the range
|
||||
const adjustedRangeStart = new Date(rangeStart.getTime() - duration);
|
||||
|
||||
if (!event.isRecurring || !event.recurrenceRule) {
|
||||
if (!event.recurrenceRule) {
|
||||
// Non-recurring event: add if it overlaps with the range
|
||||
if (endTime >= rangeStart && startTime <= rangeEnd) {
|
||||
expanded.push({
|
||||
|
||||
Reference in New Issue
Block a user