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