mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 22:34:54 +00:00
added entities for space product item
This commit is contained in:
@ -11,6 +11,7 @@ import { PermissionTypeEntity } from '../modules/permission/entities';
|
|||||||
import {
|
import {
|
||||||
SpaceEntity,
|
SpaceEntity,
|
||||||
SpaceLinkEntity,
|
SpaceLinkEntity,
|
||||||
|
SpaceProductItemEntity,
|
||||||
SubspaceEntity,
|
SubspaceEntity,
|
||||||
} from '../modules/space/entities';
|
} from '../modules/space/entities';
|
||||||
import { UserSpaceEntity } from '../modules/user/entities';
|
import { UserSpaceEntity } from '../modules/user/entities';
|
||||||
@ -78,6 +79,8 @@ import {
|
|||||||
SpaceProductModelEntity,
|
SpaceProductModelEntity,
|
||||||
SpaceProductItemModelEntity,
|
SpaceProductItemModelEntity,
|
||||||
SubspaceModelEntity,
|
SubspaceModelEntity,
|
||||||
|
SpaceProductEntity,
|
||||||
|
SpaceProductItemEntity,
|
||||||
],
|
],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export * from './subspace-model.dto';
|
export * from './subspace-model.dto';
|
||||||
export * from './space-model.dto';
|
export * from './space-model.dto';
|
||||||
export * from './space-product-item.dto';
|
export * from './space-product-item-model.dto';
|
||||||
export * from './space-product-model.dto';
|
export * from './space-product-model.dto';
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { IsString, IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
|
export class SpaceProductItemModelDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
uuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
tag: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
spaceProductModelUuid: string;
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||||
import { SpaceProductItemDto } from './space-product-item.dto';
|
import { SpaceProductItemModelDto } from './space-product-item-model.dto';
|
||||||
|
|
||||||
export class SpaceProductModelDto {
|
export class SpaceProductModelDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -17,7 +17,7 @@ export class SpaceProductModelDto {
|
|||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'List of individual items with specific names for the product',
|
description: 'List of individual items with specific names for the product',
|
||||||
type: [SpaceProductItemDto],
|
type: [SpaceProductItemModelDto],
|
||||||
})
|
})
|
||||||
items: SpaceProductItemDto[];
|
items: SpaceProductItemModelDto[];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
import { Entity, Column, ManyToOne, Unique } from 'typeorm';
|
import { Entity, Column, ManyToOne } from 'typeorm';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { SpaceProductItemDto } from '../dtos';
|
import { SpaceProductItemModelDto } from '../dtos';
|
||||||
import { SpaceProductModelEntity } from './space-product-model.entity';
|
import { SpaceProductModelEntity } from './space-product-model.entity';
|
||||||
import { SpaceModelEntity } from './space-model.entity';
|
|
||||||
|
|
||||||
@Entity({ name: 'space-product-item-model' })
|
@Entity({ name: 'space-product-item-model' })
|
||||||
@Unique(['tag', 'spaceProductModel', 'spaceModel'])
|
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemModelDto> {
|
||||||
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemDto> {
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: false,
|
nullable: false,
|
||||||
})
|
})
|
||||||
@ -20,13 +18,4 @@ export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItem
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
public spaceProductModel: SpaceProductModelEntity;
|
public spaceProductModel: SpaceProductModelEntity;
|
||||||
|
|
||||||
@ManyToOne(
|
|
||||||
() => SpaceModelEntity,
|
|
||||||
(spaceModel) => spaceModel.spaceProductModels,
|
|
||||||
{
|
|
||||||
nullable: false,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
public spaceModel: SpaceModelEntity;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,2 +1,4 @@
|
|||||||
export * from './space.dto';
|
export * from './space.dto';
|
||||||
export * from './subspace.dto';
|
export * from './subspace.dto';
|
||||||
|
export * from './space-product-item.dto';
|
||||||
|
export * from './space-product.dto';
|
||||||
|
|||||||
@ -11,5 +11,5 @@ export class SpaceProductItemDto {
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
spaceProductModelUuid: string;
|
spaceProductUuid: string;
|
||||||
}
|
}
|
||||||
23
libs/common/src/modules/space/dtos/space-product.dto.ts
Normal file
23
libs/common/src/modules/space/dtos/space-product.dto.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';
|
||||||
|
import { SpaceProductItemDto } from './space-product-item.dto';
|
||||||
|
|
||||||
|
export class SpaceProductModelDto {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
uuid: string;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
productCount: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
productUuid: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'List of individual items with specific names for the product',
|
||||||
|
type: [SpaceProductItemDto],
|
||||||
|
})
|
||||||
|
items: SpaceProductItemDto[];
|
||||||
|
}
|
||||||
@ -1,3 +1,5 @@
|
|||||||
export * from './space.entity';
|
export * from './space.entity';
|
||||||
export * from './subspace.entity';
|
export * from './subspace.entity';
|
||||||
|
export * from './space-product-item.entity';
|
||||||
|
export * from './space-product.entity';
|
||||||
export * from './space-link.entity';
|
export * from './space-link.entity';
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||||
|
import { SpaceProductEntity } from './space-product.entity';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
import { SpaceProductItemDto } from '../dtos';
|
||||||
|
|
||||||
|
@Entity({ name: 'space-product-item-model' })
|
||||||
|
export class SpaceProductItemEntity extends AbstractEntity<SpaceProductItemDto> {
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public tag: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => SpaceProductEntity, (spaceProduct) => spaceProduct.items, {
|
||||||
|
nullable: false,
|
||||||
|
})
|
||||||
|
public spaceProducts: SpaceProductEntity;
|
||||||
|
}
|
||||||
@ -1,7 +1,8 @@
|
|||||||
import { Column, Entity, ManyToOne, JoinColumn } from 'typeorm';
|
import { Column, Entity, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
|
||||||
import { SpaceEntity } from './space.entity';
|
import { SpaceEntity } from './space.entity';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { ProductEntity } from '../../product/entities';
|
import { ProductEntity } from '../../product/entities';
|
||||||
|
import { SpaceProductItemEntity } from './space-product-item.entity';
|
||||||
|
|
||||||
@Entity({ name: 'space-product' })
|
@Entity({ name: 'space-product' })
|
||||||
export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
|
export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
|
||||||
@ -25,6 +26,11 @@ export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
|
|||||||
})
|
})
|
||||||
productCount: number;
|
productCount: number;
|
||||||
|
|
||||||
|
@OneToMany(() => SpaceProductItemEntity, (item) => item.spaceProducts, {
|
||||||
|
cascade: true,
|
||||||
|
})
|
||||||
|
public items: SpaceProductItemEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SpaceProductEntity>) {
|
constructor(partial: Partial<SpaceProductEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
|||||||
@ -19,14 +19,13 @@ export class SpaceProductItemModelService {
|
|||||||
spaceModel: SpaceModelEntity,
|
spaceModel: SpaceModelEntity,
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
) {
|
) {
|
||||||
await this.validateTags(itemModelDtos, spaceModel, queryRunner);
|
await this.validateTags(itemModelDtos, queryRunner, spaceModel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const productItems = itemModelDtos.map((dto) =>
|
const productItems = itemModelDtos.map((dto) =>
|
||||||
queryRunner.manager.create(this.spaceProductItemRepository.target, {
|
queryRunner.manager.create(this.spaceProductItemRepository.target, {
|
||||||
tag: dto.tag,
|
tag: dto.tag,
|
||||||
spaceProductModel,
|
spaceProductModel,
|
||||||
spaceModel,
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -46,8 +45,8 @@ export class SpaceProductItemModelService {
|
|||||||
|
|
||||||
private async validateTags(
|
private async validateTags(
|
||||||
itemModelDtos: CreateSpaceProductItemModelDto[],
|
itemModelDtos: CreateSpaceProductItemModelDto[],
|
||||||
spaceModel: SpaceModelEntity,
|
|
||||||
queryRunner: QueryRunner,
|
queryRunner: QueryRunner,
|
||||||
|
spaceModel: SpaceModelEntity,
|
||||||
) {
|
) {
|
||||||
const incomingTags = itemModelDtos.map((item) => item.tag);
|
const incomingTags = itemModelDtos.map((item) => item.tag);
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ export class SpaceProductItemModelService {
|
|||||||
const existingTags = await queryRunner.manager.find(
|
const existingTags = await queryRunner.manager.find(
|
||||||
this.spaceProductItemRepository.target,
|
this.spaceProductItemRepository.target,
|
||||||
{
|
{
|
||||||
where: { spaceModel },
|
where: { spaceProductModel: { spaceModel } },
|
||||||
select: ['tag'],
|
select: ['tag'],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user