mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
Add SpaceTypeRepository to CommunityModule imports
This commit is contained in:
@ -4,11 +4,13 @@ import { CommunityController } from './controllers/community.controller';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { SpaceTypeRepositoryModule } from '@app/common/modules/space-type/space.type.repository.module';
|
||||
import { SpaceTypeRepository } from '@app/common/modules/space-type/repositories';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, SpaceRepositoryModule],
|
||||
imports: [ConfigModule, SpaceRepositoryModule, SpaceTypeRepositoryModule],
|
||||
controllers: [CommunityController],
|
||||
providers: [CommunityService, SpaceRepository],
|
||||
providers: [CommunityService, SpaceRepository, SpaceTypeRepository],
|
||||
exports: [CommunityService],
|
||||
})
|
||||
export class CommunityModule {}
|
||||
|
@ -43,7 +43,6 @@ export class CommunityController {
|
||||
try {
|
||||
const community =
|
||||
await this.communityService.getCommunityByUuid(communityUuid);
|
||||
|
||||
return community;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
|
@ -18,14 +18,6 @@ export class AddCommunityDto {
|
||||
@IsOptional()
|
||||
public parentUuid?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'spaceTypeUuid',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceTypeUuid: string;
|
||||
|
||||
constructor(dto: Partial<AddCommunityDto>) {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceTypeRepository } from './../../../libs/common/src/modules/space-type/repositories/space.type.repository';
|
||||
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { AddCommunityDto } from '../dtos';
|
||||
@ -5,14 +6,23 @@ import { GetCommunityByUuidInterface } from '../interface/community.interface';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityService {
|
||||
constructor(private readonly spaceRepository: SpaceRepository) {}
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly spaceTypeRepository: SpaceTypeRepository,
|
||||
) {}
|
||||
|
||||
async addCommunity(addCommunityDto: AddCommunityDto) {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'community',
|
||||
},
|
||||
});
|
||||
|
||||
await this.spaceRepository.save({
|
||||
spaceName: addCommunityDto.spaceName,
|
||||
parent: { uuid: addCommunityDto.parentUuid },
|
||||
spaceType: { uuid: addCommunityDto.spaceTypeUuid },
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@ -27,6 +37,9 @@ export class CommunityService {
|
||||
await this.spaceRepository.findOne({
|
||||
where: {
|
||||
uuid: communityUuid,
|
||||
spaceType: {
|
||||
type: 'community',
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
|
Reference in New Issue
Block a user