forked from Yara724/api
automatiacally previous stages submitted
This commit is contained in:
@@ -98,7 +98,13 @@ export class FanavaranHullReadController {
|
||||
|
||||
private clientKey(client: string) {
|
||||
if (!isFanavaranClientKey(client))
|
||||
throw new BadRequestException("Invalid Fanavaran client");
|
||||
throw new BadRequestException({
|
||||
statusCode: 400,
|
||||
code: "FANAVARAN_CLIENT_INVALID",
|
||||
field: "client",
|
||||
allowedClients: FANAVARAN_CLIENT_SWAGGER_ENUM,
|
||||
message: "شرکت بیمه انتخابشده برای سرویس فناوران معتبر نیست.",
|
||||
});
|
||||
return normalizeFanavaranClientKey(client);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ForbiddenException } from "@nestjs/common";
|
||||
import { of, throwError } from "rxjs";
|
||||
import { FanavaranHullReadService } from "./fanavaran-hull-read.service";
|
||||
import { ClaimRequestManagementService } from "src/claim-request-management/claim-request-management.service";
|
||||
import { localizeErrorPayload } from "src/common/errors/persian-errors";
|
||||
|
||||
const actor = { sub: "staff-1", role: "damage_expert", clientKey: "tenant-1" };
|
||||
const localId = "6af4594a32d485128a55742d";
|
||||
@@ -108,7 +109,11 @@ describe("Fanavaran hull retrieval", () => {
|
||||
});
|
||||
await expect(
|
||||
service.damageSections("parsian", localId, actor),
|
||||
).rejects.toThrow("expertiseId");
|
||||
).rejects.toMatchObject({
|
||||
response: expect.objectContaining({
|
||||
code: "FANAVARAN_HULL_EXPERTISE_ID_MISSING",
|
||||
}),
|
||||
});
|
||||
expect(http.get).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -166,15 +171,13 @@ describe("hull read context", () => {
|
||||
ClaimRequestManagementService.prototype,
|
||||
) as any;
|
||||
service.claimCaseDbService = {
|
||||
findById: jest
|
||||
.fn()
|
||||
.mockResolvedValue({
|
||||
claimId: 5190845,
|
||||
claimNo: 123,
|
||||
expertiseId: 44237,
|
||||
owner: { clientId: "tenant-1" },
|
||||
...claim,
|
||||
}),
|
||||
findById: jest.fn().mockResolvedValue({
|
||||
claimId: 5190845,
|
||||
claimNo: 123,
|
||||
expertiseId: 44237,
|
||||
owner: { clientId: "tenant-1" },
|
||||
...claim,
|
||||
}),
|
||||
};
|
||||
service.resolveFanavaranClaimProduct = jest
|
||||
.fn()
|
||||
@@ -195,6 +198,27 @@ describe("hull read context", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the local/external claim ID distinction visible after the global error filter", async () => {
|
||||
const service = context();
|
||||
let error: any;
|
||||
try {
|
||||
await service.getFanavaranHullReadContext("5190845", "parsian", actor);
|
||||
} catch (caught) {
|
||||
error = caught;
|
||||
}
|
||||
expect(error).toBeDefined();
|
||||
const response = localizeErrorPayload(
|
||||
error.getResponse(),
|
||||
error.getStatus(),
|
||||
);
|
||||
expect(response).toMatchObject({
|
||||
code: "FANAVARAN_LOCAL_CLAIM_ID_INVALID",
|
||||
field: "claimCaseId",
|
||||
});
|
||||
expect(response.message).toContain("شناسه داخلی");
|
||||
expect(service.claimCaseDbService.findById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects another organization's claim before retrieving credentials", async () => {
|
||||
const service = context({ owner: { clientId: "other-tenant" } });
|
||||
await expect(
|
||||
@@ -206,9 +230,27 @@ describe("hull read context", () => {
|
||||
it("rejects third-party claims and claims that only have a claimNo", async () => {
|
||||
const service = context();
|
||||
service.resolveFanavaranClaimProduct.mockResolvedValue("third-party");
|
||||
let wrongProduct: any;
|
||||
try {
|
||||
await service.getFanavaranHullReadContext(localId, "parsian", actor);
|
||||
} catch (error) {
|
||||
wrongProduct = error;
|
||||
}
|
||||
const localized = localizeErrorPayload(wrongProduct.getResponse(), 400);
|
||||
expect(localized).toMatchObject({
|
||||
code: "FANAVARAN_HULL_CLAIM_REQUIRED",
|
||||
actualProduct: "third-party",
|
||||
expectedProduct: "car-body",
|
||||
});
|
||||
expect(localized.message).toContain("شخص ثالث");
|
||||
await expect(
|
||||
service.getFanavaranHullReadContext(localId, "parsian", actor),
|
||||
).rejects.toThrow("vehicle-hull");
|
||||
).rejects.toMatchObject({
|
||||
response: expect.objectContaining({
|
||||
code: "FANAVARAN_HULL_CLAIM_REQUIRED",
|
||||
actualProduct: "third-party",
|
||||
}),
|
||||
});
|
||||
service.resolveFanavaranClaimProduct.mockResolvedValue("car-body");
|
||||
service.claimCaseDbService.findById.mockResolvedValue({
|
||||
claimNo: 123,
|
||||
@@ -216,6 +258,10 @@ describe("hull read context", () => {
|
||||
});
|
||||
await expect(
|
||||
service.getFanavaranHullReadContext(localId, "parsian", actor),
|
||||
).rejects.toThrow("claimId");
|
||||
).rejects.toMatchObject({
|
||||
response: expect.objectContaining({
|
||||
code: "FANAVARAN_HULL_CLAIM_NOT_SUBMITTED",
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,9 +85,13 @@ export class FanavaranHullReadService {
|
||||
);
|
||||
const id = selectedId ?? context.expertiseId;
|
||||
if (id == null)
|
||||
throw new BadRequestException(
|
||||
"No submitted expertiseId is stored; provide expertiseId for a previously submitted expertise",
|
||||
);
|
||||
throw new BadRequestException({
|
||||
statusCode: 400,
|
||||
code: "FANAVARAN_HULL_EXPERTISE_ID_MISSING",
|
||||
field: "expertiseId",
|
||||
message:
|
||||
"کد کارشناسی فناوران در این پرونده ثبت نشده است؛ کد کارشناسی قبلی را در پارامتر مربوط وارد کنید یا ابتدا کارشناسی را ارسال کنید.",
|
||||
});
|
||||
const url = `${getFanavaranLookupBaseUrl(clientKey)}/car/vehicle-hull-claims/${context.claimId}/expertise/${id}/dmg-sections`;
|
||||
return {
|
||||
clientKey,
|
||||
@@ -101,7 +105,18 @@ export class FanavaranHullReadService {
|
||||
private positiveId(value: string, field: string): number {
|
||||
const id = Number(value);
|
||||
if (!/^\d+$/.test(value) || !Number.isSafeInteger(id) || id <= 0) {
|
||||
throw new BadRequestException(`${field} must be a positive integer`);
|
||||
throw new BadRequestException({
|
||||
statusCode: 400,
|
||||
code:
|
||||
field === "fileId"
|
||||
? "FANAVARAN_HULL_FILE_ID_INVALID"
|
||||
: "FANAVARAN_HULL_EXPERTISE_ID_INVALID",
|
||||
field,
|
||||
message:
|
||||
field === "fileId"
|
||||
? "کد فایل فناوران باید یک عدد صحیح مثبت باشد."
|
||||
: "کد کارشناسی فناوران باید یک عدد صحیح مثبت باشد.",
|
||||
});
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ export class FanavaranController {
|
||||
@ApiOperation({
|
||||
summary: "Submit Fanavaran expertise request",
|
||||
description:
|
||||
"Swagger JSON body is optional. Always rebuilds GEN.08 from the local expert reply and lookups, then POSTs that rebuilt payload. Pasting a previous preview JSON does not skip rebuild. Only money/date fields are taken from the body. DmgCaseId, ClaimExpertId, and DmgSections in pasted JSON are ignored.",
|
||||
"Completes missing prerequisite stages in order before expertise: base claim, third-party damage case when applicable, then all pending attachments. Skipped images are retried; any image without a saved Fanavaran file ID blocks expertise with stage and pendingFiles details. Existing IDs/receipts are reused; existing expertise is not duplicated. Optional JSON overrides only allowed money/date fields; the GEN.08 third-party or GEN.06 hull payload is rebuilt from the expert reply and live lookups.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "client",
|
||||
|
||||
Reference in New Issue
Block a user