fix(ancpi): ePay county IDs = WORKSPACE_IDs, UAT IDs = SIRUTA codes
Zero discovery calls needed! ePay internal county IDs are identical to eTerra WORKSPACE_IDs (CLUJ=127, ALBA=10, etc.) and ePay UAT IDs are SIRUTA codes (Cluj-Napoca=54975, Florești=57706). Queue now uses workspacePk + siruta directly from GisUat DB. Flow: AddToCart → saveMetadata → EditCartSubmit → Poll+Download. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -175,42 +175,39 @@ async function processItem(item: QueueItem): Promise<void> {
|
||||
const basketRowId = await client.addToCart(input.prodId ?? 14200);
|
||||
await updateStatus(extractId, "cart", { basketRowId });
|
||||
|
||||
// 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
|
||||
// Step 3: Save metadata + submit order
|
||||
// ePay internal county IDs = eTerra WORKSPACE_IDs
|
||||
// ePay UAT IDs = SIRUTA codes
|
||||
// So we can skip all discovery calls!
|
||||
await updateStatus(extractId, "ordering");
|
||||
|
||||
// Resolve county ID (workspacePk) and UAT ID (siruta) from our DB
|
||||
let countyInternalId = input.judetIndex; // might already be workspacePk
|
||||
let uatInternalId = input.uatId; // might already be SIRUTA
|
||||
let countyName = input.judetName;
|
||||
let uatName = input.uatName;
|
||||
|
||||
// If siruta is provided, look up workspacePk from GisUat
|
||||
if (input.siruta) {
|
||||
const uat = await prisma.gisUat.findUnique({
|
||||
where: { siruta: input.siruta },
|
||||
select: { workspacePk: true, county: true, name: true },
|
||||
});
|
||||
if (uat?.workspacePk) {
|
||||
countyInternalId = uat.workspacePk;
|
||||
uatInternalId = Number(input.siruta);
|
||||
if (uat.county) countyName = uat.county;
|
||||
if (uat.name) uatName = uat.name;
|
||||
}
|
||||
}
|
||||
|
||||
const nrCF = input.nrCF ?? input.nrCadastral;
|
||||
const saved = await client.saveMetadata(
|
||||
basketRowId,
|
||||
countyMatch.id,
|
||||
countyMatch.value,
|
||||
uatMatch.id,
|
||||
uatMatch.value,
|
||||
countyInternalId,
|
||||
countyName,
|
||||
uatInternalId,
|
||||
uatName,
|
||||
nrCF,
|
||||
input.nrCadastral,
|
||||
process.env.ANCPI_DEFAULT_SOLICITANT_ID || "14452",
|
||||
|
||||
Reference in New Issue
Block a user