Added all community endpoints

This commit is contained in:
hannathkadher
2024-10-17 10:55:26 +04:00
parent b8d4a080ef
commit d6777c8ec1
17 changed files with 333 additions and 126 deletions

View File

@ -10,7 +10,7 @@ export class ControllerRoute {
};
static COMMUNITY = class {
public static readonly ROUTE = 'communities';
public static readonly ROUTE = 'community';
static ACTIONS = class {
public static readonly GET_COMMUNITY_BY_ID_SUMMARY =
'Get community by community id';
@ -39,8 +39,8 @@ export class ControllerRoute {
};
};
static COMMUNITYSPACE = class {
public static readonly ROUTE = 'communities/:id/spaces';
static COMMUNITY_SPACE = class {
public static readonly ROUTE = 'community/:id/spaces';
static ACTIONS = class {
public static readonly GET_COMMUNITY_SPACES_HIERARCHY_SUMMARY =
'Fetch hierarchical structure of spaces within a community.';
@ -49,4 +49,24 @@ export class ControllerRoute {
'retrieves all the spaces associated with a given community, organized into a hierarchical structure.';
};
};
static USER_COMMUNITY = class {
public static readonly ROUTE = '/user/:userUuid/communities';
static ACTIONS = class {
public static readonly GET_USER_COMMUNITIES_SUMMARY =
'Get communities associated with a user by user UUID';
public static readonly GET_USER_COMMUNITIES_DESCRIPTION =
'This endpoint returns the list of communities a specific user is associated with';
public static readonly ASSOCIATE_USER_COMMUNITY_SUMMARY =
'Associate a user with a community';
public static readonly ASSOCIATE_USER_COMMUNITY_DESCRIPTION =
'This endpoint associates a user with a community.';
public static readonly DISASSOCIATE_USER_COMMUNITY_SUMMARY =
'Disassociate a user from a community';
public static readonly DISASSOCIATE_USER_COMMUNITY_DESCRIPTION =
'This endpoint disassociates a user from a community. It removes the relationship between the specified user and the community. If the user is not associated with the community, an error will be returned.';
};
};
}

View File

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

View File

@ -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');
}
}
}