import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, OneToMany, } from 'typeorm'; import { AppointmentStatus } from '../common/enums'; import { Group } from './group.entity'; import { Game } from './game.entity'; import { User } from './user.entity'; import { AppointmentParticipant } from './appointment-participant.entity'; @Entity('appointments') export class Appointment { @PrimaryGeneratedColumn('uuid') id: string; @Column() groupId: string; @ManyToOne(() => Group, (group) => group.appointments, { onDelete: 'CASCADE', }) @JoinColumn({ name: 'groupId' }) group: Group; @Column() gameId: string; @ManyToOne(() => Game, (game) => game.appointments) @JoinColumn({ name: 'gameId' }) game: Game; @Column() initiatorId: string; @ManyToOne(() => User, (user) => user.appointments) @JoinColumn({ name: 'initiatorId' }) initiator: User; @Column({ type: 'varchar', length: 200, nullable: true }) title: string; @Column({ type: 'text', nullable: true }) description: string; @Column({ type: 'datetime' }) startTime: Date; @Column({ type: 'datetime', nullable: true }) endTime: Date; @Column({ comment: '最大参与人数' }) maxParticipants: number; @Column({ default: 0, comment: '当前参与人数' }) currentParticipants: number; @Column({ type: 'enum', enum: AppointmentStatus, default: AppointmentStatus.OPEN, }) status: AppointmentStatus; @CreateDateColumn() createdAt: Date; @UpdateDateColumn() updatedAt: Date; @OneToMany( () => AppointmentParticipant, (participant) => participant.appointment, ) participants: AppointmentParticipant[]; }