πŸ—οΈ Enkage Backend Project

Complete System Flow Documentation

1. System Overview

What is Enkage?

Enkage is a modern, scalable backend API system built with Node.js and Express, designed for knowledge management systems similar to KKMA (Kuwait Kerala Muslim Association). It provides comprehensive management of members, organizations, committees, transactions, and multi-layered authentication.

Tech Stack

πŸš€ Backend

Node.js + Express

πŸ—„οΈ Database

PostgreSQL

πŸ” Auth

JWT + 2FA

πŸ“‹ Validation

Joi

πŸ“ Files

Multer

πŸ”’ Security

Helmet + CORS

πŸ“Š Logging

Winston

☁️ Deployment

PM2

Key Features

  • βœ… Multi-Layer Authentication: Separate auth for Admin, Committee, and StarClub members
  • βœ… Role-Based Access Control: Dynamic permissions based on user roles and positions
  • βœ… Hierarchical Organization: 3-layer organizational structure (Center, Zone, Branch)
  • βœ… Committee Management: Positions, departments, and delegation support
  • βœ… Member Management: Registration, renewal, family members, and referrals
  • βœ… Transaction Processing: Payments, refunds, and comprehensive tracking
  • βœ… Form Approvals: Multi-level approval workflows
  • βœ… File Uploads: Secure file management with folder structure

2. System Architecture

graph TB Client[Client Application] -->|HTTP/HTTPS| Server[Express Server] Server --> Middleware[Middleware Layer] Middleware --> Auth[Authentication] Middleware --> Validation[Validation] Middleware --> RateLimit[Rate Limiting] Middleware --> Security[Security] Server --> Routes[Routes Layer] Routes --> Controllers[Controllers] Controllers --> Services[Services Layer] Services --> Models[Models] Models --> ORM[Sequelize ORM] ORM --> Database[(PostgreSQL Database)] Services --> Utils[Utilities] Utils --> Logger[Winston Logger] Utils --> FileUpload[File Upload] Utils --> Email[Nodemailer] Database --> Tables[Tables] Tables --> Members[Members] Tables --> Users[Users] Tables --> Committees[Committees] Tables --> Transactions[Transactions] Tables --> Organisations[Organizations] style Client fill:#667eea,stroke:#333,stroke-width:2px,color:#fff style Server fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff style Database fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style Auth fill:#ffc107,stroke:#333,stroke-width:2px,color:#333

Module Structure

The project follows a modular architecture where each feature is self-contained:

src/modules/
β”œβ”€β”€ auth/           # User authentication
β”œβ”€β”€ members/        # Member management
β”œβ”€β”€ committees/     # Committee management
β”œβ”€β”€ committeeMembers/ # Committee member assignments
β”œβ”€β”€ organizations/  # Organization structure
β”œβ”€β”€ organizationUnits/ # Layer hierarchy
β”œβ”€β”€ organizationSettings/ # Configuration
β”œβ”€β”€ transactions/   # Payment processing
β”œβ”€β”€ formApprovals/ # Approval workflows
β”œβ”€β”€ fileUpload/    # File management
β”œβ”€β”€ locations/     # Location data
└── mixedauth/     # Multi-layer authentication
                    

3. Authentication System Overview

