Merchant & Warehouse Management
Relevant source files
The following files were used as context for generating this wiki page:
- packages/core/src/services/warehouses/WarehousesService.ts
- packages/common/src/entities/Warehouse.ts
- packages/admin-web-angular/src/app/pages/+warehouses/warehouses.component.ts
- packages/core/src/graphql/warehouses/warehouse.resolver.ts
- packages/admin-web-angular/src/app/pages/+warehouses/warehouses.module.ts
- packages/admin-web-angular/src/app/pages/+fakeData/fakeData.component.ts
- README.md
- packages/merchant-tablet-ionic/package.json
The Merchant & Warehouse Management system is a core component of the Ever Demand platform, designed to handle single-store and multi-vendor marketplace environments. It provides the foundational structure for representing physical or virtual stores, merchants, and warehouses. This system manages everything from basic merchant information, product catalogs, and inventory to real-time location tracking, delivery settings, and order processing.
The platform includes a backend API (GraphQL, REST, WS), an Admin Web App for platform-wide management, and a dedicated Merchant Tablet App for store owners to manage their operations, including orders and deliveries. The terms "Warehouse," "Merchant," and "Store" are used synonymously throughout the codebase.
Sources: README.md:21-32, packages/common/src/entities/Warehouse.ts:13-18
Data Model: The Warehouse Entity
The Warehouse entity is the central data structure for representing a merchant or store. It is defined using both Mongoose schemas for MongoDB and TypeORM decorators, indicating a transition or support for multiple database types.
Sources: packages/common/src/entities/Warehouse.ts:22-29
ER Diagram
This diagram shows the Warehouse entity and its relationships with GeoLocation and WarehouseProduct.
Key Properties
The Warehouse entity contains a wide range of properties to configure a merchant's operations.
| Property | Type | Description |
|---|---|---|
name | string | The public name of the store/merchant. |
username | string | Unique username for the store administrator to log into the Merchant app. |
hash | string | Hashed password for the store administrator. Not selected by default in queries. |
isActive | boolean | Indicates if the warehouse is currently operational. |
isPaymentEnabled | boolean | If false, only cash-on-delivery or takeaway is possible. |
isCashPaymentEnabled | boolean | Toggles the cash payment method. |
geoLocation | GeoLocation | The current address and coordinates of the warehouse. Supports mobile warehouses. |
deliveryAreas | object | GeoJSON object defining the areas where the warehouse delivers. |
products | WarehouseProduct[] | An array of products available for purchase at this warehouse. |
contactEmail / contactPhone | string | Primary contact information for the store. |
ordersEmail / ordersPhone | string | Specific contact details for receiving orders. |
forwardOrdersUsing | ForwardOrdersMethod[] | An array specifying the preferred methods (e.g., email, phone) to forward new orders. |
productsDelivery | boolean | Whether the store allows deliveries for purchases. |
productsTakeaway | boolean | Whether the store allows takeaway purchases. |
paymentGateways | PaymentGateway[] | An array of configured payment gateways (e.g., Stripe). |
isDeleted | boolean | A soft-delete flag. |
Sources: packages/common/src/entities/Warehouse.ts:54-325
Backend Architecture
The backend is built with NestJS and exposes functionality through a GraphQL API. The core logic is encapsulated in services, which are then used by GraphQL resolvers.
WarehousesService
This service contains the primary business logic for managing Warehouse entities. It handles creation, authentication, data retrieval, and updates.
Sources: packages/core/src/services/warehouses/WarehousesService.ts
Service Dependencies
The WarehousesService depends on other services for authentication and product management.
Key Methods
| Method | Description |
|---|---|
register(input) | Creates a new warehouse. Hashes the password if provided. |
login(username, password) | Authenticates a warehouse administrator and returns a JWT and warehouse data. |
get(id, fullProducts) | Retrieves a single warehouse by its ID, optionally populating its full product list. |
getAllActive(fullProducts) | Retrieves all warehouses that are marked as isActive: true. |
getMerchants(findInput, pagingOptions) | Retrieves a paginated list of merchants based on a query. |
updateGeoLocation(warehouseId, geoLocation) | Updates the geographical location of a moving or stationary warehouse. |
updatePassword(id, password) | Updates the password for a warehouse's admin user. |
removeMultipleByIds(ids) | Soft-deletes multiple warehouses by setting isDeleted: true. |
Sources: packages/core/src/services/warehouses/WarehousesService.ts:63-294
GraphQL API (WarehouseResolver)
The WarehouseResolver exposes the WarehousesService methods to clients via a GraphQL interface. It defines the queries and mutations for interacting with warehouse data.
Sources: packages/core/src/graphql/warehouses/warehouse.resolver.ts
Warehouse Registration Flow
This sequence diagram illustrates how a new warehouse is registered via the GraphQL API.
Key Queries & Mutations
| Operation | Type | Description |
|---|---|---|
warehouses(findInput, pagingOptions) | Query | Fetches a paginated list of warehouses. Supports sorting. |
warehouse(id) | Query | Retrieves a single warehouse by its ID. |
nearbyStores(geoLocation) | Query | Finds stores near a given geographical location. |
getAllActiveStores(fullProducts) | Query | Gets all currently active stores. |
getStoreProducts(storeId, fullProducts) | Query | Fetches the product catalog for a specific store. |
registerWarehouse(registerInput) | Mutation | Registers a new warehouse. |
warehouseLogin(username, password) | Mutation | Logs in a merchant and returns a token. |
updateStoreGeoLocation(storeId, geoLocation) | Mutation | Updates a store's location. |
updateWarehousePassword(id, password) | Mutation | Changes a warehouse administrator's password. |
removeWarehousesByIds(ids) | Mutation | Removes a list of warehouses by their IDs. |
Sources: packages/core/src/graphql/warehouses/warehouse.resolver.ts:39-248
Frontend Administration (Angular)
The admin-web-angular application provides a comprehensive UI for managing all warehouses on the platform.
Warehouses List View
The main view for managing warehouses is the WarehousesComponent, which displays a list of all stores in a ng2-smart-table. This table allows for sorting, filtering, and multi-selection for bulk actions like deletion.
Sources: packages/admin-web-angular/src/app/pages/+warehouses/warehouses.component.ts
Smart Table Configuration
The table displays key information about each warehouse and provides actions for management.
| Column | Title (en) | Render Component | Description |
|---|---|---|---|
images | Image | WarehouseImageComponent | Displays the warehouse logo. |
name | Name | RedirectNameComponent | Displays the warehouse name and links to its detail page. |
email | WarehouseEmailComponent | Displays the contact email. | |
phone | Phone | WarehousePhoneComponent | Displays the contact phone. |
city | City | - | The city from the warehouse's geoLocation. |
address | Address | - | The street address and house number. |
ordersQty | Orders | WarehouseOrdersNumberComponent | Shows the total number of orders for the warehouse. |
actions | Actions | WarehouseActionsComponent | Provides action buttons (e.g., edit, delete) for the row. |
Sources: packages/admin-web-angular/src/app/pages/+warehouses/warehouses.component.ts:192-243
Angular Module Structure
The warehouse management feature is organized into several Angular modules, promoting separation of concerns. The main WarehousesModule imports specialized modules for UI components, forms, and routing.
This graph shows the dependencies of the main WarehousesModule.
Merchant Tablet Application
The platform includes a dedicated application for merchants, built with Ionic and Angular. This app is designed for tablets and allows store owners to perform daily operational tasks.
Key features of the Merchant Tablet App include:
- Managing and tracking orders in real-time.
- Organizing deliveries.
- Accessing store-specific data and settings.
The existence and purpose of this application are confirmed in the project's root README.md and its own package.json.
Sources: README.md:29, packages/merchant-tablet-ionic/package.json:2-3
Fake Data Generation
For development and testing, the project includes a FakeDataComponent that can populate the database with sample data, including warehouses. The createWarehouse1 method, for example, demonstrates the programmatic creation of a warehouse by calling warehouseRouter.register. This utility is useful for understanding the data required to create a valid warehouse entity.
Sources: packages/admin-web-angular/src/app/pages/+fakeData/fakeData.component.ts:358-364