mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 22:34:54 +00:00
added subspace product
This commit is contained in:
@ -13,6 +13,7 @@ import {
|
|||||||
SpaceLinkEntity,
|
SpaceLinkEntity,
|
||||||
SpaceProductItemEntity,
|
SpaceProductItemEntity,
|
||||||
SubspaceEntity,
|
SubspaceEntity,
|
||||||
|
SubspaceProductEntity,
|
||||||
} from '../modules/space/entities';
|
} from '../modules/space/entities';
|
||||||
import { UserSpaceEntity } from '../modules/user/entities';
|
import { UserSpaceEntity } from '../modules/user/entities';
|
||||||
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||||
@ -85,6 +86,7 @@ import {
|
|||||||
SpaceProductItemEntity,
|
SpaceProductItemEntity,
|
||||||
SubspaceProductModelEntity,
|
SubspaceProductModelEntity,
|
||||||
SubspaceProductItemModelEntity,
|
SubspaceProductItemModelEntity,
|
||||||
|
SubspaceProductEntity,
|
||||||
],
|
],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
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.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 { 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 { SubspaceProductEntity } from './subspace-product.entity';
|
||||||
|
|
||||||
@Entity({ name: 'subspace' })
|
@Entity({ name: 'subspace' })
|
||||||
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||||
@ -35,6 +36,15 @@ export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
|||||||
@JoinColumn({ name: 'subspace_model_uuid' })
|
@JoinColumn({ name: 'subspace_model_uuid' })
|
||||||
subSpaceModel?: SubspaceModelEntity;
|
subSpaceModel?: SubspaceModelEntity;
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => SubspaceProductEntity,
|
||||||
|
(subspaceProduct) => subspaceProduct.subspace,
|
||||||
|
{
|
||||||
|
nullable: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
public subspaceProducts: SubspaceProductEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SubspaceEntity>) {
|
constructor(partial: Partial<SubspaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
|||||||
@ -1,11 +1,17 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { SpaceEntity, SubspaceEntity } from './entities';
|
import { SpaceEntity, SubspaceEntity, SubspaceProductEntity } from './entities';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([SpaceEntity, SubspaceEntity])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
SpaceEntity,
|
||||||
|
SubspaceEntity,
|
||||||
|
SubspaceProductEntity,
|
||||||
|
]),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class SpaceRepositoryModule {}
|
export class SpaceRepositoryModule {}
|
||||||
|
|||||||
Reference in New Issue
Block a user