docs: sync from backend 8fc2309 — M43/M44 missing FKs + H37 dispute enums
This commit is contained in:
@@ -117,8 +117,7 @@ Both repos use Prettier defaults from the local config:
|
||||
| React component | PascalCase | `RequestCard` |
|
||||
| Hook | camelCase starting with `use` | `useSocket`, `useAuthContext` |
|
||||
| Constant | SCREAMING_SNAKE | `MAX_FILE_SIZE` |
|
||||
| Mongoose model | PascalCase singular | `User`, `PurchaseRequest` |
|
||||
| Mongo collection | lowercase plural (auto) | `users`, `purchaserequests` |
|
||||
| Drizzle table | camelCase (schema) / snake_case (SQL) | `purchaseRequests` / `purchase_requests` |
|
||||
| Route handler | `<verb><Noun>` | `getRequestById`, `createOffer` |
|
||||
| Express route file | `<domain>Routes.ts` | `paymentRoutes.ts` |
|
||||
|
||||
@@ -133,8 +132,7 @@ src/services/marketplace/
|
||||
├── index.ts # Barrel — only public exports
|
||||
├── marketplaceRoutes.ts # Router (express.Router) — auth middleware, validation, controller calls
|
||||
├── marketplaceController.ts # HTTP layer — parses req, calls service, formats response envelope
|
||||
├── marketplaceService.ts # Business logic — talks to models, throws domain errors
|
||||
└── marketplaceRepository.ts # Optional Mongoose query helpers (when service grows)
|
||||
└── marketplaceService.ts # Business logic — calls repository layer, throws domain errors
|
||||
```
|
||||
|
||||
### Response envelope
|
||||
@@ -195,6 +193,44 @@ logError("Request Network webhook verification failed", err);
|
||||
|
||||
Never use raw `console.error` in service code — it bypasses Sentry breadcrumbs.
|
||||
|
||||
### Database access
|
||||
|
||||
PostgreSQL + Drizzle ORM is the **only** database layer. MongoDB and Mongoose have been completely removed from the runtime.
|
||||
|
||||
Rules:
|
||||
- Always access data through the repository layer (`src/db/repositories/`). Call `getXxxRepo()` from the factory (`src/db/repositories/factory.ts`).
|
||||
- Never import `mongoose` or reference Mongoose models — they no longer exist. All `src/models/` Mongoose model files have been deleted.
|
||||
- Never use raw Drizzle `db` queries in service or controller code; wrap them in a repository method.
|
||||
- `PG_URL` is a required environment variable. The old `MONGO_URI` / `MONGODB_URI` / `MONGO_CONNECT_MODE` vars are obsolete and must not be added back.
|
||||
|
||||
```ts
|
||||
// ✅ Correct
|
||||
import { getOfferRepo } from "@db/repositories/factory";
|
||||
|
||||
const repo = getOfferRepo();
|
||||
const offer = await repo.findById(offerId);
|
||||
|
||||
// ❌ Wrong — Mongoose is gone
|
||||
import { Offer } from "@models/offer";
|
||||
const offer = await Offer.findById(offerId);
|
||||
```
|
||||
|
||||
### ID conventions
|
||||
|
||||
All primary keys are **PostgreSQL UUIDs** (`string`).
|
||||
|
||||
- Use `.id` to read an entity's primary key — never `._id`.
|
||||
- The `users` table retains a `legacy_object_id` column (the old MongoDB ObjectId string) for backward compatibility only. Do not use `legacy_object_id` in new code; use `user.pgId` (UUID) for foreign-key references to users (e.g. `offer.sellerId`).
|
||||
- Marketplace FKs such as `offer.sellerId` are `user.pgId` (UUID), **not** `user._id` (legacy ObjectId).
|
||||
|
||||
```ts
|
||||
// ✅ Correct
|
||||
const id: string = entity.id; // Postgres UUID
|
||||
|
||||
// ❌ Wrong — _id is a legacy ObjectId string, not a Postgres UUID
|
||||
const id = entity._id;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Frontend — UI standards
|
||||
@@ -377,4 +413,7 @@ Before requesting review:
|
||||
| `useState` for global state that 3+ components need | a context in `src/contexts/` or a custom hook |
|
||||
| Direct `axios.create` calls in components | use `src/lib/axios.ts` or an action in `src/actions/` |
|
||||
| Hard-coded URLs | constants in `src/routes/paths.ts` (frontend) or env vars (backend) |
|
||||
| Schema changes without a migration | add a migration script in `src/scripts/` and document it |
|
||||
| Schema changes without a migration | add a Drizzle migration (`drizzle-kit generate`) and document it |
|
||||
| `import mongoose` / Mongoose models | `getXxxRepo()` from `src/db/repositories/factory` |
|
||||
| `entity._id` for Postgres entities | `entity.id` (UUID string) |
|
||||
| `MONGO_URI` / `MONGO_CONNECT_MODE` env vars | `PG_URL` (required) |
|
||||
|
||||
Reference in New Issue
Block a user