Files
serverMontime/src/entities/booking.entity.ts
T
2026-06-29 19:31:26 +03:30

95 lines
2.5 KiB
TypeScript

import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { BusinessEntity } from './business.entity';
import { BusinessServiceEntity } from './business-service.entity';
import { BusinessServiceClassEntity } from './business-service-class.entity';
import { UserEntity } from './user.entity';
export enum BookingStatus {
PENDING = 'pending',
AWAITING_PAYMENT = 'awaiting_payment',
CONFIRMED = 'confirmed',
CANCELLED = 'cancelled',
COMPLETED = 'completed',
}
@Entity('bookings')
export class BookingEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@ManyToOne(() => UserEntity, (user) => user.bookings, { onDelete: 'RESTRICT' })
@JoinColumn({ name: 'customerId' })
customer!: UserEntity;
@Column('uuid')
customerId!: string;
@ManyToOne(() => BusinessEntity, (business) => business.bookings, { onDelete: 'RESTRICT' })
@JoinColumn({ name: 'businessId' })
business!: BusinessEntity;
@Column('uuid')
businessId!: string;
@ManyToOne(() => BusinessServiceEntity, (service) => service.bookings, {
onDelete: 'RESTRICT',
})
@JoinColumn({ name: 'businessServiceId' })
businessService!: BusinessServiceEntity;
@Column('uuid')
businessServiceId!: string;
@ManyToOne(() => BusinessServiceClassEntity, { nullable: true, onDelete: 'RESTRICT' })
@JoinColumn({ name: 'serviceClassId' })
serviceClass!: BusinessServiceClassEntity | null;
@Column({ type: 'uuid', nullable: true })
serviceClassId!: string | null;
@Column({ type: 'uuid', nullable: true })
bookingGroupId!: string | null;
@Column({ type: 'timestamptz' })
scheduledAt!: Date;
@Column({ type: 'enum', enum: BookingStatus, default: BookingStatus.PENDING })
status!: BookingStatus;
@Column({ type: 'text', nullable: true })
note!: string | null;
@Column({ type: 'text', nullable: true })
cancellationReason!: string | null;
/** Shared token for paying a booking group (or single booking). */
@Column({ type: 'varchar', nullable: true, length: 64 })
paymentToken!: string | null;
@Column({ type: 'decimal', precision: 12, scale: 0, nullable: true })
paymentAmount!: string | null;
@Column({ type: 'varchar', nullable: true, length: 64 })
paymentAuthority!: string | null;
@Column({ type: 'timestamptz', nullable: true })
completedAt!: Date | null;
@Column({ type: 'timestamptz', nullable: true })
reviewPromptedAt!: Date | null;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}