73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
ManyToOne,
|
|
OneToMany,
|
|
OneToOne,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
JoinColumn,
|
|
} from 'typeorm';
|
|
import { EventType } from './event-type.entity';
|
|
import { RecurrenceRule } from './recurrence-rule.entity';
|
|
import { EventException } from './event-exception.entity';
|
|
import { Booking } from './booking.entity';
|
|
|
|
@Entity('events')
|
|
export class Event {
|
|
@PrimaryGeneratedColumn({ type: 'bigint' })
|
|
id: number;
|
|
|
|
@Column({ name: 'title', type: 'varchar', length: 255 })
|
|
title: string;
|
|
|
|
@Column({ name: 'description', type: 'text', nullable: true })
|
|
description: string;
|
|
|
|
@Column({ name: 'start_time', type: 'timestamptz' })
|
|
startTime: Date;
|
|
|
|
@Column({ name: 'end_time', type: 'timestamptz' })
|
|
endTime: Date;
|
|
|
|
@Column({ name: 'timezone', type: 'varchar', length: 50 })
|
|
timezone: string;
|
|
|
|
@Column({ name: 'is_recurring', type: 'boolean', default: false })
|
|
isRecurring: boolean;
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
|
|
updatedAt: Date;
|
|
|
|
// --- Relationships ---
|
|
|
|
@Column({ name: 'event_type_id', type: 'bigint', nullable: true })
|
|
eventTypeId: number;
|
|
|
|
@ManyToOne(() => EventType, (eventType) => eventType.events, {
|
|
nullable: true,
|
|
onDelete: 'SET NULL', // As requested for optional relationship
|
|
})
|
|
@JoinColumn({ name: 'event_type_id' })
|
|
eventType: EventType;
|
|
|
|
@OneToOne(() => RecurrenceRule, (rule) => rule.event, {
|
|
cascade: true, // Automatically save/update recurrence rule when event is saved
|
|
})
|
|
recurrenceRule: RecurrenceRule;
|
|
|
|
@OneToMany(() => EventException, (exception) => exception.event, {
|
|
cascade: true, // Automatically save/update exceptions when event is saved
|
|
})
|
|
exceptions: EventException[];
|
|
|
|
@OneToMany(() => Booking, (booking) => booking.event, {
|
|
cascade: true, // Automatically save/update exceptions when event is saved
|
|
})
|
|
bookings: Booking[];
|
|
}
|