mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:54:53 +00:00
Merge pull request #141 from SyncrowIOT/feature/space-management
Feature/space management
This commit is contained in:
@ -457,6 +457,9 @@ export class SceneService {
|
||||
const space = await this.getSpaceByUuid(scene.spaceUuid);
|
||||
|
||||
await this.delete(scene.sceneTuyaUuid, space.spaceTuyaUuid);
|
||||
|
||||
await this.sceneRepository.remove(scene);
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Scene with ID ${sceneUuid} deleted successfully`,
|
||||
});
|
||||
|
||||
@ -41,7 +41,7 @@ export class UserSpaceService {
|
||||
userUuid: string,
|
||||
) {
|
||||
try {
|
||||
const space = await this.findUnitByInviteCode(params.inviteCode);
|
||||
const space = await this.findSpaceByInviteCode(params.inviteCode);
|
||||
|
||||
await this.addUserToSpace(userUuid, space.uuid);
|
||||
|
||||
@ -51,31 +51,43 @@ export class UserSpaceService {
|
||||
|
||||
await this.addUserPermissionsToDevices(userUuid, deviceUUIDs);
|
||||
} catch (err) {
|
||||
if (err instanceof HttpException) {
|
||||
throw err;
|
||||
} else {
|
||||
throw new HttpException(
|
||||
`An unexpected error occurred: ${err.message}`,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async findSpaceByInviteCode(
|
||||
inviteCode: string,
|
||||
): Promise<SpaceEntity> {
|
||||
try {
|
||||
const space = await this.spaceRepository.findOneOrFail({
|
||||
where: {
|
||||
invitationCode: inviteCode,
|
||||
},
|
||||
});
|
||||
return space;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Invalid invitation code',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
'Space with the provided invite code not found',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async findUnitByInviteCode(inviteCode: string): Promise<SpaceEntity> {
|
||||
const space = await this.spaceRepository.findOneOrFail({
|
||||
where: {
|
||||
invitationCode: inviteCode,
|
||||
},
|
||||
});
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
private async addUserToSpace(userUuid: string, spaceUuid: string) {
|
||||
const user = await this.addUserSpace({ userUuid, spaceUuid });
|
||||
try {
|
||||
const user = await this.addUserSpace({ userUuid, spaceUuid });
|
||||
|
||||
if (user.uuid) {
|
||||
return user;
|
||||
} else {
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Failed to add user to unit',
|
||||
`An error occurred while adding user to space ${spaceUuid} : ${error.message}}`,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
@ -113,7 +125,7 @@ export class UserSpaceService {
|
||||
): Promise<{ uuid: string }[]> {
|
||||
const devices = await this.spaceRepository.find({
|
||||
where: { uuid: unitUuid },
|
||||
relations: ['devicesSpaceEntity', 'devicesSpaceEntity.productDevice'],
|
||||
relations: ['devices', 'devices.productDevice'],
|
||||
});
|
||||
|
||||
const allDevices = devices.flatMap((space) => space.devices);
|
||||
|
||||
Reference in New Issue
Block a user