forked from Yara724/api
Fixed GET users
This commit is contained in:
@@ -60,6 +60,11 @@ import {
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import { applyListQueryV2 } from "src/helpers/list-query-v2";
|
||||
import { partyPersonMatchesUser } from "src/helpers/iran-mobile";
|
||||
import {
|
||||
buildBlamePartyAccessOrConditions,
|
||||
mongoUserIdEqualityFilter,
|
||||
} from "src/helpers/party-access-queries";
|
||||
import { claimCaseInitiatedByFieldExpert } from "src/helpers/tenant-scope";
|
||||
import { ClaimDetailsV2ResponseDto } from "./dto/claim-details-v2.dto";
|
||||
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
|
||||
import { ClaimRequiredDocumentType } from "src/Types&Enums/claim-request-management/required-document-type.enum";
|
||||
@@ -4201,21 +4206,16 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
|
||||
if (actor?.role === RoleEnum.FIELD_EXPERT) {
|
||||
if (claim.initiatedByFieldExpertId?.toString() === currentUserId) {
|
||||
const blame = claim.blameRequestId
|
||||
? await this.blameRequestDbService.findById(
|
||||
claim.blameRequestId.toString(),
|
||||
)
|
||||
: null;
|
||||
if (
|
||||
claimCaseInitiatedByFieldExpert(claim, { sub: currentUserId }, blame)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (claim.blameRequestId) {
|
||||
const blame = await this.blameRequestDbService.findById(
|
||||
claim.blameRequestId.toString(),
|
||||
);
|
||||
if (
|
||||
blame?.expertInitiated &&
|
||||
blame.initiatedByFieldExpertId &&
|
||||
String(blame.initiatedByFieldExpertId) === currentUserId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (actor?.role === RoleEnum.REGISTRAR && claim.blameRequestId) {
|
||||
@@ -6580,25 +6580,24 @@ export class ClaimRequestManagementService {
|
||||
try {
|
||||
let claims: any[];
|
||||
if (actor?.role === RoleEnum.FIELD_EXPERT) {
|
||||
const expertOid = new Types.ObjectId(currentUserId);
|
||||
const expertBlameIds = await this.blameRequestDbService
|
||||
.find(
|
||||
{
|
||||
expertInitiated: true,
|
||||
initiatedByFieldExpertId: new Types.ObjectId(currentUserId),
|
||||
initiatedByFieldExpertId: expertOid,
|
||||
},
|
||||
{ select: "_id", lean: true },
|
||||
)
|
||||
.then((docs) => docs.map((d) => (d as any)._id));
|
||||
const claimOr: Record<string, unknown>[] = [
|
||||
{ initiatedByFieldExpertId: expertOid },
|
||||
];
|
||||
if (expertBlameIds.length > 0) {
|
||||
claimOr.push({ blameRequestId: { $in: expertBlameIds } });
|
||||
}
|
||||
claims = await this.claimCaseDbService.find(
|
||||
{
|
||||
$or: [
|
||||
{ "owner.userId": new Types.ObjectId(currentUserId) },
|
||||
...(expertBlameIds.length
|
||||
? [{ blameRequestId: { $in: expertBlameIds } }]
|
||||
: []),
|
||||
{ initiatedByFieldExpertId: new Types.ObjectId(currentUserId) },
|
||||
],
|
||||
},
|
||||
{ $or: claimOr },
|
||||
{ lean: true },
|
||||
);
|
||||
} else if (actor?.role === RoleEnum.REGISTRAR) {
|
||||
@@ -6624,27 +6623,38 @@ export class ClaimRequestManagementService {
|
||||
{ lean: true },
|
||||
);
|
||||
} else {
|
||||
const partyBlameOr = buildBlamePartyAccessOrConditions({
|
||||
sub: currentUserId,
|
||||
username: (actor as { username?: string })?.username,
|
||||
});
|
||||
const partyBlameIds = await this.blameRequestDbService
|
||||
.find(
|
||||
{
|
||||
$or: [
|
||||
{ "parties.person.userId": new Types.ObjectId(currentUserId) },
|
||||
],
|
||||
},
|
||||
partyBlameOr.length === 1
|
||||
? (partyBlameOr[0] as any)
|
||||
: ({ $or: partyBlameOr } as any),
|
||||
{ select: "_id", lean: true },
|
||||
)
|
||||
.then((docs) => docs.map((d) => (d as any)._id));
|
||||
claims = await this.claimCaseDbService.find(
|
||||
{
|
||||
$or: [
|
||||
{ "owner.userId": new Types.ObjectId(currentUserId) },
|
||||
...(partyBlameIds.length
|
||||
? [{ blameRequestId: { $in: partyBlameIds } }]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{ lean: true },
|
||||
|
||||
const ownerOr = mongoUserIdEqualityFilter(
|
||||
"owner.userId",
|
||||
currentUserId,
|
||||
);
|
||||
const claimOr: Record<string, unknown>[] = [];
|
||||
if (ownerOr) claimOr.push(ownerOr);
|
||||
if (partyBlameIds.length) {
|
||||
claimOr.push({ blameRequestId: { $in: partyBlameIds } });
|
||||
}
|
||||
|
||||
claims =
|
||||
claimOr.length === 0
|
||||
? []
|
||||
: await this.claimCaseDbService.find(
|
||||
claimOr.length === 1
|
||||
? (claimOr[0] as any)
|
||||
: ({ $or: claimOr } as any),
|
||||
{ lean: true },
|
||||
);
|
||||
}
|
||||
const list = (claims as any[]).map((c) => ({
|
||||
claimRequestId: c._id.toString(),
|
||||
|
||||
Reference in New Issue
Block a user