graph TD Start([User Requests Access]) --> CheckType{What User Type?} CheckType -->|Admin/Staff| AdminAuth[Admin Authentication] CheckType -->|Committee Member| CommitteeAuth[Committee Auth] CheckType -->|StarClub Member| StarClubAuth[StarClub Auth] AdminAuth --> AdminTable[Query Users Table] AdminTable --> AdminCheck{Valid
Credentials?} AdminCheck -->|No| AdminError[Login Error] AdminCheck -->|Yes| AdminToken[Generate JWT Token] CommitteeAuth --> FindMember1[Find Member by ID/Email/Civil ID] FindMember1 --> CheckCommittee{Is Committee
Member?} CheckCommittee -->|No| CommitteeError[Not Eligible] CheckCommittee -->|Yes| AuthCheck1{2FA Status?} StarClubAuth --> FindMember2[Find Member by ID/Email/Civil ID] FindMember2 --> CheckReferrer{Has Referred
Members?} CheckReferrer -->|No| StarClubError[Not Eligible] CheckReferrer -->|Yes| AuthCheck2{2FA Status?} AuthCheck1 -->|Pending| Onetime1[Use Onetime Password] AuthCheck1 -->|Active| TOTP1[Use TOTP Code] AuthCheck2 -->|Pending| Onetime2[Use Onetime Password] AuthCheck2 -->|Active| TOTP2[Use TOTP Code] Onetime1 --> Setup2FA1[Setup 2FA with QR Code] Onetime2 --> Setup2FA2[Setup 2FA with QR Code] TOTP1 --> Verify1[Verify TOTP] TOTP2 --> Verify2[Verify TOTP] Verify1 --> LoadPerms1[Load Position Permissions] Verify2 --> DefaultPerms[Load Default Permissions] LoadPerms1 --> MemberToken1[Generate JWT with Committee Data] DefaultPerms --> MemberToken2[Generate JWT] AdminToken --> AdminAccess[Full System Access] MemberToken1 --> CommitteeAccess[Committee Portal Access] MemberToken2 --> StarClubAccess[StarClub Portal Access] style AdminAuth fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style CommitteeAuth fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style StarClubAuth fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style AdminAccess fill:#667eea,stroke:#333,stroke-width:3px,color:#fff style CommitteeAccess fill:#28a745,stroke:#333,stroke-width:3px,color:#fff style StarClubAccess fill:#ffc107,stroke:#333,stroke-width:3px,color:#333

4. SuperAdmin FlowAdmin

Authentication Flow

graph LR A[Admin Login Page] -->|Username/Email + Password| B[POST /api/v1/mixed-auth/admin-login] B --> C{Validate Credentials} C -->|Invalid| D[Return 401 Error] C -->|Valid| E[Update Last Login] E --> F[Generate JWT Token] F --> G[Return Token + Full Permissions] G --> H[Access All Modules] H --> I[Member Management] H --> J[Committee Management] H --> K[Organization Management] H --> L[Transaction Management] H --> M[User Management] H --> N[Settings Management] style A fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style G fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style H fill:#667eea,stroke:#333,stroke-width:3px,color:#fff

Key Features & Permissions

Full System Access

  • βœ… Manage all users in the system
  • βœ… Create, edit, and delete all members
  • βœ… Manage committee structures and assignments
  • βœ… Configure organization hierarchy and settings
  • βœ… View and manage all transactions
  • βœ… Generate onetime passwords for members
  • βœ… Reset 2FA for any member
  • βœ… Export reports and data
  • βœ… System configuration and settings

Common Admin Workflows

graph TD Login[Admin Logs In] --> Dashboard[Admin Dashboard] Dashboard --> SetupMember[Setup New Member] SetupMember --> CreateMember[Create Member Record] CreateMember --> GenerateOTP[Generate Onetime Password] GenerateOTP --> NotifyMember[Notify Member] Dashboard --> ManageCommittee[Manage Committees] ManageCommittee --> CreateCommittee[Create Committee] CreateCommittee --> AssignMembers[Assign Committee Members] AssignMembers --> SetPositions[Assign Positions] Dashboard --> ApproveForm[Approve Forms] ApproveForm --> ViewForm[View Form Details] ViewForm --> ReviewData[Review Submitted Data] ReviewData --> Decision{Approve/Reject?} Decision -->|Approve| UpdateStatus[Update Status] Decision -->|Reject| SendFeedback[Send Feedback] Dashboard --> ViewReports[View Reports] ViewReports --> FilterData[Filter by Date/Range] FilterData --> ExportData[Export to Excel] style Login fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style Dashboard fill:#667eea,stroke:#333,stroke-width:2px,color:#fff style ApproveForm fill:#28a745,stroke:#333,stroke-width:2px,color:#fff

Admin API Endpoints

  • POST /api/v1/mixed-auth/admin-login - Admin login
  • GET /api/v1/members - List all members
  • POST /api/v1/members - Create new member
  • PUT /api/v1/members/:id - Update member
  • POST /api/v1/committees - Create committee
  • POST /api/v1/mixed-auth/admin/generate-onetime-password - Generate OTP
  • POST /api/v1/mixed-auth/admin/reset-2fa - Reset member 2FA
  • GET /api/v1/transactions/transaction-table - View all transactions
  • GET /api/v1/form-approvals - View pending approvals

