forked from Yara724/api
Fixed Lock for Field expert + user view of files
This commit is contained in:
@@ -59,6 +59,7 @@ import {
|
||||
} from "./dto/my-claims-v2.dto";
|
||||
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 { 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";
|
||||
@@ -4179,6 +4180,26 @@ export class ClaimRequestManagementService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
(!actor?.role || actor.role === RoleEnum.USER) &&
|
||||
claim.blameRequestId
|
||||
) {
|
||||
const blame = await this.blameRequestDbService.findById(
|
||||
claim.blameRequestId.toString(),
|
||||
);
|
||||
const isParty =
|
||||
Array.isArray(blame?.parties) &&
|
||||
blame.parties.some((p: any) =>
|
||||
partyPersonMatchesUser(p?.person, {
|
||||
sub: currentUserId,
|
||||
username: (actor as { username?: string })?.username,
|
||||
}),
|
||||
);
|
||||
if (isParty) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (actor?.role === RoleEnum.FIELD_EXPERT) {
|
||||
if (claim.initiatedByFieldExpertId?.toString() === currentUserId) {
|
||||
return;
|
||||
@@ -6603,8 +6624,25 @@ export class ClaimRequestManagementService {
|
||||
{ lean: true },
|
||||
);
|
||||
} else {
|
||||
const partyBlameIds = await this.blameRequestDbService
|
||||
.find(
|
||||
{
|
||||
$or: [
|
||||
{ "parties.person.userId": new Types.ObjectId(currentUserId) },
|
||||
],
|
||||
},
|
||||
{ select: "_id", lean: true },
|
||||
)
|
||||
.then((docs) => docs.map((d) => (d as any)._id));
|
||||
claims = await this.claimCaseDbService.find(
|
||||
{ "owner.userId": new Types.ObjectId(currentUserId) },
|
||||
{
|
||||
$or: [
|
||||
{ "owner.userId": new Types.ObjectId(currentUserId) },
|
||||
...(partyBlameIds.length
|
||||
? [{ blameRequestId: { $in: partyBlameIds } }]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{ lean: true },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user