mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 10:46:17 +00:00
Update user spaces retrieval based on user status
This commit is contained in:
@ -3,12 +3,15 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { InviteUserRepository } from '@app/common/modules/Invite-user/repositiories';
|
||||
import { ProjectService } from './project.service';
|
||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
|
||||
@Injectable()
|
||||
export class ProjectUserService {
|
||||
constructor(
|
||||
private readonly inviteUserRepository: InviteUserRepository,
|
||||
private readonly projectService: ProjectService,
|
||||
private readonly userSpaceRepository: UserSpaceRepository,
|
||||
) {}
|
||||
|
||||
async getUsersByProject(uuid: string): Promise<BaseResponseDto> {
|
||||
@ -70,6 +73,7 @@ export class ProjectUserService {
|
||||
invitedUserUuid: string,
|
||||
): Promise<BaseResponseDto> {
|
||||
try {
|
||||
let userSpaces;
|
||||
const user = await this.inviteUserRepository.findOne({
|
||||
where: {
|
||||
project: { uuid: projectUuid },
|
||||
@ -96,6 +100,15 @@ export class ProjectUserService {
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
if (user.status === UserStatusEnum.ACTIVE) {
|
||||
const spaces = await this.userSpaceRepository.find({
|
||||
where: { user: { inviteUser: { uuid: invitedUserUuid } } },
|
||||
relations: ['space'],
|
||||
});
|
||||
userSpaces = spaces.map((space) => space.space);
|
||||
} else {
|
||||
userSpaces = user.spaces.map((space) => space.space);
|
||||
}
|
||||
const createdAt = new Date(user.createdAt);
|
||||
const createdDate = createdAt.toLocaleDateString();
|
||||
const createdTime = createdAt.toLocaleTimeString();
|
||||
@ -106,7 +119,7 @@ export class ProjectUserService {
|
||||
roleType: user.roleType.type,
|
||||
createdDate,
|
||||
createdTime,
|
||||
spaces: user.spaces.map((space) => space.space),
|
||||
spaces: userSpaces,
|
||||
},
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
|
Reference in New Issue
Block a user