Add platform invoices API with item templates and optional name.

Super admins can manage predefined invoice lines and issue invoices to businesses; schema is ready for future business-scoped use.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-07-24 20:59:35 +03:30
co-authored by Cursor
parent 136711dfb3
commit 426316d53c
10 changed files with 1094 additions and 3 deletions
+45 -3
View File
@@ -1,7 +1,7 @@
# Meshkee CMS API — Project Context
> Living reference for developers and AI assistants working on this codebase.
> Last updated: July 2026
> Last updated: July 24, 2026
## What This Project Is
@@ -77,6 +77,8 @@ src/
├── orders/ # Customer checkout + admin order management
├── media/ # Upload/list/update/delete media
├── storage/ # S3 driver abstraction
├── website-docs/ # Public website API docs pack
├── invoices/ # Platform invoices + item templates (super-admin; business-ready schema)
├── prisma/ # PrismaModule + PrismaService
├── redis/ # Redis client + OTP helpers
└── common/ # Shared interceptors (BigInt serialization)
@@ -150,7 +152,8 @@ Example super admin: `+989121111111` / `password`
| `018_product_variant_reward_points.sql` | Reward points on store items |
| `019_cart_and_orders.sql` | Shopping cart, orders, order items + order permissions |
| `020_store_items_and_variants.sql` | `store_items` + `store_item_variants` (replaces `product_variants`) |
| `030_website_homepage.sql` | Website category/brand groups, sliders, brand `sort_order` |
| `036_invoices.sql` | Invoices, invoice items, invoice item templates + permissions |
| `037_invoice_name.sql` | Optional `invoices.name` |
Docker mounts `./database/migrations` into Postgres init — migrations run automatically only on **first** volume creation. Use `migrate.sh` for subsequent migrations.
@@ -167,6 +170,8 @@ Docker mounts `./database/migrations` into Postgres init — migrations run auto
| `VariationType` | `color`, `size`, `custom` |
| `OrderStatus` | `pending`, `confirmed`, `processing`, `shipped`, `delivered`, `cancelled` |
| `OrderSource` | `website`, `admin` |
| `InvoiceOwnerScope` | `platform`, `business` |
| `InvoiceStatus` | `draft`, `issued`, `paid`, `cancelled` |
| `TechnicalFieldType` | `text`, `textarea`, `select`, `multi_select` |
| `MediaType` | `image`, `video` |
@@ -194,6 +199,10 @@ Business 1──* Cart (per customer) 1──* CartItem → ProductVariant
Business 1──* Order 1──* OrderItem → ProductVariant (snapshot on order)
User 1──* Cart, Order (as customer)
Business 1──* Invoice (billed party) 1──* InvoiceItem
InvoiceItemTemplate (platform or per-business predefined lines)
Invoice.issuedBy → User
Media 1──* MediaAttachment (polymorphic: entityType + entityId)
```
@@ -553,6 +562,37 @@ See `.env.example` for the full list. Key groups:
---
## Invoices (platform / super-admin)
Super admins issue invoices **to** a business. Schema is ready for future business-scoped issuing (`owner_scope=business`).
### Tables
| Table | Purpose |
|-------|---------|
| `invoice_item_templates` | Predefined line items (`owner_scope` platform \| business) |
| `invoices` | Invoice header (`business_id` = billed party, optional `name`, `notes`, `status`) |
| `invoice_items` | Line items (title, duration, worktime, description, price, discounted_price) |
### API (super_admin only today)
| Method | Path |
|--------|------|
| GET/POST | `/invoice-item-templates` |
| PATCH/DELETE | `/invoice-item-templates/:templateId` |
| GET/POST | `/businesses/:businessId/invoices` |
| GET/PATCH/DELETE | `/businesses/:businessId/invoices/:invoiceId` |
Auth: `JwtAuthGuard` + service `assertSuperAdmin`.
Serialized platform invoices include `publicUrl`: `https://{INVOICE_PUBLIC_DOMAIN}/invoices/{id}` (default domain `meshkee.com`). Public HTML viewer is **not** implemented yet.
Permissions seeded for future business dashboard: `invoices.*`, `invoice_templates.*`.
Module: `src/invoices/`
---
## Testing
**Postman collection:** `postman/Meshkee-CMS-Auth.postman_collection.json`
@@ -595,7 +635,9 @@ Follow the pattern in `CategoryVariationsService` / `CategoryTechnicalFormServic
| Purpose | Path |
|---------|------|
| Prisma schema | `prisma/schema.prisma` |
| Env template | `.env.example` |
| Env template | `.env.example` (`INVOICE_PUBLIC_DOMAIN` for platform invoice links) |
| Invoices module | `src/invoices/` |
| Invoice migrations | `database/migrations/036_invoices.sql`, `037_invoice_name.sql` |
| Docker services | `docker-compose.yml` |
| Dev seed data | `database/seeds/001_sample_data.sql` |
| Postman | `postman/Meshkee-CMS-Auth.postman_collection.json` |