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 : []) }; } }