145 lines
4.5 KiB
TypeScript
145 lines
4.5 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { BookingEntity } from './booking.entity';
|
|
import { BusinessAttributeValueEntity } from './business-attribute-value.entity';
|
|
import { BusinessAvailabilitySlotEntity } from './business-availability-slot.entity';
|
|
import { BusinessCategoryEntity } from './business-category.entity';
|
|
import { BusinessImageEntity } from './business-image.entity';
|
|
import { BusinessServiceClassEntity } from './business-service-class.entity';
|
|
import { BusinessServiceEntity } from './business-service.entity';
|
|
import { UserEntity } from './user.entity';
|
|
|
|
@Entity('businesses')
|
|
export class BusinessEntity {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ length: 150 })
|
|
title!: string;
|
|
|
|
@Column({ unique: true, length: 120 })
|
|
slug!: string;
|
|
|
|
@Column({ type: 'varchar', nullable: true, length: 150 })
|
|
subtitle!: string | null;
|
|
|
|
@Column({ type: 'varchar', nullable: true, length: 500 })
|
|
description!: string | null;
|
|
|
|
@Column({ type: 'varchar', nullable: true, length: 20 })
|
|
contactPhone!: string | null;
|
|
|
|
@Column({ type: 'varchar', nullable: true, length: 500 })
|
|
address!: string | null;
|
|
|
|
@Column({ type: 'double precision', nullable: true })
|
|
latitude!: number | null;
|
|
|
|
@Column({ type: 'double precision', nullable: true })
|
|
longitude!: number | null;
|
|
|
|
@Column({ default: true })
|
|
isActive!: boolean;
|
|
|
|
@Column({ default: false })
|
|
serviceClassesEnabled!: boolean;
|
|
|
|
@Column({ type: 'int', default: 1 })
|
|
concurrentCapacity!: number;
|
|
|
|
@Column({ type: 'int', default: 30 })
|
|
slotStepMinutes!: number;
|
|
|
|
/** When true, new bookings skip manual owner approval and go straight to payment. */
|
|
@Column({ default: false })
|
|
autoApproveBookings!: boolean;
|
|
|
|
/** When true, customers can leave an optional gratuity after rating a completed booking. */
|
|
@Column({ default: false })
|
|
tipsEnabled!: boolean;
|
|
|
|
/** Owner-defined promotional percentage discount. */
|
|
@Column({ default: false })
|
|
promoDiscountEnabled!: boolean;
|
|
|
|
/** Banner / receipt title, e.g. "اولین رزرو شما" or "تخفیف ویژه تابستان". */
|
|
@Column({ type: 'varchar', nullable: true, length: 150 })
|
|
promoDiscountTitle!: string | null;
|
|
|
|
@Column({ type: 'int', nullable: true })
|
|
promoDiscountPercent!: number | null;
|
|
|
|
/** Display code on landing (auto-applied; not a separate redeem step). */
|
|
@Column({ type: 'varchar', nullable: true, length: 40 })
|
|
promoDiscountCode!: string | null;
|
|
|
|
/** `first_booking` = only first booking of customer at this business; `always` = every booking while enabled. */
|
|
@Column({ type: 'varchar', length: 20, default: 'first_booking' })
|
|
promoDiscountMode!: 'first_booking' | 'always';
|
|
|
|
/** Up to 3 keys from the platform highlight catalog for the landing hero. */
|
|
@Column({ name: 'hero_highlight_keys', type: 'jsonb', nullable: true })
|
|
heroHighlightKeys!: string[] | null;
|
|
|
|
@Column({ name: 'logo_light_url', type: 'varchar', length: 500, nullable: true })
|
|
logoLightUrl!: string | null;
|
|
|
|
@Column({ name: 'logo_dark_url', type: 'varchar', length: 500, nullable: true })
|
|
logoDarkUrl!: string | null;
|
|
|
|
@ManyToOne(() => BusinessCategoryEntity, (category) => category.businesses, {
|
|
onDelete: 'RESTRICT',
|
|
})
|
|
@JoinColumn({ name: 'categoryId' })
|
|
category!: BusinessCategoryEntity;
|
|
|
|
@Column('uuid')
|
|
categoryId!: string;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.ownedBusinesses, {
|
|
nullable: true,
|
|
onDelete: 'SET NULL',
|
|
})
|
|
@JoinColumn({ name: 'ownerId' })
|
|
owner!: UserEntity | null;
|
|
|
|
@Column({ type: 'uuid', nullable: true })
|
|
ownerId!: string | null;
|
|
|
|
@OneToMany(() => BusinessImageEntity, (image) => image.business, {
|
|
cascade: true,
|
|
})
|
|
images!: BusinessImageEntity[];
|
|
|
|
@OneToMany(() => BusinessServiceEntity, (service) => service.business)
|
|
services!: BusinessServiceEntity[];
|
|
|
|
@OneToMany(() => BusinessServiceClassEntity, (serviceClass) => serviceClass.business)
|
|
serviceClasses!: BusinessServiceClassEntity[];
|
|
|
|
@OneToMany(() => BusinessAttributeValueEntity, (attr) => attr.business)
|
|
attributes!: BusinessAttributeValueEntity[];
|
|
|
|
@OneToMany(() => BookingEntity, (booking) => booking.business)
|
|
bookings!: BookingEntity[];
|
|
|
|
@OneToMany(() => BusinessAvailabilitySlotEntity, (slot) => slot.business, {
|
|
cascade: true,
|
|
})
|
|
availabilitySlots!: BusinessAvailabilitySlotEntity[];
|
|
|
|
@CreateDateColumn()
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn()
|
|
updatedAt!: Date;
|
|
}
|