5. Committee Member FlowCommittee

Authentication Flow

graph LR A[Committee Login Page] -->|Civil ID/Email/Member ID| B[POST /api/v1/mixed-auth/member-login] B --> C{Member Exists?} C -->|No| D[Return 404] C -->|Yes| E{Is Committee Member?} E -->|No| F[Return 403 Not Eligible] E -->|Yes| G{2FA Status?} G -->|Pending| H[Enter Onetime Password] G -->|Active| I[Enter TOTP Code] H --> J{Correct OTP?} J -->|No| K[Return 401 Error] J -->|Yes| L[Generate QR Code] L --> M[Complete 2FA Setup] M --> N[Enter TOTP to Verify] I --> O{Valid TOTP?} N --> O O -->|No| K O -->|Yes| P[Load Committee Data] P --> Q[Get Position & Permissions] Q --> R[Generate JWT with Committee Info] R --> S[Return Token + Committee Access] S --> T[Committee Portal Access] T --> U[View Assigned Forms] T --> V[Approve/Reject Forms] T --> W[Manage Committee Tasks] style A fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style E fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style S fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style T fill:#667eea,stroke:#333,stroke-width:3px,color:#fff

Committee Member Features

Based on Position Permissions

  • βœ… View committee-specific reports and data
  • βœ… Manage assigned committee members (if permitted)
  • βœ… Approve/Reject transactions based on position
  • βœ… View and manage assigned cases/forms
  • βœ… Access layer-specific data based on committee assignment
  • βœ… Department-specific access if assigned

Committee Member Workflows

graph TD Login[Committee Member Login] --> CheckAuth{First Time?} CheckAuth -->|Yes| Setup2FA[Setup 2FA] CheckAuth -->|No| EnterTOTP[Enter TOTP] Setup2FA --> ShowQR[Show QR Code] ShowQR --> ScanQR[Scan with Google Authenticator] ScanQR --> VerifyCode[Verify with TOTP] EnterTOTP --> VerifyCode VerifyCode --> Portal[Committee Portal] Portal --> ViewDashboard[Dashboard] ViewDashboard --> ShowPending[Pending Approvals] ViewDashboard --> ShowAssigned[Assigned Tasks] ShowPending --> SelectForm[Select Form] SelectForm --> ReviewDetails[Review Details] ReviewDetails --> CheckPermissions{Has Permission?} CheckPermissions -->|No| DenyAccess[Access Denied] CheckPermissions -->|Yes| MakeDecision{Approve/Reject} MakeDecision -->|Approve| UpdateForm[Mark as Approved] MakeDecision -->|Reject| AddComments[Add Rejection Comments] AddComments --> UpdateForm UpdateForm --> NotifyNext[Notify Next Approver] UpdateForm --> NotifyMember[Notify Member] Portal --> ViewReports[View Reports] ViewReports --> FilterByDept[Filter by Department] ViewReports --> FilterByLayer[Filter by Layer] Portal --> ManageDelegation[Manage Delegation] ManageDelegation --> AssignDelegate[Assign Delegate] style Login fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style Portal fill:#667eea,stroke:#333,stroke-width:3px,color:#fff style MakeDecision fill:#ffc107,stroke:#333,stroke-width:2px,color:#333

Committee Member API Endpoints

  • POST /api/v1/mixed-auth/member-login - Committee login
  • POST /api/v1/mixed-auth/complete-2fa-setup - Setup 2FA
  • GET /api/v1/form-approvals - View assigned forms
  • PUT /api/v1/form-approvals/:id/approve - Approve form
  • PUT /api/v1/form-approvals/:id/reject - Reject form
  • GET /api/v1/committees/:id/members - View committee members
  • GET /api/v1/transactions - View transactions (filtered by permissions)

6. StarClub Member FlowStarClub

Authentication Flow

