@clidey/dory 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/api-playground-demo.mdx +119 -0
- package/docs/api-reference/openapi.json +366 -0
- package/docs/api-reference/operations/create.mdx +5 -0
- package/docs/api-reference/operations/delete.mdx +5 -0
- package/docs/api-reference/operations/get.mdx +5 -0
- package/docs/api-reference/operations/update.mdx +5 -0
- package/docs/assets/dory.jpeg +0 -0
- package/docs/dory.json +12 -131
- package/docs/favicon.svg +75 -0
- package/docs/features.mdx +440 -0
- package/docs/introduction.mdx +44 -0
- package/docs/logo/logo.png +0 -0
- package/package.json +9 -10
- package/src/mdx/fence.tsx +2 -1
- package/src/mdx/mermaid.tsx +39 -11
- package/src/mdx/source.tsx +15 -4
- package/docs/README.md +0 -2
- package/docs/configuration/app-settings/feature-flags.mdx +0 -157
- package/docs/configuration/app-settings/user-settings.mdx +0 -201
- package/docs/configuration/installation-setup/env-vars.mdx +0 -198
- package/docs/configuration/installation-setup/installation.mdx +0 -127
- package/docs/integrations/analytics-monitoring/error-tracking.mdx +0 -199
- package/docs/integrations/analytics-monitoring/notifications.mdx +0 -189
- package/docs/integrations/analytics-monitoring/user-analytics.mdx +0 -182
- package/docs/integrations/shopify-integration/shopify-setup.mdx +0 -226
- package/docs/integrations/shopify-integration/shopify-webhooks.mdx +0 -207
- package/docs/overview/developer-overview/dev-architecture.mdx +0 -292
- package/docs/overview/product-intro/app-overview.mdx +0 -167
- package/docs/overview/product-intro/architecture.mdx +0 -203
- package/docs/overview/product-intro/core-concepts.mdx +0 -267
- package/docs/platform-admin/billing-subscriptions/billing.mdx +0 -176
- package/docs/platform-admin/system-maintenance/db-migrations.mdx +0 -184
- package/docs/platform-admin/system-maintenance/health-monitoring.mdx +0 -222
- package/docs/platform-admin/system-maintenance/queue-management.mdx +0 -234
- package/docs/platform-admin/user-team-management/teams.mdx +0 -170
- package/docs/platform-admin/user-team-management/users.mdx +0 -185
- package/docs/support/legal/dependency-analysis.mdx +0 -132
- package/docs/support/legal/privacy-terms.mdx +0 -73
- package/docs/support/troubleshooting/common-issues.mdx +0 -159
- package/docs/usage/api-usage/api-inventory.mdx +0 -213
- package/docs/usage/api-usage/api-products.mdx +0 -249
- package/docs/usage/api-usage/api-purchase-orders.mdx +0 -289
- package/docs/usage/api-usage/api-reports.mdx +0 -227
- package/docs/usage/api-usage/api-suppliers.mdx +0 -171
- package/docs/usage/api-usage/api-user-management.mdx +0 -171
- package/docs/usage/ui-workflows/bundles.mdx +0 -157
- package/docs/usage/ui-workflows/demand-planning.mdx +0 -210
- package/docs/usage/ui-workflows/favorites.mdx +0 -167
- package/docs/usage/ui-workflows/inventory-management.mdx +0 -179
- package/docs/usage/ui-workflows/onboarding.mdx +0 -215
- package/docs/usage/ui-workflows/purchase-orders.mdx +0 -200
- package/docs/usage/ui-workflows/reports.mdx +0 -257
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Purchase Orders API'
|
|
3
|
-
description: 'Endpoints to create, update, delete, and manage purchase orders and shipments.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Purchase Orders API - Internal Developer Documentation
|
|
7
|
-
|
|
8
|
-
### 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The Purchase Orders API serves as the core backend module responsible for managing the lifecycle and data of purchase orders within the Genie platform. It handles creation, retrieval, updating, deletion, shipment management, payment processing, item variant management, import/export of purchase orders, and status transitions.
|
|
11
|
-
|
|
12
|
-
This service encapsulates all business logic related to purchase orders, including complex internal state updates such as shipment receipt processing and integration with external systems (e.g., Shopify). It operates within the broader context of team-based multi-tenancy and is integral to inventory planning and supplier coordination.
|
|
13
|
-
|
|
14
|
-
The API module boundaries cover:
|
|
15
|
-
- Purchase order CRUD operations
|
|
16
|
-
- Purchase order item and shipment management
|
|
17
|
-
- Purchase order status and payment status updates
|
|
18
|
-
- Integration points with email notifications and Shopify
|
|
19
|
-
- PDF export and multi-format data export
|
|
20
|
-
|
|
21
|
-
It interacts closely with user/team management services for authorization and compliance, and with shipment cost, bundle, and product variant services.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### 2. Technical Overview
|
|
25
|
-
|
|
26
|
-
The Purchase Orders API is implemented as a NestJS module exposing a comprehensive RESTful API and internal service methods. It leverages TypeORM for data persistence and transaction support. Key features include:
|
|
27
|
-
|
|
28
|
-
- **PurchaseOrdersController**: Exposes HTTP endpoints for CRUD and specialized operations.
|
|
29
|
-
- **PurchaseOrdersService**: Contains business logic and database operations.
|
|
30
|
-
- **Transactional Operations**: Key operations such as purchase order duplication, creation with shipments, and status updates are performed within database transactions to ensure consistency.
|
|
31
|
-
- **Integration with Email and Slack**: Sends notifications upon shipment receipt, import requests, and reminders.
|
|
32
|
-
- **Data Export**: Supports PDF generation and CSV export of POs for downstream reporting or user download.
|
|
33
|
-
|
|
34
|
-
#### Dependencies & Shared Libraries
|
|
35
|
-
- `@genie/shared`: Common Typescript DTOs, enums, and helper utilities (e.g., error codes, date utilities).
|
|
36
|
-
- `typeorm`: ORM for data access.
|
|
37
|
-
- External services:
|
|
38
|
-
- ShopifyProductsService for inventory adjustments
|
|
39
|
-
- EmailService and SlackService for notifications
|
|
40
|
-
- TeamsService for team plan and user info
|
|
41
|
-
|
|
42
|
-
#### Architectural Patterns
|
|
43
|
-
- Structurally, the module adheres to the **MVC** pattern with controller, service, and entity layers.
|
|
44
|
-
- Uses **repository pattern** via TypeORM.
|
|
45
|
-
- Employs **transactional consistency** for multi-entity updates.
|
|
46
|
-
- Implements **soft delete** semantics for data retention.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Mermaid Diagram
|
|
50
|
-
|
|
51
|
-
```mermaid
|
|
52
|
-
flowchart TD
|
|
53
|
-
subgraph Backend API
|
|
54
|
-
POController["PurchaseOrdersController"]:::controller
|
|
55
|
-
POService["PurchaseOrdersService"]:::service
|
|
56
|
-
PORepo["PurchaseOrderRepository (TypeORM)"]:::repository
|
|
57
|
-
POItemRepo["PurchaseOrderItemRepository"]:::repository
|
|
58
|
-
POShipmentRepo["PurchaseOrderShipmentRepository"]:::repository
|
|
59
|
-
POShipmentItemRepo["PurchaseOrderShipmentItemRepository"]:::repository
|
|
60
|
-
POPaymentRepo["PurchaseOrderPaymentRepository"]:::repository
|
|
61
|
-
ProductVariantRepo["ProductVariantRepository"]:::repository
|
|
62
|
-
TeamRepo["TeamRepository"]:::repository
|
|
63
|
-
LocationRepo["LocationRepository"]:::repository
|
|
64
|
-
AssetsService["AssetsService"]:::service
|
|
65
|
-
WorkflowService["WorkflowService"]:::service
|
|
66
|
-
ShopifyStoreService["ShopifyStoreService"]:::service
|
|
67
|
-
ExportService["ExportService"]:::service
|
|
68
|
-
SlackService["SlackService"]:::service
|
|
69
|
-
TeamsService["TeamsService"]:::service
|
|
70
|
-
ShopifyProductsService["ShopifyProductsService"]:::service
|
|
71
|
-
EmailService["EmailService"]:::service
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
POController -->|calls| POService
|
|
75
|
-
POService -->|reads/writes| PORepo
|
|
76
|
-
POService -->|reads/writes| POItemRepo
|
|
77
|
-
POService -->|reads/writes| POShipmentRepo
|
|
78
|
-
POService -->|reads/writes| POShipmentItemRepo
|
|
79
|
-
POService -->|reads/writes| POPaymentRepo
|
|
80
|
-
POService -->|reads| ProductVariantRepo
|
|
81
|
-
POService -->|reads| TeamRepo
|
|
82
|
-
POService -->|reads| LocationRepo
|
|
83
|
-
POService -->|calls| AssetsService
|
|
84
|
-
POService -->|calls| WorkflowService
|
|
85
|
-
POService -->|calls| ShopifyStoreService
|
|
86
|
-
POService -->|calls| ExportService
|
|
87
|
-
POService -->|calls| SlackService
|
|
88
|
-
POService -->|calls| TeamsService
|
|
89
|
-
POService -->|calls| ShopifyProductsService
|
|
90
|
-
POService -->|calls| EmailService
|
|
91
|
-
|
|
92
|
-
classDef controller fill:#A3CEF1,stroke:#0366d6,color:#000,stroke-width:1px
|
|
93
|
-
classDef service fill:#FFE156,stroke:#996515,color:#000,stroke-width:1px
|
|
94
|
-
classDef repository fill:#3F72AF,stroke:#1C385F,color:#fff,stroke-width:1px
|
|
95
|
-
|
|
96
|
-
class POController controller
|
|
97
|
-
class POService,AssetsService,WorkflowService,ShopifyStoreService,ExportService,SlackService,TeamsService,ShopifyProductsService,EmailService service
|
|
98
|
-
class PORepo,POItemRepo,POShipmentRepo,POShipmentItemRepo,POPaymentRepo,ProductVariantRepo,TeamRepo,LocationRepo repository
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
### 3. Core Concepts and Responsibilities
|
|
103
|
-
|
|
104
|
-
- **Purchase Order (PO)**: Represents a formal request to a supplier for products including details such as supplier, items, shipments, and costs.
|
|
105
|
-
- **PO Item**: Individual product variant entries within a purchase order, including quantities and unit costs.
|
|
106
|
-
- **Shipment**: Defines delivery batches and dates linked to POs with associated costs and receipt status.
|
|
107
|
-
- **Payment**: Payment schedule and status related to a PO.
|
|
108
|
-
|
|
109
|
-
The service maintains strict ownership of PO data, ensuring state transitions and shipment receipt are synchronized with inventory and external systems (Shopify).
|
|
110
|
-
|
|
111
|
-
#### Key Assumptions & Decisions
|
|
112
|
-
- Soft deleting POs for data retention and audit.
|
|
113
|
-
- Payments and shipments are managed as child entities to POs.
|
|
114
|
-
- Duplicate PO functionality resets status to Draft and clears received dates, while retaining items, shipments, and payments logically linked to new PO.
|
|
115
|
-
- Exchange rates per currency are stored against POs for accurate financial calculations.
|
|
116
|
-
|
|
117
|
-
#### Maintainers & Logging
|
|
118
|
-
- Maintained by backend engineering team.
|
|
119
|
-
- Uses NestJS Logger extensively for method tracing.
|
|
120
|
-
- Exception handling centralizes on `GenieException` with domain-specific error codes.
|
|
121
|
-
|
|
122
|
-
#### Non-Functional Requirements
|
|
123
|
-
- Transactional integrity during complex updates (PO update, shipment receipt).
|
|
124
|
-
- Scalable queries with pagination and filtering (e.g., shipment query API).
|
|
125
|
-
- Security enforced via team membership checks (throwing `GenieException` if user not on a team).
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
### 4. Code Structure
|
|
129
|
-
|
|
130
|
-
- **Controllers**
|
|
131
|
-
- `PurchaseOrdersController` ([app/api/src/purchase-order/controllers/purchase-orders.controller.ts](apps/api/src/purchase-order/controllers/purchase-orders.controller.ts))
|
|
132
|
-
- Handles REST API routes such as:
|
|
133
|
-
- `POST /purchase-orders` (list POs)
|
|
134
|
-
- `GET /purchase-orders/:id`
|
|
135
|
-
- `POST /create`, `/create-with-quantities`
|
|
136
|
-
- `PUT /:id`, `PUT /:id/status`
|
|
137
|
-
- `DELETE /:id` and bulk deletes
|
|
138
|
-
- `POST /:id/duplicate`
|
|
139
|
-
- Shipment updates, payment updates, PO item additions
|
|
140
|
-
- Export endpoints
|
|
141
|
-
|
|
142
|
-
- **Services**
|
|
143
|
-
- `PurchaseOrdersService` ([app/api/src/purchase-order/services/purchase-orders.service.ts](apps/api/src/purchase-order/services/purchase-orders.service.ts))
|
|
144
|
-
- Core business logic
|
|
145
|
-
- Uses injected repositories for DB operations
|
|
146
|
-
- Contains methods for:
|
|
147
|
-
- Fetching POs with flexible filters
|
|
148
|
-
- Summary aggregation of purchase orders
|
|
149
|
-
- Creating purchase orders with and without quantities
|
|
150
|
-
- Updating POs, statuses, shipments, payments
|
|
151
|
-
- Duplication logic with full entity cloning except IDs
|
|
152
|
-
- Import notification handling
|
|
153
|
-
- Shipment receipt processing with Shopify sync
|
|
154
|
-
- PDF generation via ExportService
|
|
155
|
-
|
|
156
|
-
- **Repositories**
|
|
157
|
-
- TypeORM repos for PO entities (purchase order, items, shipments, payments, shipment costs, etc.).
|
|
158
|
-
|
|
159
|
-
- **Utilities & Helpers**
|
|
160
|
-
- Use of `@genie/shared` modules for enums, DTOs, error handling, date utilities.
|
|
161
|
-
- Helper methods for stock coverage calculations, cost resolutions.
|
|
162
|
-
|
|
163
|
-
### Example Snippet: Updating a Purchase Order
|
|
164
|
-
```ts
|
|
165
|
-
async updatePurchaseOrder({ id, teamId, data }) {
|
|
166
|
-
await this.handleAttachmentsUpdate(id, data.content?.attachmentUrls || []);
|
|
167
|
-
|
|
168
|
-
let purchaseOrder = await this.poRepository.findOneOrFail({
|
|
169
|
-
where: { teamId, id },
|
|
170
|
-
relations: ["items", "shipments", "shipments.items", "shipments.costs"],
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
purchaseOrder.status = data.status;
|
|
174
|
-
purchaseOrder.content = data.content;
|
|
175
|
-
purchaseOrder.supplierId = data.supplierId;
|
|
176
|
-
purchaseOrder.payments = data.payments.map((payment) =>
|
|
177
|
-
this.poPaymentRepository.create({
|
|
178
|
-
...payment,
|
|
179
|
-
id: payment.id ?? undefined,
|
|
180
|
-
purchaseOrderId: purchaseOrder.id,
|
|
181
|
-
teamId,
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
purchaseOrder.issueDate = toDate(data.issueDate) ?? null;
|
|
186
|
-
|
|
187
|
-
// Update shipment costs
|
|
188
|
-
purchaseOrder.shipments = purchaseOrder.shipments!.map((shipment) => {
|
|
189
|
-
const newCosts = data.shipmentCosts.find((s) => s.shipmentId === shipment.id)?.costs ?? [];
|
|
190
|
-
shipment.costs = newCosts.map((cost) =>
|
|
191
|
-
this.poShipmentCostRepository.create({ ...cost, teamId, purchaseOrderShipmentId: shipment.id })
|
|
192
|
-
);
|
|
193
|
-
return shipment;
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
// Update items preserving IDs
|
|
197
|
-
purchaseOrder.items = data.items?.map((newItem) => {
|
|
198
|
-
const item = purchaseOrder.items!.find(i => newItem.productVariantId === i.productVariantId);
|
|
199
|
-
return this.poItemRepository.create({ ...newItem, id: item?.id, purchaseOrderId: purchaseOrder.id, teamId });
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
await this.poRepository.save(purchaseOrder);
|
|
203
|
-
|
|
204
|
-
// If only one shipment, re-sync shipment items quantities
|
|
205
|
-
if (purchaseOrder.shipments!.length === 1) {
|
|
206
|
-
purchaseOrder = await this.poRepository.findOneOrFail({
|
|
207
|
-
where: { teamId, id },
|
|
208
|
-
relations: ["items", "shipments", "shipments.items", "payments"],
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
purchaseOrder.shipments!.forEach(shipment => {
|
|
212
|
-
purchaseOrder.items!.forEach(poItem => {
|
|
213
|
-
const shipmentItem = shipment.items!.find(item => item.purchaseOrderItemId === poItem.id);
|
|
214
|
-
const orderedQuantity = poItem.quantity ?? 0;
|
|
215
|
-
|
|
216
|
-
if (shipmentItem) {
|
|
217
|
-
shipmentItem.orderedQuantity = orderedQuantity;
|
|
218
|
-
} else {
|
|
219
|
-
shipment.items!.push(
|
|
220
|
-
this.poShipmentItemRepository.create({
|
|
221
|
-
teamId,
|
|
222
|
-
purchaseOrderShipmentId: shipment.id,
|
|
223
|
-
purchaseOrderItemId: poItem.id,
|
|
224
|
-
orderedQuantity,
|
|
225
|
-
})
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
await this.poRepository.save(purchaseOrder);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
### 5. API and Interfaces
|
|
238
|
-
|
|
239
|
-
The primary API endpoints are exposed via `PurchaseOrdersController` with payload validation powered by Zod schemas from `@genie/shared`:
|
|
240
|
-
|
|
241
|
-
| Endpoint | HTTP Method | Purpose |
|
|
242
|
-
|--------------------------|---------------|--------------------------|
|
|
243
|
-
| `/purchase-orders` | POST | List purchase orders for a team with optional filters |
|
|
244
|
-
| `/purchase-orders/summary` | GET | Summary of purchase orders for a team |
|
|
245
|
-
| `/purchase-orders/:id` | GET | Get detailed purchase order by ID |
|
|
246
|
-
| `/purchase-orders/create` | POST | Create a new purchase order |
|
|
247
|
-
| `/purchase-orders/create-with-quantities` | POST | Create a new PO with explicit quantities |
|
|
248
|
-
| `/purchase-orders/:id` | PUT | Update purchase order data |
|
|
249
|
-
| `/purchase-orders/:id/status` | PUT | Update status of a specific PO |
|
|
250
|
-
| `/purchase-orders/delete` | POST | Delete multiple POs in bulk |
|
|
251
|
-
| `/purchase-orders/:id/delete` | DELETE | Soft delete a specific PO |
|
|
252
|
-
| `/purchase-orders/:id/add-product-variants` | PUT | Add new product variants to existing PO |
|
|
253
|
-
| `/purchase-orders/:id/shipments` | PUT | Update shipments of a PO |
|
|
254
|
-
| `/purchase-orders/:id/shipments/:shipmentId` | PUT | Update a specific shipment within a PO |
|
|
255
|
-
| `/purchase-orders/:id/duplicate` | POST | Duplicate an existing PO |
|
|
256
|
-
| `/purchase-orders/import` | POST | Trigger import and notify process for POs
|
|
257
|
-
| `/purchase-orders/:id/export/pdf` | POST | Export PO as PDF with sorted items |
|
|
258
|
-
|
|
259
|
-
Requests and responses adhere to strict DTO validation. Errors produce consistent HTTP status codes such as `400` for bad requests, `404` for missing POs, and custom error bodies via `GenieException`.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
### 6. Environment & Configuration
|
|
263
|
-
|
|
264
|
-
- No direct environment variables specific to purchase orders documented here.
|
|
265
|
-
- Requires database connection for TypeORM repositories.
|
|
266
|
-
- External credentials/configurations for:
|
|
267
|
-
- Shopify integration in `ShopifyStoreService` and `ShopifyProductsService`
|
|
268
|
-
- Email service credentials for `EmailService`
|
|
269
|
-
- Slack bot tokens for `SlackService`
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
### 7. Testing, Monitoring, and Deployment
|
|
273
|
-
|
|
274
|
-
- Testing strategy is not explicitly detailed in the provided context.
|
|
275
|
-
- The system uses NestJS `Logger` for auditing main flows and error capture.
|
|
276
|
-
- Errors are monitored using `captureException` with `GenieException` wrappers.
|
|
277
|
-
- Transactions are used for critical update flows ensuring data integrity.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
### 8. Troubleshooting and Known Issues
|
|
281
|
-
|
|
282
|
-
- When purchase order not found, service throws a `GenieException` with code `PurchaseOrderNotFound` handled as `404` on controller level.
|
|
283
|
-
- Shipment receipt updates include rigorous validation and proper error wrapping to prevent inconsistent state.
|
|
284
|
-
- Duplicate PO includes validation to ensure related items exist before copying shipments and items.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
This documentation enables backend developers to understand, maintain, and extend the Purchase Orders API with confidence, ensuring coherent purchase order management across the Genie platform.
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Reports API'
|
|
3
|
-
description: 'APIs for generating reports, managing report definitions and email alert definitions.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Reports API Developer Documentation
|
|
7
|
-
|
|
8
|
-
## 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The **Reports API** is responsible for managing the lifecycle and content of inventory and purchase order reports within the Genie system. It serves to generate, store, update, and deliver detailed reports that provide inventory insights, alerts, and operational snapshots.
|
|
11
|
-
|
|
12
|
-
This API handles:
|
|
13
|
-
|
|
14
|
-
- Defining and initializing report definitions and email alert definitions per team.
|
|
15
|
-
- Generating report instances (both scheduled and manual).
|
|
16
|
-
- Providing data for reports including detailed inventory statuses, purchase orders, and dashboard snapshots.
|
|
17
|
-
- Emailing reports and alert emails to designated recipients.
|
|
18
|
-
|
|
19
|
-
**System boundaries:**
|
|
20
|
-
- Operates primarily within the backend service layer, interacting with database repositories (e.g., ReportDefinitionEntity, ReportInstanceEntity).
|
|
21
|
-
- Integrates tightly with services handling inventory data, purchase orders, suppliers, dashboard data, and email delivery.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
## 2. Technical Overview
|
|
25
|
-
|
|
26
|
-
The Reports API is implemented as a NestJS injectable service producing report instances based on saved definitions. It uses TypeORM for data persistence and relies on several domain-specific services for gathering required data:
|
|
27
|
-
|
|
28
|
-
- `InventoryService`: Retrieves inventory items and their attributes.
|
|
29
|
-
- `PurchaseOrdersService`: Provides summaries and details of purchase orders.
|
|
30
|
-
- `SupplierService`: Supplies supplier information.
|
|
31
|
-
- `DashboardService`: Collects dashboard snapshot data.
|
|
32
|
-
- `SettingsService`: Provides user/team-specific settings such as timezone.
|
|
33
|
-
- `EmailService`: Sends generated reports and alert emails.
|
|
34
|
-
|
|
35
|
-
Report generation is type-driven: each report type maps to a dedicated content-generation method.
|
|
36
|
-
|
|
37
|
-
### Architecture Diagram
|
|
38
|
-
|
|
39
|
-
```mermaid
|
|
40
|
-
flowchart TD
|
|
41
|
-
subgraph Backend Services
|
|
42
|
-
ReportsService["ReportsService"]:::service
|
|
43
|
-
InventoryService["InventoryService"]:::service
|
|
44
|
-
PurchaseOrdersService["PurchaseOrdersService"]:::service
|
|
45
|
-
SupplierService["SupplierService"]:::service
|
|
46
|
-
DashboardService["DashboardService"]:::service
|
|
47
|
-
SettingsService["SettingsService"]:::service
|
|
48
|
-
EmailService["EmailService"]:::service
|
|
49
|
-
ReportRepository["ReportDefinition & ReportInstance Repos"]:::database
|
|
50
|
-
EmailAlertRepo["EmailAlertDefinition Repository"]:::database
|
|
51
|
-
end
|
|
52
|
-
subgraph Database
|
|
53
|
-
Postgres[("PostgreSQL DB")]:::db
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
ReportsService -->|uses| InventoryService
|
|
57
|
-
ReportsService -->|uses| PurchaseOrdersService
|
|
58
|
-
ReportsService -->|uses| SupplierService
|
|
59
|
-
ReportsService -->|uses| DashboardService
|
|
60
|
-
ReportsService -->|uses| SettingsService
|
|
61
|
-
ReportsService -->|reads/writes| ReportRepository
|
|
62
|
-
ReportsService -->|reads/writes| EmailAlertRepo
|
|
63
|
-
ReportsService -->|generates emails via| EmailService
|
|
64
|
-
|
|
65
|
-
InventoryService -->|reads inventory data| Postgres
|
|
66
|
-
PurchaseOrdersService -->|reads purchase orders| Postgres
|
|
67
|
-
SupplierService -->|reads suppliers| Postgres
|
|
68
|
-
DashboardService -->|reads dashboard info| Postgres
|
|
69
|
-
SettingsService -->|fetches settings| Postgres
|
|
70
|
-
|
|
71
|
-
classDef service fill:#147efb,color:#fff,stroke:#005da8,stroke-width:1px
|
|
72
|
-
classDef database fill:#ffb74d,color:#000,stroke:#cc7a00,stroke-width:1px
|
|
73
|
-
classDef db fill:#8bc34a,color:#000,stroke:#689f38,stroke-width:1px
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
## 3. Core Concepts and Responsibilities
|
|
78
|
-
|
|
79
|
-
### Terminology
|
|
80
|
-
- **Report Definition:** A persisted template describing the type of report, frequency, schedule, and settings.
|
|
81
|
-
- **Report Instance:** A generated report based on a definition, containing snapshot data at the generation time.
|
|
82
|
-
- **Email Alert Definition:** Defines configuration for alert emails for inventory or purchase order states.
|
|
83
|
-
- **Report Types:** Enumerated constants describing report categories (e.g., dead stock, stockout risk, purchase order snapshots).
|
|
84
|
-
- **Report Frequency and Schedule:** Controls when reports are generated or sent.
|
|
85
|
-
|
|
86
|
-
### Responsibility
|
|
87
|
-
- The ReportsService is owned by the backend development team.
|
|
88
|
-
- It logs its operations via NestJS Logger for traceability.
|
|
89
|
-
- Error conditions use the custom `GenieException` for consistent exception handling.
|
|
90
|
-
- Data consistency and report validity are enforced before generating instances.
|
|
91
|
-
|
|
92
|
-
### Non-Functional Requirements
|
|
93
|
-
- **Reliability:** Handles data errors by capturing exceptions and logging without crashing.
|
|
94
|
-
- **Performance:** Implements pagination when fetching large data (e.g., inventory snapshots) to support scalability.
|
|
95
|
-
- **Security:** Uses teamId scoping for all data queries to ensure multi-tenancy data isolation.
|
|
96
|
-
- **Extensibility:** Supports adding new report types by implementing corresponding content generation methods.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
## 4. Code Structure
|
|
100
|
-
|
|
101
|
-
### Key Files
|
|
102
|
-
- [apps/api/src/reports/services/reports.service.ts](apps/api/src/reports/services/reports.service.ts): Main service implementing report generation logic, CRUD on report definitions, exclusions, and email alert handling.
|
|
103
|
-
- [apps/web/src/components/pages/reports/reports.tsx](apps/web/src/components/pages/reports/reports.tsx): React frontend for listing and managing reports; uses API to fetch definitions.
|
|
104
|
-
- [apps/api/src/admin/controllers/report.controller.ts](apps/api/src/admin/controllers/report.controller.ts): Admin controller exposing backend endpoints for reports.
|
|
105
|
-
- [apps/api/src/admin/services/report.service.ts](apps/api/src/admin/services/report.service.ts): Service for admin report data health and purchase order reports.
|
|
106
|
-
- [apps/api/src/email/services/email.service.ts](apps/api/src/email/services/email.service.ts): Handles email sending, including report alert emails.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
### Core Methods in `ReportsService`
|
|
110
|
-
|
|
111
|
-
- `getReportDefinitionsDto(teamId)`: Fetches all report definitions for a team with the next scheduled run.
|
|
112
|
-
|
|
113
|
-
- `initReportDefinitions(teamId)`: Ensures default report definitions exist with valid default settings.
|
|
114
|
-
|
|
115
|
-
- `generateReportInstance({teamId, definitionId, type})`: Creates and stores a new report instance, generating content for the report type.
|
|
116
|
-
|
|
117
|
-
- `generateReportContent(instance)`: Routes to the appropriate report content generation method based on report type.
|
|
118
|
-
|
|
119
|
-
- `getReportDefinitionExcludedProductVariantIds(teamId, definitionId)`: Determines which product variants are excluded from the report.
|
|
120
|
-
|
|
121
|
-
- `excludeReportDefinitionProductVariants(...)` and `includeReportDefinitionProductVariants(...)`: Manage exclusions by updating the database.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### Report Content Generation
|
|
125
|
-
|
|
126
|
-
Each report type has a corresponding method, e.g.,
|
|
127
|
-
|
|
128
|
-
```ts
|
|
129
|
-
private async generateInventoryStockoutRiskAlertContent(instance: ReportInstanceEntity): Promise<InventoryItemsStockoutRiskListReport> {
|
|
130
|
-
// Fetch stockout risk items and exclusions
|
|
131
|
-
// Filter out excluded variants
|
|
132
|
-
// Format and return structured report content
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
These methods gather raw data from domain services, apply filtering and business logic, and format results according to predefined report content types.
|
|
137
|
-
|
|
138
|
-
### Example snippet: Creating a report instance
|
|
139
|
-
|
|
140
|
-
```ts
|
|
141
|
-
async generateReportInstance({ teamId, definitionId, type }) {
|
|
142
|
-
const definition = await this.getReportDefinition(teamId, definitionId);
|
|
143
|
-
if (!definition.isValid()) {
|
|
144
|
-
throw new GenieException("Invalid report definition", {definition, teamId});
|
|
145
|
-
}
|
|
146
|
-
const instance = this.reportInstanceRepository.create({
|
|
147
|
-
teamId,
|
|
148
|
-
reportDefinitionId: definitionId,
|
|
149
|
-
reportDefinitionSnapshot: definition.getSnapshot(),
|
|
150
|
-
type,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
instance.content = await this.generateReportContent(instance);
|
|
154
|
-
await this.reportInstanceRepository.save(instance);
|
|
155
|
-
return instance;
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
## 5. API and Interfaces
|
|
161
|
-
|
|
162
|
-
The ReportController exposes API endpoints (admin restricted) for:
|
|
163
|
-
|
|
164
|
-
- `GET /admin/reports/data-health` - Returns health status of reports and Shopify integrations for all teams.
|
|
165
|
-
- `GET /admin/reports/teams/:teamId/purchase-orders` - Returns purchase order report data for a team.
|
|
166
|
-
- `POST /admin/reports/send-email-alert` - Sends alert emails for specified report instances to given email addresses.
|
|
167
|
-
|
|
168
|
-
### Report Types Enum
|
|
169
|
-
`ReportType` enumerates the available report categories:
|
|
170
|
-
|
|
171
|
-
| Enum Value | Description |
|
|
172
|
-
|---------------------------------|-------------------------------------|
|
|
173
|
-
| INVENTORY_STOCKOUT_RISK_ALERT | Stockout risk alert |
|
|
174
|
-
| INVENTORY_OUT_OF_STOCK_ALERT | Out of stock alert |
|
|
175
|
-
| INVENTORY_DEAD_STOCK_ALERT | Dead stock alert |
|
|
176
|
-
| INVENTORY_SALES_VELOCITY_ALERT | Sales velocity alert |
|
|
177
|
-
| INVENTORY_ACTIVE_STOCK_ASSET_VALUE | Asset value report (active products) |
|
|
178
|
-
| INVENTORY_ALL_STOCK_ASSET_VALUE| Asset value report (all products) |
|
|
179
|
-
| INVENTORY_NEGATIVE_ON_HAND_ALERT| Negative on-hand alert |
|
|
180
|
-
| INVENTORY_SNAPSHOT | Inventory snapshot |
|
|
181
|
-
| INVENTORY_SALES_SNAPSHOT | Inventory sales snapshot |
|
|
182
|
-
| PURCHASE_ORDER_ACTIVE_SNAPSHOT | Purchase order active snapshot |
|
|
183
|
-
| DASHBOARD_SNAPSHOT | Dashboard snapshot |
|
|
184
|
-
| INVENTORY_ITEMS_VARIANCE | Inventory variance report |
|
|
185
|
-
| INVENTORY_IN_TRANSIT | Inventory in transit report |
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
### Report Frequency and Schedule
|
|
189
|
-
- Frequencies include Daily, Weekly, Monthly.
|
|
190
|
-
- Schedule represents the time of day for scheduled reports (e.g., 0900, 1200).
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
## 6. Environment & Configuration
|
|
194
|
-
|
|
195
|
-
- Requires configuration of `APP_URL` for front-end link generation.
|
|
196
|
-
- Uses `SENDGRID_API_KEY` for email delivery via SendGrid (configured in EmailService).
|
|
197
|
-
- Environment variables control email sending behavior (e.g., prevents email sending in non-production environments to external domains).
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
## 7. Testing, Monitoring, and Deployment
|
|
201
|
-
|
|
202
|
-
- Logging uses NestJS Logger module; exceptions are captured via `captureException` for centralized error tracking.
|
|
203
|
-
- Email sending failures log exceptions without blocking overall operations.
|
|
204
|
-
- Report instance generation performs input validation and throws `GenieException` on invalid states.
|
|
205
|
-
- Deployment uses TypeORM migrations for DB schema updates, including inventory view adjustments.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
## 8. Troubleshooting & Known Issues
|
|
209
|
-
|
|
210
|
-
- Report instances are only generated for valid definition statuses (`Active`).
|
|
211
|
-
- Generating report content without required type-specific settings throws exceptions.
|
|
212
|
-
- Excluded product variants are filtered correctly to avoid irrelevant data in reports.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
## 9. References & Source Links
|
|
216
|
-
|
|
217
|
-
- [Reports Service Implementation](apps/api/src/reports/services/reports.service.ts)
|
|
218
|
-
- [Report Controller](apps/api/src/admin/controllers/report.controller.ts)
|
|
219
|
-
- [Report Admin Service](apps/api/src/admin/services/report.service.ts)
|
|
220
|
-
- [Email Service for Reports](apps/api/src/email/services/email.service.ts)
|
|
221
|
-
- [Web UI Reports Listing](apps/web/src/components/pages/reports/reports.tsx)
|
|
222
|
-
- [Report Instance CSV Export Utils](apps/web/src/components/pages/report-instance/utils.ts)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
This documentation provides an authoritative technical overview of the Genie Reports API backend implementation, enabling developers to understand, maintain, and extend report generation and delivery capabilities effectively.
|