Account Management
The Account Management submodule handles core account operations including main account creation, sub-account management, account retrieval with filtering, and account lifecycle operations within the DashClicks platform.
API Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
GET | /v1/accounts | Get sub-accounts with filtering and pagination |
POST | /v1/accounts | Create main account (public signup) |
POST | /v1/accounts/project | Create project-based sub-account |
GET | /v1/accounts/email-check | Check email availability and send verification |
GET | /v1/accounts/verify/:code | Verify signup code |
GET | /v1/accounts/verify | Verify token |
GET | /v1/accounts/search | Search accounts by business data |
GET | /v1/accounts/:id | Get specific account details |
PUT | /v1/accounts/:id | Update account information |
DELETE | /v1/accounts/:id | Archive sub-account |
PUT | /v1/accounts/:id/unarchive | Unarchive sub-account |
MongoDB Collections Used
Primary Collections
_accounts- Main account collection with business relationships and configurationcrm.contacts- Business contact information (linked as account.business)_users- Account users and owner relationships_store.subscriptions- Store subscriptions for account tiers and servicesaccount-signup-codes- Email verification codes for signup
Core Account Workflows
Main Account Creation Flow
graph TD
A[Email Verification Request] --> B[Generate Signup Code]
B --> C[Send Verification Email]
C --> D[User Clicks Verification Link]
D --> E[Validate JWT Token]
E --> F[Create Business Contact]
F --> G[Generate DashClicks Subdomain]
G --> H[Create Account Record]
H --> I[Generate Affiliate Code]
I --> J[Create Owner User]
J --> K[Process Stripe Domain Verification]
K --> L[Queue Default Setup Tasks]
Project Account Creation Flow
graph TD
A[Select Business for Project] --> B[Validate Business Availability]
B --> C[Generate JWT Token]
C --> D[Create Project Sub-Account]
D --> E[Link Business to Account]
E --> F[Generate Affiliate Code]
F --> G[Send Project Invitation Email]
G --> H[User Setup Process]
Service Methods & Functionality
Core Account Services
getAccounts() - Sub-account retrieval with filtering
- Retrieves sub-accounts with comprehensive filtering and pagination support
- Supports tier-based filtering (tier0-tier3) based on store subscriptions
- Implements status-based filtering (opened vs not_opened invitations)
- Provides search across business names, phones, and owner information
- Includes pending account visibility control with all/pending parameters
- Returns paginated account data with global count statistics
postAccount() - Main account creation
- Creates new main accounts through public signup process
- Handles business entity creation and JWT token validation
- Manages subdomain generation and availability checking
- Implements affiliate code generation and referrer tracking
- Integrates with Stripe for domain verification
- Returns created account and user with status confirmation
newAccountProject() - Project-based sub-account creation
- Creates sub-accounts from existing business contacts for project management
- Handles JWT token generation for invitation workflows
- Manages affiliate code assignment and parent account relationships
- Sends invitation emails to business contacts
- Returns created project account with confirmation
Email Verification Services
emailCheck() - Email verification and signup codes
- Validates email uniqueness for main account creation
- Generates JWT tokens with email and tier information
- Creates short verification codes for signup process
- Sends verification emails with signup links
- Returns verification status confirmation
verifyCode() / verify() - Signup verification
- Validates signup codes and JWT tokens
- Checks email uniqueness before proceeding
- Redirects to appropriate signup or error pages
- Handles token expiration and validation errors
Account Management Services
getAccountById() - Individual account details
- Retrieves detailed account information by ID with authorization
- Includes business relationships and account hierarchy
- Provides complete account profile with nested data
- Returns comprehensive account information
updateAccountById() - Account modification
- Updates account information including business and branding data
- Handles metadata updates and feature flag configurations
- Manages owner information and account settings
- Supports scheduled demo and public account configurations
- Returns updated account confirmation
search() - Business search functionality
- Searches businesses associated with accounts using custom fields
- Supports advanced filtering and search across contact information
- Provides search across additional_info and address fields
- Returns filtered account results with business data
Account Lifecycle Services
archiveSubAccount() / unArchiveSubAccount() - Account status management
- Archives sub-accounts with proper authorization and status validation
- Handles pending account cleanup and invitation token removal
- Unarchives previously archived accounts with owner validation
- Manages account status transitions with role-based permissions
Technical Implementation Details
Authentication & Authorization
- JWT Token Management: Secure token generation for signup verification
- Owner-based Access Control: Account owner privileges for sensitive operations
- Multi-tenant Isolation: Parent-child account relationships with secure data isolation
- Role-based Permissions: Granular permission system for account operations
Data Processing Architecture
- MongoDB Aggregation: Complex aggregation pipelines for account filtering and statistics
- Pagination Framework: Efficient pagination with skip/limit for large datasets
- Search Integration: Full-text search across business and contact information
- Transaction Management: Database transactions for critical account operations
Business Logic Features
Advanced Account Filtering
- Tier-based Filtering: Filter accounts by subscription tier (tier0-tier3)
- Status-based Filtering: Distinguish between opened and pending invitations
- Search Capabilities: Full-text search across business and owner information
- Aggregation Pipeline: MongoDB aggregation for complex filtering and counting
Secure Account Creation
- Email Verification: Multi-step verification process with secure codes
- Subdomain Generation: Automatic available subdomain detection and assignment
- Business Integration: Seamless business contact creation and linking
- Affiliate Tracking: Automatic affiliate code generation and referrer tracking
Account Hierarchy Management
- Parent-Child Relationships: Structured account hierarchy for multi-tenancy
- Project-based Accounts: Special account creation for project management
- Status Management: Comprehensive account lifecycle and status tracking
- Search and Discovery: Advanced search across account hierarchies
Key Features
Comprehensive Account Operations
- Account Creation: Complete main account creation with email verification
- Sub-Account Management: Project-based and invitation-based sub-account creation
- Account Filtering: Advanced filtering with tier-based and status-based options
- Search Functionality: Full-text search across business and contact data
Secure Verification System
- Email Verification: Secure email verification with time-limited codes
- Token Management: JWT-based token system for secure account creation
- Uniqueness Validation: Email and business uniqueness checking
- Redirect Handling: Proper redirect flows for verification and errors
Multi-tenant Architecture
- Account Hierarchy: Parent-child account relationships for white-label operations
- Business Integration: Seamless integration with business contact management
- Project Management: Specialized project-based account creation workflows
- Status Tracking: Comprehensive account status and invitation management