mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
added subspace and space product allocation entity
This commit is contained in:
@ -0,0 +1,37 @@
|
|||||||
|
import { Entity, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
|
||||||
|
import { SpaceEntity } from './space.entity';
|
||||||
|
import { SpaceModelProductAllocationEntity } from '../../space-model';
|
||||||
|
import { ProductEntity } from '../../product/entities';
|
||||||
|
import { NewTagEntity } from '../../tag';
|
||||||
|
|
||||||
|
@Entity({ name: 'space_product_allocation' })
|
||||||
|
export class SpaceProductAllocationEntity {
|
||||||
|
@Column({
|
||||||
|
type: 'uuid',
|
||||||
|
default: () => 'gen_random_uuid()',
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => SpaceEntity, (space) => space.productAllocations, {
|
||||||
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
public space: SpaceEntity;
|
||||||
|
|
||||||
|
@ManyToOne(() => SpaceModelProductAllocationEntity, {
|
||||||
|
nullable: true,
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
})
|
||||||
|
public inheritedFromModel?: SpaceModelProductAllocationEntity;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProductEntity, { nullable: false, onDelete: 'CASCADE' })
|
||||||
|
public product: ProductEntity;
|
||||||
|
|
||||||
|
@Column({ type: 'int', default: 1 })
|
||||||
|
public allowedQuantity: number;
|
||||||
|
|
||||||
|
@ManyToMany(() => NewTagEntity)
|
||||||
|
@JoinTable({ name: 'space_product_tags' })
|
||||||
|
public allowedTags: NewTagEntity[];
|
||||||
|
}
|
@ -10,6 +10,7 @@ import { SceneEntity } from '../../scene/entities';
|
|||||||
import { SpaceModelEntity } from '../../space-model';
|
import { SpaceModelEntity } from '../../space-model';
|
||||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||||
import { TagEntity } from './tag.entity';
|
import { TagEntity } from './tag.entity';
|
||||||
|
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||||
|
|
||||||
@Entity({ name: 'space' })
|
@Entity({ name: 'space' })
|
||||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
@ -105,6 +106,15 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
@OneToMany(() => TagEntity, (tag) => tag.space)
|
@OneToMany(() => TagEntity, (tag) => tag.space)
|
||||||
tags: TagEntity[];
|
tags: TagEntity[];
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => SpaceProductAllocationEntity,
|
||||||
|
(allocation) => allocation.space,
|
||||||
|
{
|
||||||
|
cascade: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
public productAllocations: SpaceProductAllocationEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SpaceEntity>) {
|
constructor(partial: Partial<SpaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export * from './subspace.entity';
|
export * from './subspace.entity';
|
||||||
|
export * from './subspace-product-allocation.entity';
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
ManyToOne,
|
||||||
|
ManyToMany,
|
||||||
|
JoinTable,
|
||||||
|
Unique,
|
||||||
|
} from 'typeorm';
|
||||||
|
import { SubspaceEntity } from './subspace.entity';
|
||||||
|
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||||
|
import { NewTagEntity } from '@app/common/modules/tag';
|
||||||
|
import { SubspaceModelProductAllocationEntity } from '@app/common/modules/space-model';
|
||||||
|
|
||||||
|
@Entity({ name: 'subspace_product_allocation' })
|
||||||
|
@Unique(['subspaceModel', 'product', 'allowedTags'])
|
||||||
|
export class SubspaceProductAllocationEntity {
|
||||||
|
@Column({
|
||||||
|
type: 'uuid',
|
||||||
|
default: () => 'gen_random_uuid()',
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public uuid: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => SubspaceEntity, (subspace) => subspace.productAllocations, {
|
||||||
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
public subspace: SubspaceEntity;
|
||||||
|
|
||||||
|
@ManyToOne(() => SubspaceModelProductAllocationEntity, {
|
||||||
|
nullable: true,
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
})
|
||||||
|
public inheritedFromModel?: SubspaceModelProductAllocationEntity;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProductEntity, { nullable: false, onDelete: 'CASCADE' })
|
||||||
|
public product: ProductEntity;
|
||||||
|
|
||||||
|
@Column({ type: 'int', default: 1 })
|
||||||
|
public allowedQuantity: number;
|
||||||
|
|
||||||
|
@ManyToMany(() => NewTagEntity)
|
||||||
|
@JoinTable({ name: 'subspace_product_tags' })
|
||||||
|
public allowedTags: NewTagEntity[];
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
|||||||
import { SubspaceDto } from '../../dtos';
|
import { SubspaceDto } from '../../dtos';
|
||||||
import { SpaceEntity } from '../space.entity';
|
import { SpaceEntity } from '../space.entity';
|
||||||
import { TagEntity } from '../tag.entity';
|
import { TagEntity } from '../tag.entity';
|
||||||
|
import { SubspaceProductAllocationEntity } from './subspace-product-allocation.entity';
|
||||||
|
|
||||||
@Entity({ name: 'subspace' })
|
@Entity({ name: 'subspace' })
|
||||||
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||||
@ -45,6 +46,13 @@ export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
|||||||
@OneToMany(() => TagEntity, (tag) => tag.subspace)
|
@OneToMany(() => TagEntity, (tag) => tag.subspace)
|
||||||
tags: TagEntity[];
|
tags: TagEntity[];
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => SubspaceProductAllocationEntity,
|
||||||
|
(allocation) => allocation.subspace,
|
||||||
|
{ cascade: true },
|
||||||
|
)
|
||||||
|
public productAllocations: SubspaceProductAllocationEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SubspaceEntity>) {
|
constructor(partial: Partial<SubspaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
Reference in New Issue
Block a user