graph LR A[StarClub Login Page] -->|Civil ID/Email/Member ID| B[POST /api/v1/mixed-auth/member-login] B --> C{Member Exists?} C -->|No| D[Return 404] C -->|Yes| E{Has Referred Members?} E -->|No| F[Return 403 Not Eligible] E -->|Yes| G{2FA Status?} G -->|Pending| H[Enter Onetime Password] G -->|Active| I[Enter TOTP Code] H --> J{Correct OTP?} J -->|No| K[Return 401 Error] J -->|Yes| L[Generate QR Code] L --> M[Complete 2FA Setup] M --> N[Enter TOTP to Verify] I --> O{Valid TOTP?} N --> O O -->|No| K O -->|Yes| P[Generate JWT Token] P --> S[Return Token + StarClub Access] S --> T[StarClub Portal Access] T --> U[View Referral Network] T --> V[View Referral Statistics] T --> W[Manage Referred Members] T --> X[View Referral Reports] style A fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style E fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style S fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style T fill:#667eea,stroke:#333,stroke-width:3px,color:#fff

StarClub Member Features

Referral-Based Access

  • βœ… View complete referral network tree
  • βœ… View referral statistics and analytics
  • βœ… Track referred members' status
  • βœ… Access referral-based reports
  • βœ… View income/benefits from referrals
  • βœ… Manage and contact referred members

StarClub Member Workflows

graph TD Login[StarClub Login] --> CheckAuth{First Time?} CheckAuth -->|Yes| Setup2FA[Setup 2FA] CheckAuth -->|No| EnterTOTP[Enter TOTP] Setup2FA --> ShowQR[Show QR Code] ShowQR --> ScanQR[Scan with Google Authenticator] ScanQR --> VerifyCode[Verify with TOTP] EnterTOTP --> VerifyCode VerifyCode --> Portal[StarClub Portal] Portal --> Dashboard[Dashboard] Dashboard --> ShowStats[Referral Statistics] Dashboard --> ShowNetwork[Referral Network] ShowStats --> DisplayTotal[Total Referrals] DisplayTotal --> DisplayActive[Active Referrals] DisplayActive --> DisplayBenefits[Earned Benefits] ShowNetwork --> LoadNetwork[Load Network Tree] LoadNetwork --> ShowDirect[Direct Referrals] ShowDirect --> ShowIndirect[Indirect Referrals] Portal --> ViewMembers[View Referred Members] ViewMembers --> FilterStatus[Filter by Status] FilterStatus --> ViewDetails[View Member Details] ViewDetails --> ContactMember[Contact Member] Portal --> ViewReports[Referral Reports] ViewReports --> SelectPeriod[Select Time Period] SelectPeriod --> GenerateReport[Generate Report] GenerateReport --> ExportReport[Export Report] Portal --> ViewTransactions[Related Transactions] ViewTransactions --> FilterByRef[Filter by Referral] FilterByRef --> ViewDetails[View Transaction Details] style Login fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style Portal fill:#667eea,stroke:#333,stroke-width:3px,color:#fff style Dashboard fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff

StarClub Member API Endpoints

  • POST /api/v1/mixed-auth/member-login - StarClub login
  • POST /api/v1/mixed-auth/complete-2fa-setup - Setup 2FA
  • GET /api/v1/members/referred-by/:memberId - View referrals
  • GET /api/v1/members/referral-stats/:memberId - Referral statistics
  • GET /api/v1/members/referral-network/:memberId - Network tree
  • GET /api/v1/transactions/member/:memberId - Related transactions

7. Module Overview

Core Modules Flow

