added space product service

This commit is contained in:
hannathkadher
2024-11-20 16:34:44 +04:00
parent bc1638aba4
commit 11564eece7
6 changed files with 128 additions and 1 deletions

View File

@ -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,