mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:54:55 +00:00
Simplify user space retrieval in ProjectUserService
This commit is contained in:
@ -3,7 +3,6 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
import { InviteUserRepository } from '@app/common/modules/Invite-user/repositiories';
|
import { InviteUserRepository } from '@app/common/modules/Invite-user/repositiories';
|
||||||
import { ProjectService } from './project.service';
|
import { ProjectService } from './project.service';
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -74,7 +73,6 @@ export class ProjectUserService {
|
|||||||
invitedUserUuid: string,
|
invitedUserUuid: string,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
try {
|
try {
|
||||||
let userSpaces;
|
|
||||||
const user = await this.inviteUserRepository.findOne({
|
const user = await this.inviteUserRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
project: { uuid: projectUuid },
|
project: { uuid: projectUuid },
|
||||||
@ -102,15 +100,7 @@ export class ProjectUserService {
|
|||||||
HttpStatus.NOT_FOUND,
|
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 createdAt = new Date(user.createdAt);
|
||||||
const createdDate = createdAt.toLocaleDateString();
|
const createdDate = createdAt.toLocaleDateString();
|
||||||
const createdTime = createdAt.toLocaleTimeString();
|
const createdTime = createdAt.toLocaleTimeString();
|
||||||
@ -121,7 +111,7 @@ export class ProjectUserService {
|
|||||||
roleType: user.roleType.type,
|
roleType: user.roleType.type,
|
||||||
createdDate,
|
createdDate,
|
||||||
createdTime,
|
createdTime,
|
||||||
spaces: userSpaces,
|
spaces: user.spaces.map((space) => space.space),
|
||||||
},
|
},
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user