flowchart TB subgraph AUTH["Authentication Module"] A1[Mixed Auth] A2[Admin Auth] A3[2FA Setup] A4[JWT Generation] end subgraph MEMBERS["Members Module"] M1[Register Member] M2[Update Member] M3[Member Renewal] M4[Family Members] M5[Referral Management] end subgraph COMMITTEES["Committees Module"] C1[Create Committee] C2[Assign Members] C3[Position Management] C4[Department Assignment] C5[Delegation] end subgraph TRANSACTIONS["Transactions Module"] T1[Create Transaction] T2[Process Payment] T3[Process Refund] T4[Status Update] T5[Payment History] end subgraph FORMS["Form Approvals Module"] F1[Submit Form] F2[Approval Flow] F3[Multi-Level Review] F4[Status Tracking] end subgraph ORGANIZATIONS["Organizations Module"] O1[Layer Hierarchy] O2[Department Management] O3[Position Management] O4[Settings] end subgraph REPORTS["Reports Module"] R1[Transaction Reports] R2[Member Reports] R3[Committee Reports] R4[Financial Reports] R5[Export to Excel] end Client[Client Applications] --> A1 A1 --> M1 A1 --> C1 A1 --> T1 A1 --> F1 M1 --> T1 M1 -.->|Referrals| M1 C1 --> F1 C1 --> R1 O1 --> C1 O1 --> M1 T1 --> R1 M1 --> R1 classDef authModule fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff classDef membersModule fill:#28a745,stroke:#333,stroke-width:2px,color:#fff classDef committeesModule fill:#667eea,stroke:#333,stroke-width:2px,color:#fff classDef transactionsModule fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 classDef formsModule fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff classDef orgModule fill:#17a2b8,stroke:#333,stroke-width:2px,color:#fff classDef reportsModule fill:#e83e8c,stroke:#333,stroke-width:2px,color:#fff class A1,A2,A3,A4 authModule class M1,M2,M3,M4,M5 membersModule class C1,C2,C3,C4,C5 committeesModule class T1,T2,T3,T4,T5 transactionsModule class F1,F2,F3,F4 formsModule class O1,O2,O3,O4 orgModule class R1,R2,R3,R4,R5 reportsModule

Module Description

Module Purpose Key Features
auth User authentication JWT tokens, password management, user CRUD
mixedauth Multi-layer authentication Admin, Committee, StarClub login with 2FA
members Member management Registration, renewal, family, referrals, profiles
committees Committee structure Create committees, assign members, define hierarchy
committeeMembers Committee membership Assign positions, departments, delegation
transactions Payment processing Create, pay, refund, track payment history
formApprovals Approval workflows Submit, review, approve/reject forms
organizations Organization structure Manage organization hierarchy
organizationUnits Layer management Center, Zone, Branch hierarchy
fileUpload File management Upload, organize, secure file storage
locations Location data Countries, states, districts, cities
reports (Integrated) Reporting & Analytics Transaction, member, committee reports with Excel export

8. Data Filtering & Access Control by User Type

How Filtering Works

Three-Tier Access Control System

The system implements role-based filtering at multiple levels:

  1. User Type Level: Admin sees all, Committee/StarClub see filtered data
  2. Permission Level: Position-based permissions for committee members
  3. Hierarchy Level: Organization layer (Center, Zone, Branch) filtering
  4. Department Level: Department-specific access for committee members

SuperAdmin Filtering

graph LR AdminLogin[Admin Login] --> AllAccess[Full System Access] AllAccess --> NoFilter[No Automatic Filters] NoFilter --> ManualFilter[Manual Filters Available] ManualFilter --> ByDate[Filter by Date Range] ManualFilter --> ByMember[Filter by Member] ManualFilter --> ByType[Filter by Type] ManualFilter --> ByStatus[Filter by Status] ManualFilter --> ByOrg[Filter by Organization] ManualFilter --> ByLayer[Filter by Layer] ByDate --> ExportAll[Export All Data] ByMember --> ExportAll ByType --> ExportAll ByStatus --> ExportAll ByOrg --> ExportAll ByLayer --> ExportAll style AdminLogin fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style AllAccess fill:#28a745,stroke:#333,stroke-width:3px,color:#fff style NoFilter fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
Data Type Admin Access Automatic Filters Can View
Members βœ… Full Access ❌ None - See All All members across all organizations, layers, and departments
Transactions βœ… Full Access ❌ None - See All All transactions, payments, refunds regardless of organization/layer
Committees βœ… Full Access ❌ None - See All All committees, positions, and assignments
Forms βœ… Full Access ❌ None - See All All submitted and pending approval forms
Reports βœ… Full Access ❌ None - Generate All All organizational, financial, and member reports

Committee Member Filtering

