mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
refactor: update BookableSpaceEntity relationship to OneToOne with SpaceEntity
This commit is contained in:
@ -1,19 +1,17 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Unique,
|
||||
OneToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
import { DaysEnum } from '@app/common/constants/days.enum';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { BookableSpaceDto } from '../dtos';
|
||||
|
||||
@Entity('bookable-space')
|
||||
@Unique(['space'])
|
||||
export class BookableSpaceEntity extends AbstractEntity<BookableSpaceDto> {
|
||||
export class BookableSpaceEntity extends AbstractEntity {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
@ -21,9 +19,8 @@ export class BookableSpaceEntity extends AbstractEntity<BookableSpaceDto> {
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.bookableConfigs, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@OneToOne(() => SpaceEntity, (space) => space.bookableConfigs)
|
||||
@JoinColumn({ name: 'space_uuid' })
|
||||
space: SpaceEntity;
|
||||
|
||||
@Column({
|
||||
|
@ -1,4 +1,11 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { SpaceDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserSpaceEntity } from '../../user/entities';
|
||||
@ -127,8 +134,8 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
)
|
||||
occupancyDaily: SpaceDailyOccupancyDurationEntity[];
|
||||
|
||||
@OneToMany(() => BookableSpaceEntity, (bookable) => bookable.space)
|
||||
bookableConfigs: BookableSpaceEntity[];
|
||||
@OneToOne(() => BookableSpaceEntity, (bookable) => bookable.space)
|
||||
bookableConfigs: BookableSpaceEntity;
|
||||
|
||||
constructor(partial: Partial<SpaceEntity>) {
|
||||
super();
|
||||
|
Reference in New Issue
Block a user