forked from Yara724/api
Fixed GET users
This commit is contained in:
@@ -339,6 +339,28 @@ export class ExpertClaimService {
|
||||
return ev;
|
||||
}
|
||||
|
||||
/** Load linked blame when resolving field-expert ownership on a claim. */
|
||||
private async loadBlameForClaim(
|
||||
claim: { blameRequestId?: unknown } | null | undefined,
|
||||
) {
|
||||
const id = claim?.blameRequestId?.toString?.();
|
||||
if (!id) return null;
|
||||
return this.blameRequestDbService.findById(id);
|
||||
}
|
||||
|
||||
private async assertExpertActorOnClaim(claim: any, actor: any): Promise<void> {
|
||||
const blame = await this.loadBlameForClaim(claim);
|
||||
assertClaimCaseForExpertActor(claim, actor, blame);
|
||||
}
|
||||
|
||||
private async fieldExpertOwnsClaim(
|
||||
claim: any,
|
||||
actor: { sub: string },
|
||||
): Promise<boolean> {
|
||||
const blame = await this.loadBlameForClaim(claim);
|
||||
return claimCaseInitiatedByFieldExpert(claim, actor, blame);
|
||||
}
|
||||
|
||||
/** Load immutable profile fields from `damage-expert` for the acting expert. */
|
||||
private async snapshotDamageExpert(actorId: string) {
|
||||
const doc = await this.damageExpertDbService.findById(actorId);
|
||||
@@ -2151,7 +2173,7 @@ export class ExpertClaimService {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
|
||||
const factorValidationSnapshot = await this.snapshotDamageExpert(actor.sub);
|
||||
|
||||
@@ -2402,11 +2424,11 @@ export class ExpertClaimService {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
|
||||
const isFieldExpertOwner =
|
||||
(actor as any).role === RoleEnum.FIELD_EXPERT &&
|
||||
claimCaseInitiatedByFieldExpert(claim, actor);
|
||||
(await this.fieldExpertOwnsClaim(claim, actor));
|
||||
const isFactorValidationLock =
|
||||
claimIsAwaitingExpertFactorValidationV2(claim);
|
||||
const isDamageReviewLock =
|
||||
@@ -2745,7 +2767,7 @@ export class ExpertClaimService {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
|
||||
if (claim.status !== ClaimCaseStatus.EXPERT_REVIEWING) {
|
||||
throw new BadRequestException(
|
||||
@@ -2910,7 +2932,7 @@ export class ExpertClaimService {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
|
||||
if (claim.status !== ClaimCaseStatus.EXPERT_REVIEWING) {
|
||||
throw new BadRequestException(
|
||||
@@ -3579,8 +3601,23 @@ export class ExpertClaimService {
|
||||
actor: any,
|
||||
query: ListQueryV2Dto = {},
|
||||
): Promise<GetClaimListV2ResponseDto> {
|
||||
const expertOid = new Types.ObjectId(actor.sub);
|
||||
const expertBlameIds = await this.blameRequestDbService
|
||||
.find(
|
||||
{ expertInitiated: true, initiatedByFieldExpertId: expertOid },
|
||||
{ select: "_id", lean: true },
|
||||
)
|
||||
.then((docs) => docs.map((d) => (d as { _id: unknown })._id));
|
||||
|
||||
const claimOr: Record<string, unknown>[] = [
|
||||
{ initiatedByFieldExpertId: expertOid },
|
||||
];
|
||||
if (expertBlameIds.length > 0) {
|
||||
claimOr.push({ blameRequestId: { $in: expertBlameIds } });
|
||||
}
|
||||
|
||||
const claims = (await this.claimCaseDbService.find({
|
||||
initiatedByFieldExpertId: new Types.ObjectId(actor.sub),
|
||||
$or: claimOr,
|
||||
})) as any[];
|
||||
|
||||
const blameIds = [
|
||||
@@ -4008,7 +4045,8 @@ export class ExpertClaimService {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
const linkedBlame = await this.loadBlameForClaim(claim);
|
||||
assertClaimCaseForExpertActor(claim, actor, linkedBlame);
|
||||
|
||||
// Variables used both in the gate block and in the detail-build section below
|
||||
const isDamageExpertPhase =
|
||||
@@ -4019,7 +4057,7 @@ export class ExpertClaimService {
|
||||
|
||||
// Field experts can always view their own initiated claims regardless of status
|
||||
if (actor.role === RoleEnum.FIELD_EXPERT) {
|
||||
if (!claimCaseInitiatedByFieldExpert(claim, actor)) {
|
||||
if (!claimCaseInitiatedByFieldExpert(claim, actor, linkedBlame)) {
|
||||
throw new ForbiddenException("This claim was not initiated by you.");
|
||||
}
|
||||
// Fall through to the detail build below (skip the damage-expert gate)
|
||||
@@ -4317,7 +4355,7 @@ export class ExpertClaimService {
|
||||
/** V2 price-drop: claim locked by this expert during damage assessment. */
|
||||
private assertExpertCanEditClaimDuringReviewV2(claim: any, actor: any): void {
|
||||
if (actor.role !== RoleEnum.FIELD_EXPERT) requireActorClientKey(actor);
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
if (claim.status !== ClaimCaseStatus.EXPERT_REVIEWING) {
|
||||
throw new BadRequestException(
|
||||
`Claim must be EXPERT_REVIEWING to edit price drop. Current status: ${claim.status}`,
|
||||
@@ -4551,7 +4589,7 @@ export class ExpertClaimService {
|
||||
if (!claim) {
|
||||
throw new NotFoundException("Claim request not found");
|
||||
}
|
||||
assertClaimCaseForExpertActor(claim, actor);
|
||||
await this.assertExpertActorOnClaim(claim, actor);
|
||||
if (claim.status !== ClaimCaseStatus.EXPERT_REVIEWING) {
|
||||
throw new BadRequestException(
|
||||
`Claim is not in EXPERT_REVIEWING state. Current status: ${claim.status}`,
|
||||
|
||||
Reference in New Issue
Block a user