fix(ancpi): complete rewrite based on Angular source code analysis

All endpoints and payloads verified against epaymentAngularApp.js:
- EpayJsonInterceptor: form-urlencoded (not JSON), uses reqType param
- County IDs: internal ANCPI IDs from judeteNom (NOT 0-41 indices)
- UAT lookup: reqType=nomenclatorUAT&countyId=<internal_ID>
- Save metadata: reqType=saveProductMetadataForBasketItem (multipart)
  with productMetadataJSON using stringValues[] arrays
- SearchEstate: field names are identificator/judet/uat (not identifier/countyId/uatId)
- Download PDF: Content-Type: application/pdf in request header
- Queue resolves county+UAT IDs dynamically via getCountyList+getUatList

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-23 02:01:39 +02:00
parent eb8cd18210
commit e13a9351be
3 changed files with 490 additions and 629 deletions
File diff suppressed because it is too large Load Diff
+44 -10
View File
@@ -175,20 +175,54 @@ async function processItem(item: QueueItem): Promise<void> {
const basketRowId = await client.addToCart(input.prodId ?? 14200);
await updateStatus(extractId, "cart", { basketRowId });
// Step 3: Configure + submit order
// Skip SearchEstate — we already have the data from eTerra.
// configureCartItem (via EditCartItemJson) + submitOrder (via EditCartSubmit)
// Step 3: Resolve internal county + UAT IDs
await updateStatus(extractId, "searching");
const counties = await client.getCountyList();
const normalize = (s: string) =>
s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase().trim();
const countyMatch = counties.find(
(c) => normalize(c.value) === normalize(input.judetName),
);
if (!countyMatch) {
await updateStatus(extractId, "failed", {
errorMessage: `Județul "${input.judetName}" nu a fost găsit în ePay. Disponibile: ${counties.slice(0, 5).map((c) => c.value).join(", ")}...`,
});
return;
}
const uats = await client.getUatList(countyMatch.id);
const uatMatch = uats.find(
(u) => normalize(u.value) === normalize(input.uatName),
);
if (!uatMatch) {
await updateStatus(extractId, "failed", {
errorMessage: `UAT "${input.uatName}" nu a fost găsit în ePay pentru ${input.judetName}.`,
});
return;
}
// Step 4: Save metadata + submit order
await updateStatus(extractId, "ordering");
const nrCF = input.nrCF ?? input.nrCadastral;
const orderId = await client.submitOrder({
const saved = await client.saveMetadata(
basketRowId,
judetIndex: input.judetIndex,
uatId: input.uatId,
countyMatch.id,
countyMatch.value,
uatMatch.id,
uatMatch.value,
nrCF,
nrCadastral: input.nrCadastral,
solicitantId:
process.env.ANCPI_DEFAULT_SOLICITANT_ID || "14452",
});
input.nrCadastral,
process.env.ANCPI_DEFAULT_SOLICITANT_ID || "14452",
);
if (!saved) {
await updateStatus(extractId, "failed", {
errorMessage: "Salvarea metadatelor în ePay a eșuat.",
});
return;
}
const orderId = await client.submitOrder();
await updateStatus(extractId, "polling", { orderId });