graph LR CommitteeLogin[Committee Login] --> LoadCommitteeData[Load Committee Info] LoadCommitteeData --> CheckPosition{Has Position?} CheckPosition -->|Yes| LoadPerms[Load Position Permissions] CheckPosition -->|No| DefaultPerms[Use Default Committee Perms] LoadPerms --> CheckLayer{Hierarchy Level?} CheckLayer --> CheckDept{Department Access?} CheckLayer --> Layer1[Layer 1 Access] CheckLayer --> Layer2[Layer 2 Access] CheckLayer --> Layer3[Layer 3 Access] CheckLayer --> AllLayers[All Layers Access] CheckDept --> Dept1[Specific Departments] CheckDept --> AllDepts[All Departments] Layer1 --> ApplyLayerFilter[Apply Layer Filter] Layer2 --> ApplyLayerFilter Layer3 --> ApplyLayerFilter AllLayers --> NoLayerFilter[No Layer Filter] Dept1 --> ApplyDeptFilter[Apply Department Filter] AllDepts --> NoDeptFilter[No Department Filter] ApplyLayerFilter --> FilteredData1[Filtered Data] NoLayerFilter --> FilteredData2[Filtered Data] ApplyDeptFilter --> FilteredData1 NoDeptFilter --> FilteredData2 DefaultPerms --> LimitedAccess[Limited Default Access] style CommitteeLogin fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style LoadPerms fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style ApplyLayerFilter fill:#667eea,stroke:#333,stroke-width:2px,color:#fff style ApplyDeptFilter fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
Data Type Committee Access Automatic Filters Can View
Transactions ⏸️ Based on Permissions βœ… Layer Assignment Only transactions from members in assigned layer
Forms βœ… Approve/Reject βœ… Department + Layer Only forms from assigned department in assigned layer
Members ❌ Limited Access βœ… Layer + Department Only members in committee's layer and department
Committees ⏸️ Own Committee βœ… Committee ID Only own committee details and members
Reports ⏸️ Filtered βœ… Layer + Department Only reports for assigned layer and department

StarClub Member Filtering

graph LR StarClubLogin[StarClub Login] --> CheckReferrals{Has Referrals?} CheckReferrals -->|No| DenyAccess[Access Denied] CheckReferrals -->|Yes| LoadReferrals[Load Referral Network] LoadReferrals --> DirectRefs[Direct Referrals] DirectRefs --> IndirectRefs[Indirect Referrals] IndirectRefs --> NetworkTree[Network Tree] NetworkTree --> ApplyRefFilter[Apply Referral Filter] ApplyRefFilter --> FilteredData[Only Referral Data] FilteredData --> ViewNetwork[View Network] FilteredData --> ViewStats[View Statistics] FilteredData --> ViewTransactions[View Transactions] style StarClubLogin fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style LoadReferrals fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff style ApplyRefFilter fill:#667eea,stroke:#333,stroke-width:2px,color:#fff style DenyAccess fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
Data Type StarClub Access Automatic Filters Can View
Referral Network βœ… Full Access βœ… Own Referrals Only All members referred by them (direct & indirect)
Transactions ⏸️ Filtered βœ… Referral-Based Only transactions from referred members
Statistics βœ… Full Access βœ… Own Network Only Referral count, active members, benefits earned
Members ⏸️ Limited βœ… Referral Network Only members they referred
Reports βœ… Filtered βœ… Referral-Based Only reports related to their referral network

Transaction Filtering Details

Available Transaction Filters

The transaction table supports comprehensive filtering:

  • Date Range: dateFrom, dateTo - Filter by transaction creation date
  • Amount Range: amountMin, amountMax - Filter by transaction amount
  • Type: transactionType - membership_fee, renewal_fee, late_fee, etc.
  • Status: paymentStatus - pending, completed, failed, cancelled, refunded
  • Organization: organizationId - Filter by specific organization
  • Layer Hierarchy: center (Layer 1), zone (Layer 2), branch (Layer 3)
  • Member: memberId - Filter by specific member
  • Star Club: starClubMember - Filter by referring member
  • Search: search - Search by name, transaction ID, payment ID
  • Currency: currency - Filter by currency (KWD, USD, etc.)

How Filtering is Applied in Code

Example: Transaction Filtering Logic


// 1. User logs in - JWT token contains user info
const user = { 
    id: 123, 
    layer: 'committee',
    committeeData: { layerId: 5, departmentId: 2 }
}

// 2. Request comes with filters
GET /api/v1/transactions/transaction-table?page=1&limit=20

// 3. Backend applies automatic filters based on user type
if (user.layer === 'committee') {
    // Only show transactions from members in same layer
    filters.layerId = user.committeeData.layerId;
    
    // Optional: Filter by department if assigned
    if (user.committeeData.departmentId) {
        filters.departmentId = user.committeeData.departmentId;
    }
}

