mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 21:04:53 +00:00
added subspace product
This commit is contained in:
@ -13,6 +13,7 @@ import {
|
||||
SpaceLinkEntity,
|
||||
SpaceProductItemEntity,
|
||||
SubspaceEntity,
|
||||
SubspaceProductEntity,
|
||||
} from '../modules/space/entities';
|
||||
import { UserSpaceEntity } from '../modules/user/entities';
|
||||
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||
@ -85,6 +86,7 @@ import {
|
||||
SpaceProductItemEntity,
|
||||
SubspaceProductModelEntity,
|
||||
SubspaceProductItemModelEntity,
|
||||
SubspaceProductEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';
|
||||
|
||||
export class SubspaceProductDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
uuid: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
productCount: number;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
productUuid: string;
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
export * from './subspace.entity';
|
||||
export * from './subspace-product.entity';
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { SubspaceEntity } from './subspace.entity';
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
import { SubspaceProductDto } from '../../dtos/subspace/subspace-product.dto';
|
||||
|
||||
@Entity({ name: 'subspace-product' })
|
||||
export class SubspaceProductEntity extends AbstractEntity<SubspaceProductDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@ManyToOne(() => SubspaceEntity, (subspace) => subspace.subspaceProducts, {
|
||||
nullable: false,
|
||||
})
|
||||
public subspace: SubspaceEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.subpaceProductModels, {
|
||||
nullable: false,
|
||||
})
|
||||
public product: ProductEntity;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import { SubspaceModelEntity } from '@app/common/modules/space-model';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SubspaceDto } from '../../dtos';
|
||||
import { SpaceEntity } from '../space.entity';
|
||||
import { SubspaceProductEntity } from './subspace-product.entity';
|
||||
|
||||
@Entity({ name: 'subspace' })
|
||||
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||
@ -35,6 +36,15 @@ export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||
@JoinColumn({ name: 'subspace_model_uuid' })
|
||||
subSpaceModel?: SubspaceModelEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductEntity,
|
||||
(subspaceProduct) => subspaceProduct.subspace,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
public subspaceProducts: SubspaceProductEntity[];
|
||||
|
||||
constructor(partial: Partial<SubspaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SpaceEntity, SubspaceEntity } from './entities';
|
||||
import { SpaceEntity, SubspaceEntity, SubspaceProductEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([SpaceEntity, SubspaceEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
SpaceEntity,
|
||||
SubspaceEntity,
|
||||
SubspaceProductEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class SpaceRepositoryModule {}
|
||||
|
||||
Reference in New Issue
Block a user