forked from Yara724/api
fix(api contract): trimmed user blame/claim lists and queues and removing unused data
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
export type BlameUserNextAction =
|
||||
| "SIGN"
|
||||
| "WAIT_FOR_OTHER_SIGNATURE"
|
||||
| "CREATE_CLAIM"
|
||||
| "CONTINUE_CLAIM"
|
||||
| "VIEW_RESULT"
|
||||
| null;
|
||||
|
||||
/** Viewer-specific guidance, without exposing the other party's private data. */
|
||||
export function resolveBlameUserNextAction(
|
||||
status: string,
|
||||
party: { confirmation?: { accepted?: boolean } } | undefined,
|
||||
claimCreation: { hasClaim: boolean; shouldGuideToCreateClaim: boolean },
|
||||
): BlameUserNextAction {
|
||||
if (!party) return null;
|
||||
if (status === "WAITING_FOR_SIGNATURES") {
|
||||
return party.confirmation?.accepted === true
|
||||
? "WAIT_FOR_OTHER_SIGNATURE"
|
||||
: "SIGN";
|
||||
}
|
||||
if (status === "COMPLETED") {
|
||||
if (claimCreation.shouldGuideToCreateClaim) return "CREATE_CLAIM";
|
||||
if (claimCreation.hasClaim) return "CONTINUE_CLAIM";
|
||||
return "VIEW_RESULT";
|
||||
}
|
||||
if (status === "STOPPED") return "VIEW_RESULT";
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { toPublicListItems } from "./public-list-response";
|
||||
import { applyListQueryV2 } from "./list-query-v2";
|
||||
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
|
||||
import { ExpertClaimService } from "src/expert-claim/expert-claim.service";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
|
||||
describe("public list payloads", () => {
|
||||
it("filters full party snapshots before removing them, and preserves locks/workflow fields", () => {
|
||||
const row = {
|
||||
publicId: "A100",
|
||||
status: "EXPERT_REVIEWING",
|
||||
createdAt: "2026-10-03",
|
||||
claimRequestId: "claim-id",
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
partyIdentities: [
|
||||
{
|
||||
person: { nationalCode: "1234567890" },
|
||||
evidence: { secret: "large snapshot" },
|
||||
},
|
||||
],
|
||||
};
|
||||
const paged = applyListQueryV2(
|
||||
[row],
|
||||
{
|
||||
publicId: (r) => r.publicId,
|
||||
createdAt: (r) => r.createdAt,
|
||||
status: (r) => r.status,
|
||||
},
|
||||
{ nationalCode: "۱۲۳۴۵۶۷۸۹۰" },
|
||||
);
|
||||
const result = toPublicListItems(paged.list);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
});
|
||||
expect(result[0]).not.toHaveProperty("partyIdentities");
|
||||
expect(row.partyIdentities).toHaveLength(1);
|
||||
expect(toPublicListItems([])).toEqual([]);
|
||||
});
|
||||
|
||||
it("removes identity snapshots at the actual user and expert list response boundaries", async () => {
|
||||
const userService = Object.create(
|
||||
ClaimRequestManagementService.prototype,
|
||||
) as any;
|
||||
userService.blameRequestDbService = {
|
||||
find: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
userService.claimCaseDbService = {
|
||||
find: jest.fn().mockResolvedValue([
|
||||
{
|
||||
_id: "claim-id",
|
||||
publicId: "A100",
|
||||
status: "WAITING_FOR_DAMAGE_EXPERT",
|
||||
createdAt: "2026-10-03",
|
||||
workflow: { currentStep: "EXPERT_COST_EVALUATION" },
|
||||
snapshot: {
|
||||
parties: [
|
||||
{
|
||||
person: { nationalCode: "1234567890" },
|
||||
inquiries: { huge: "raw provider data" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]),
|
||||
};
|
||||
const userResult = await userService.getMyClaimsV2(
|
||||
"650000000000000000000001",
|
||||
{ role: RoleEnum.FIELD_EXPERT },
|
||||
{ nationalCode: "1234567890" },
|
||||
);
|
||||
expect(userResult.total).toBe(1);
|
||||
expect(userResult.list[0]).not.toHaveProperty("partyIdentities");
|
||||
const expertService = Object.create(ExpertClaimService.prototype) as any;
|
||||
const expertResult = expertService.paginateClaimListV2(
|
||||
[
|
||||
{
|
||||
claimRequestId: "claim-id",
|
||||
publicId: "A100",
|
||||
status: "WAITING_FOR_DAMAGE_EXPERT",
|
||||
currentStep: "EXPERT_COST_EVALUATION",
|
||||
locked: true,
|
||||
lockedBy: { actorId: "expert-id" },
|
||||
partyIdentities: [{ person: { nationalCode: "1234567890" } }],
|
||||
},
|
||||
],
|
||||
{ nationalCode: "1234567890" },
|
||||
);
|
||||
expect(expertResult.total).toBe(1);
|
||||
expect(expertResult.list[0]).not.toHaveProperty("partyIdentities");
|
||||
expect(expertResult.list[0].lockedBy).toEqual({ actorId: "expert-id" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
/** Identity lookup material is used by list filters, never by list renderers. */
|
||||
export function toPublicListItems<T extends object>(rows: T[]): T[] {
|
||||
return rows.map((row) => {
|
||||
const { partyIdentities: _searchOnly, ...publicRow } = row as T & {
|
||||
partyIdentities?: unknown;
|
||||
};
|
||||
return publicRow as T;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user