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