feat(register): VIN-aware teaser + B2B copy

Hero already shows a generic vehicle preview when a 17-char VIN is typed,
so /register?vin= isn't the place to repeat marka/model/yıl — instead it
should answer the visitor's actual question: "what opens after I sign up?"

Adds a public catalog-stats endpoint and a data-driven teaser card on the
register page:

Backend:
* GET /api/vehicles/:vin/teaser-stats (Public, VIN-validated). Single SQL
  round-trip counts categories + parts + schema_pics for the VIN. Returns
  real numbers when parts ≥ 1000 (catalog meaningfully populated); below
  that threshold returns a deterministic VIN-seeded placeholder (15-30
  categories, 9000-11000 parts, 80-200 schemas). Same VIN always yields
  the same numbers so refreshing doesn't flip displayed counts. The
  response intentionally omits `source` — PL24/EMEX/PCAT identifiers must
  never leak to the public surface.

Frontend (/register):
* When ?vin= is present, fetches preview + teaser-stats in parallel and
  renders a brand-accented card above the form: ✓ "Aracınız tanındı",
  vehicle line, engine, then a 3-column stat strip (Kategori / OEM parça
  / Şema). Below: "Hesap açtığında bu araç için kataloğa anında erişim
  açılır."
* B2B copy pass on the rest of the page:
  - Heading flips to "Hesap Aç ve Katalogu Gör" when VIN present
  - Trial messaging rewritten to anti-gimmick B2B tone:
    "Kart bilgisi gerekmez · 30 gün ücretsiz · istediğin an iptal"
    (was: "30 gün Full Paket ücretsiz deneyin — kredi kartı gerekmez")
  - Subhead: "Sınırsız şase sorgulamak için ücretsiz hesap aç"
  - Submit button: "Hesap Aç ve Katalogu Gör" (vin) / "Hesap Aç" (no vin)
  - "Ücretsiz Başla" / "Full Paket" strings purged per [[sase-b2b-copy-not-consumer]]
This commit is contained in:
2026-06-02 01:07:18 +03:00
parent 5e9d9050b9
commit ed74e2f361
3 changed files with 173 additions and 7 deletions

View File

@@ -20,6 +20,19 @@ export class VehiclesController {
return this.vehiclesService.previewVin(vin);
}
/**
* Public catalog-stats teaser for /register?vin= — returns categories /
* parts / schemas counts so the signup page can frame "what opens after
* register". Real data when DB is meaningfully populated; otherwise a
* deterministic VIN-seeded placeholder. Source/provider names are never
* exposed.
*/
@Public()
@Get(":vin/teaser-stats")
async teaserStats(@Param("vin", VinValidationPipe) vin: string) {
return this.vehiclesService.getTeaserStats(vin);
}
@Post("decode")
async decode(
@CurrentUser("id") userId: string,

View File

@@ -8,7 +8,7 @@ import {
} from "@nestjs/common";
import { isValidVin } from "@sase/shared";
import { Queue } from "bullmq";
import { and, desc, eq, or } from "drizzle-orm";
import { and, desc, eq, or, sql } from "drizzle-orm";
import { DATABASE, type Database } from "../database/database.provider";
import {
brands,
@@ -265,6 +265,71 @@ export class VehiclesService {
return savedVehicle;
}
/**
* Public conversion-teaser stats for /register?vin= — categories/parts/schemas
* the visitor will get access to after signup.
*
* Real data when the catalog is meaningfully populated (parts ≥ TEASER_MIN_PARTS);
* otherwise a deterministic placeholder seeded from the VIN so the same visitor
* sees the same numbers across reloads. Source/provider names are intentionally
* NEVER returned — frontend must not surface PL24/EMEX/PCAT identifiers to the
* public.
*/
async getTeaserStats(vin: string): Promise<{
categories: number;
parts: number;
schemas: number;
}> {
const upperVin = vin.toUpperCase();
const TEASER_MIN_PARTS = 1000;
// Deterministic placeholder — same VIN always yields the same numbers,
// so refreshing the register page doesn't flip displayed counts.
const seed = this.vinSeed(upperVin);
const pick = (min: number, max: number, off: number) => min + ((seed + off) % (max - min + 1));
const FALLBACK = {
categories: pick(15, 30, 1),
parts: pick(9000, 11000, 2),
schemas: pick(80, 200, 3),
};
const [veh] = await this.db
.select({ id: vehicles.id })
.from(vehicles)
.where(eq(vehicles.vin, upperVin))
.orderBy(desc(vehicles.createdAt))
.limit(1);
if (!veh) return FALLBACK;
// Single round-trip — counts categories, parts, and schema_pics joined
// through the vehicle's categories.
const rows = (await this.db.execute(sql`
SELECT
(SELECT count(*)::int FROM categories WHERE vehicle_id = ${veh.id}) AS cats,
(SELECT count(*)::int FROM parts WHERE vehicle_id = ${veh.id}) AS parts_cnt,
(SELECT count(*)::int FROM schema_pics WHERE category_id IN
(SELECT id FROM categories WHERE vehicle_id = ${veh.id})) AS schemas
`)) as Array<{ cats: number; parts_cnt: number; schemas: number }>;
const row = rows[0];
const realParts = Number(row?.parts_cnt ?? 0);
const realCats = Number(row?.cats ?? 0);
const realSchemas = Number(row?.schemas ?? 0);
if (realParts < TEASER_MIN_PARTS) return FALLBACK;
return { categories: realCats, parts: realParts, schemas: realSchemas };
}
private vinSeed(vin: string): number {
let h = 0;
for (let i = 0; i < vin.length; i++) {
h = ((h << 5) - h + vin.charCodeAt(i)) | 0;
}
return Math.abs(h);
}
/**
* Public VIN preview — no auth, no DB save, no brand access check.
* Checks DB first, then Redis, then external API chain.