mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 19:57:55 +00:00
Added all community endpoints
This commit is contained in:
@@ -10,19 +10,27 @@ import { DeviceMessagesService } from './services/device.messages.service';
|
||||
import { DeviceRepositoryModule } from '../modules/device/device.repository.module';
|
||||
import { DeviceNotificationRepository } from '../modules/device/repositories';
|
||||
import { DeviceStatusFirebaseModule } from '../firebase/devices-status/devices-status.module';
|
||||
import { CommunityPermissionService } from './services/community.permission.service';
|
||||
import { CommunityRepository } from '../modules/community/repositories';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [
|
||||
HelperHashService,
|
||||
SpacePermissionService,
|
||||
CommunityPermissionService,
|
||||
SpaceRepository,
|
||||
TuyaWebSocketService,
|
||||
OneSignalService,
|
||||
DeviceMessagesService,
|
||||
DeviceNotificationRepository,
|
||||
CommunityRepository,
|
||||
],
|
||||
exports: [
|
||||
HelperHashService,
|
||||
SpacePermissionService,
|
||||
CommunityPermissionService,
|
||||
],
|
||||
exports: [HelperHashService, SpacePermissionService],
|
||||
controllers: [],
|
||||
imports: [
|
||||
SpaceRepositoryModule,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityPermissionService {
|
||||
constructor(private readonly communityRepository: CommunityRepository) {}
|
||||
|
||||
async checkUserPermission(
|
||||
communityUuid: string,
|
||||
userUuid: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const communityData = await this.communityRepository.findOne({
|
||||
where: {
|
||||
uuid: communityUuid,
|
||||
users: {
|
||||
uuid: userUuid,
|
||||
},
|
||||
},
|
||||
relations: ['users'],
|
||||
});
|
||||
|
||||
if (!communityData) {
|
||||
throw new BadRequestException(
|
||||
'You do not have permission to access this community',
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new BadRequestException(err.message || 'Invalid UUID');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user