Add UserRepository and addUserCommunity endpoint

This commit is contained in:
faris Aljohari
2024-04-16 17:22:12 +03:00
parent 1d9bb96a87
commit ae63ac6717
4 changed files with 63 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import {
BadRequestException,
} from '@nestjs/common';
import { SpaceRepository } from '@app/common/modules/space/repositories';
import { AddCommunityDto } from '../dtos';
import { AddCommunityDto, AddUserCommunityDto } from '../dtos';
import {
CommunityChildInterface,
GetCommunityByUserUuidInterface,
@ -188,6 +188,26 @@ export class CommunityService {
}
}
}
async addUserCommunity(addUserCommunityDto: AddUserCommunityDto) {
try {
await this.userSpaceRepository.save({
user: { uuid: addUserCommunityDto.userUuid },
space: { uuid: addUserCommunityDto.communityUuid },
});
} catch (err) {
if (err.code === '23505') {
throw new HttpException(
'User already belongs to this community',
HttpStatus.BAD_REQUEST,
);
}
throw new HttpException(
err.message || 'Internal Server Error',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
async renameCommunityByUuid(
communityUuid: string,
updateCommunityDto: UpdateCommunityNameDto,