Every OEM code was a link → unmatched codes (the majority — fasteners, clips, body parts TecDoc doesn't carry) opened an empty "no equivalents" page. Now the schema page batch-checks its codes against the snapshot (POST /p/matched, one indexed query) and links ONLY the matched ones; unmatched codes render as plain text. Copy stays for all. No more dead-end empty pages from the parts panel. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
|
|
import { PSourceDbService } from "./p-source-db.service";
|
|
|
|
@Controller("p")
|
|
export class PController {
|
|
constructor(private readonly p: PSourceDbService) {}
|
|
|
|
/**
|
|
* Resolve an OEM code from the catalog to its P equivalents.
|
|
* `GET /p/oem?code=1J0973702` → { matched, articles, aftermarketParts,
|
|
* oeCrossReferences }. Always 200 with `matched: false` on any miss.
|
|
*/
|
|
@Get("oem")
|
|
async oem(@Query("code") code: string) {
|
|
return this.p.lookupByOem(code ?? "");
|
|
}
|
|
|
|
/**
|
|
* Batch: which of these OEM codes have a P cross-reference. The schema page
|
|
* sends the codes it's about to render and links only the returned ones, so
|
|
* unmatched codes stay plain text and never open an empty detail page.
|
|
* `POST /p/matched { codes: [...] }` → { matched: [...] }.
|
|
*/
|
|
@Post("matched")
|
|
async matched(@Body("codes") codes: string[]) {
|
|
return { matched: await this.p.matchedCodes(Array.isArray(codes) ? codes : []) };
|
|
}
|
|
}
|