Add business images upload and cascade delete improvements.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { BusinessEntity } from './business.entity';
|
||||
|
||||
@Entity('business_images')
|
||||
export class BusinessImageEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@ManyToOne(() => BusinessEntity, (business) => business.images, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'businessId' })
|
||||
business!: BusinessEntity;
|
||||
|
||||
@Column('uuid')
|
||||
businessId!: string;
|
||||
|
||||
/** Relative path under uploads root, e.g. businesses/{id}/{file}.jpg */
|
||||
@Column({ length: 500 })
|
||||
url!: string;
|
||||
|
||||
@Column({ type: 'varchar', nullable: true, length: 255 })
|
||||
originalName!: string | null;
|
||||
|
||||
@Column({ default: 0 })
|
||||
sortOrder!: number;
|
||||
|
||||
@Column({ default: false })
|
||||
isCover!: boolean;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Date;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { BookingEntity } from './booking.entity';
|
||||
import { BusinessAttributeValueEntity } from './business-attribute-value.entity';
|
||||
import { BusinessCategoryEntity } from './business-category.entity';
|
||||
import { BusinessImageEntity } from './business-image.entity';
|
||||
import { BusinessServiceEntity } from './business-service.entity';
|
||||
import { UserEntity } from './user.entity';
|
||||
|
||||
@@ -62,6 +63,11 @@ export class BusinessEntity {
|
||||
@Column({ type: 'uuid', nullable: true })
|
||||
ownerId!: string | null;
|
||||
|
||||
@OneToMany(() => BusinessImageEntity, (image) => image.business, {
|
||||
cascade: true,
|
||||
})
|
||||
images!: BusinessImageEntity[];
|
||||
|
||||
@OneToMany(() => BusinessServiceEntity, (service) => service.business)
|
||||
services!: BusinessServiceEntity[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user