// 4. Query database with applied filters
SELECT * FROM transactions 
WHERE layer_id = 5 
AND department_id = 2
LIMIT 20 OFFSET 0;
                    

9. Complete API Endpoints Overview

Authentication & Authorization

  • POST /api/v1/mixed-auth/admin-login - Admin login
  • POST /api/v1/mixed-auth/member-login - Member login (Committee/StarClub)
  • POST /api/v1/mixed-auth/complete-2fa-setup - Complete 2FA setup
  • GET /api/v1/mixed-auth/check-auth-status - Check auth status
  • POST /api/v1/mixed-auth/admin/generate-onetime-password - Generate OTP (Admin)
  • POST /api/v1/mixed-auth/admin/reset-2fa - Reset 2FA (Admin)
  • GET /api/v1/mixed-auth/admin/view-onetime-password/:memberId/:tabType - View OTP (Admin)
  • GET /api/v1/mixed-auth/admin/auth-status/:memberId/:tabType - Auth status (Admin)

Members Management

  • POST /api/v1/members - Create member
  • GET /api/v1/members - List all members (filtered)
  • GET /api/v1/members/:id - Get member details
  • PUT /api/v1/members/:id - Update member
  • DELETE /api/v1/members/:id - Delete member
  • GET /api/v1/members/:id/family - Get family members
  • PUT /api/v1/members/:id/renew - Renew membership
  • GET /api/v1/members/referred-by/:memberId - Get referrals

Committees Management

  • POST /api/v1/committees - Create committee
  • GET /api/v1/committees - List committees
  • GET /api/v1/committees/:id - Get committee details
  • PUT /api/v1/committees/:id - Update committee
  • DELETE /api/v1/committees/:id - Delete committee
  • POST /api/v1/committee-members - Assign committee member
  • GET /api/v1/committee-members - List committee members
  • PUT /api/v1/committee-members/:id - Update assignment

Transactions Management

  • POST /api/v1/transactions - Create transaction
  • GET /api/v1/transactions - List transactions
  • GET /api/v1/transactions/:id - Get transaction details
  • PUT /api/v1/transactions/:id - Update transaction
  • DELETE /api/v1/transactions/:id - Delete transaction
  • POST /api/v1/transactions/:id/pay - Process payment
  • POST /api/v1/transactions/:id/refund - Process refund
  • GET /api/v1/transactions/:id/payment - Get payment details
  • GET /api/v1/transactions/transaction-table - Advanced transaction table
  • GET /api/v1/transactions/transaction-table-filters - Get filter options

Organizations & Structure

  • GET /api/v1/organizations - List organizations
  • GET /api/v1/organization-units - List units (layers)
  • GET /api/v1/departments - List departments
  • GET /api/v1/positions - List positions
  • GET /api/v1/organization-settings - Get settings

Form Approvals

  • POST /api/v1/form-approvals - Submit form
  • GET /api/v1/form-approvals - List forms
  • PUT /api/v1/form-approvals/:id/approve - Approve form
  • PUT /api/v1/form-approvals/:id/reject - Reject form

File Upload

  • POST /api/v1/fileupload/:folder/:subfolder - Upload single file
  • POST /api/v1/fileupload/:folder/:subfolder/multiple - Upload multiple files

9. User Type Comparison

Feature SuperAdmin Committee Member StarClub Member
Authentication Username/Email + Password Civil ID/Email + 2FA (TOTP) Civil ID/Email + 2FA (TOTP)
Member Management βœ… Full access ❌ No access ❌ No access
Committee Management βœ… Full access ⏸️ Limited (own committee) ❌ No access
Transaction Management βœ… Full access ⏸️ Approve based on permissions ❌ No access
Form Approvals βœ… Full access βœ… Assign and approve forms ❌ No access
Referral Network βœ… View all ❌ No access βœ… Own referrals only
Reports & Analytics βœ… All reports ⏸️ Committee-specific ⏸️ Referral-specific
Settings Management βœ… Full access ❌ No access ❌ No access
2FA Management βœ… Generate/Reset for all ❌ Setup only (self) ❌ Setup only (self)