Files
serverMontime/src/entities/business.entity.ts
T

80 lines
2.0 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 { BusinessCategoryEntity } from './business-category.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({ nullable: true, length: 500 })
description!: string | null;
@Column({ nullable: true, length: 20 })
contactPhone!: string | null;
@Column({ 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;
@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(() => BusinessServiceEntity, (service) => service.business)
services!: BusinessServiceEntity[];
@OneToMany(() => BusinessAttributeValueEntity, (attr) => attr.business)
attributes!: BusinessAttributeValueEntity[];
@OneToMany(() => BookingEntity, (booking) => booking.business)
bookings!: BookingEntity[];
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}