docs: sync from backend c5db471 — request templates

This commit is contained in:
Siavash Sameni
2026-06-01 19:02:03 +04:00
parent 02641e1333
commit 8a90bb69be
5 changed files with 49 additions and 21 deletions

View File

@@ -1,18 +1,20 @@
---
title: RequestTemplate
tags: [data-model, mongoose]
tags: [data-model, mongoose, postgres]
aliases: [Template, Request Template, IRequestTemplate]
---
# RequestTemplate
> **Last updated:** 2026-05-31 — seller-owned delivery mode and per-template payment rails documented.
> **Last updated:** 2026-06-01 — Postgres schema and backfill surface documented.
A reusable template authored by a seller. When a buyer visits the template's `shareableLink`, the front-end pre-fills a new [[PurchaseRequest]] with the template's category, urgency, specs, seller-selected delivery mode, payment rail allowlist, and an optional default seller `proposal`. The schema mirrors `PurchaseRequest` for fast cloning, plus template-specific bookkeeping (`isActive`, `usageCount`, `maxUsage`, `expiresAt`).
> [!note] Source
> `backend/src/models/RequestTemplate.ts:65` — schema definition
> `backend/src/models/RequestTemplate.ts:295` — model export
> `backend/src/models/RequestTemplate.ts:83` — Mongoose schema definition
> `backend/src/models/RequestTemplate.ts:335` — model export
> `backend/src/db/schema/requestTemplate.ts:35` — Drizzle table definition
> `backend/src/db/backfill/backfill-requestTemplates.ts:1` — Mongo → Postgres backfill
## Schema
@@ -83,6 +85,16 @@ Defined at `backend/src/models/RequestTemplate.ts:283-293`:
`shareableLink` and `sellerId` already get indexes from `unique: true` / field-level conventions (see source comment at line 282).
Postgres migration `0010_request_templates.sql` creates `request_templates` with:
- `request_templates_legacy_object_id_uq`: idempotent Mongo bridge for backfill.
- `request_templates_shareable_link_uq`: public slug uniqueness.
- FK columns `seller_id → users.id` and `category_id → categories.id`.
- Matching single/compound indexes for seller, category, product type, active state, expiry, and public slug lookups.
- JSONB `specifications` and scalar/array columns for delivery, service, proposal, payment rails, images, and attachments.
Runtime service wiring is not cut over yet; `RequestTemplateService` still uses Mongoose directly.
## Pre/Post Hooks
None declared.