mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 12:44:54 +00:00
added space product service
This commit is contained in:
@ -11,12 +11,14 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { generateRandomString } from '@app/common/helper/randomString';
|
||||
import { SpaceProductService } from './space-products';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceService {
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
private readonly spaceProductService: SpaceProductService,
|
||||
) {}
|
||||
|
||||
async createSpace(
|
||||
@ -25,7 +27,7 @@ export class SpaceService {
|
||||
): Promise<BaseResponseDto> {
|
||||
let parent: SpaceEntity | null = null;
|
||||
|
||||
const { parentUuid } = addSpaceDto;
|
||||
const { parentUuid, products } = addSpaceDto;
|
||||
const community = await this.communityRepository.findOne({
|
||||
where: { uuid: communityId },
|
||||
});
|
||||
@ -60,6 +62,13 @@ export class SpaceService {
|
||||
|
||||
await this.spaceRepository.save(newSpace);
|
||||
|
||||
if (products && products.length > 0) {
|
||||
await this.spaceProductService.assignProductsToSpace(
|
||||
newSpace,
|
||||
products,
|
||||
);
|
||||
}
|
||||
|
||||
return new SuccessResponseDto({
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: newSpace,
|
||||
|
||||
Reference in New Issue
Block a user