add calendar dashboard edit

This commit is contained in:
Schneider Roland
2025-12-03 07:47:16 +01:00
parent fa098f4a1b
commit f740c11685
5 changed files with 38 additions and 20 deletions

View File

@@ -374,24 +374,32 @@ export class CalendarService {
event.eventType = undefined;
}
// 4. Handle Recurrence Rule
// Because your entity has @OneToOne(..., { cascade: true }),
// modifying event.recurrenceRule and calling eventRepository.save(event)
// will automatically save/update the rule.
if (event.isRecurring && updateEventDto.recurrenceRule) {
// await this.eventRepository.save(event);
if (updateEventDto.isRecurring) {
const updateRRule = updateEventDto.recurrenceRule;
// If no rule exists yet, initialize a new one
if (!event.recurrenceRule) {
event.recurrenceRule = this.recurrenceRuleRepository.create({});
event.recurrenceRule = this.recurrenceRuleRepository.create({
frequency: 'DAILY',
interval: 1,
count: 1,
} as Partial<RecurrenceRule>);
}
// Update the properties on the relation object
event.recurrenceRule.frequency = updateRRule.frequency;
event.recurrenceRule.interval = updateRRule.interval;
event.recurrenceRule.byDay = updateRRule.byDay as string;
event.recurrenceRule.endDate = updateRRule.endDate as Date;
event.recurrenceRule.count = updateRRule.count as number;
if (updateRRule) {
// Update the properties on the relation object
event.recurrenceRule.frequency = updateRRule.frequency;
event.recurrenceRule.interval = updateRRule.interval;
event.recurrenceRule.byDay = updateRRule.byDay as string;
event.recurrenceRule.endDate = updateRRule.endDate as Date;
event.recurrenceRule.count = updateRRule.count as number;
}
} else {
if (event.recurrenceRule) {
await this.recurrenceRuleRepository.remove(event.recurrenceRule);
event.recurrenceRule = undefined;
}
}
// 5. Use SAVE instead of UPDATE

View File

@@ -58,7 +58,7 @@ export class Event {
@OneToOne(() => RecurrenceRule, (rule) => rule.event, {
cascade: true, // Automatically save/update recurrence rule when event is saved
})
recurrenceRule: RecurrenceRule;
recurrenceRule?: RecurrenceRule;
@OneToMany(() => EventException, (exception) => exception.event, {
cascade: true, // Automatically save/update exceptions when event is saved