mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 18:44:54 +00:00
Add functionality to add user to a unit
This commit is contained in:
@ -7,7 +7,7 @@ import {
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { AddUnitDto } from '../dtos';
|
||||
import { AddUnitDto, AddUserUnitDto } from '../dtos';
|
||||
import {
|
||||
UnitChildInterface,
|
||||
UnitParentInterface,
|
||||
@ -228,6 +228,26 @@ export class UnitService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async addUserUnit(addUserUnitDto: AddUserUnitDto) {
|
||||
try {
|
||||
await this.userSpaceRepository.save({
|
||||
user: { uuid: addUserUnitDto.userUuid },
|
||||
space: { uuid: addUserUnitDto.unitUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
throw new HttpException(
|
||||
'User already belongs to this unit',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
throw new HttpException(
|
||||
err.message || 'Internal Server Error',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async renameUnitByUuid(
|
||||
unitUuid: string,
|
||||
updateUnitNameDto: UpdateUnitNameDto,
|
||||
|
||||
Reference in New Issue
Block a user