Skip to content

Credit Weekly Reset

This workflow automatically resets weekly credit tracking counters every Monday at midnight (East Africa Time) for users enrolled in active credit modules. It maintains historical credit data, calculates trends, and prepares fresh weekly metrics for ongoing credit management.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

Based on the workflow implementation, this appears to be part of a credit management system that tracks user credit behavior over time. The workflow serves users who are actively participating in credit modules by maintaining their weekly progress metrics and historical credit trends.

How It Works

  1. Schedule Trigger: Every day at 12:05 AM East Africa Time, the workflow checks if it's Monday
  2. Day Validation: Confirms the current day is Monday in Nairobi timezone before proceeding
  3. Database Reset: Updates the creditTracking table for all active credit module users:
    • Increments the week number
    • Shifts historical credit data (moves day1 → day2 → day3)
    • Calculates credit trend (improving/worsening/stable) based on recent history
    • Resets weekly and daily counters to zero
  4. Logging: Records how many users were processed in the reset operation

Workflow Diagram

graph TD
    A[Every Monday Midnight EAT] --> B[Check Monday]
    B --> C[Reset Weekly Counters]
    C --> D[Log Result]

Trigger

  • Type: Schedule Trigger
  • Frequency: Daily at 12:05 AM East Africa Time
  • Actual Execution: Only runs on Mondays (filtered by the Check Monday node)

Nodes Used

Node Name Type Purpose
Every Monday Midnight EAT Schedule Trigger Triggers daily at 12:05 AM EAT
Check Monday Code (JavaScript) Validates current day is Monday in Nairobi timezone
Reset Weekly Counters Postgres Updates credit tracking data for active users
Log Result Code (JavaScript) Logs the number of users processed

External Services & Credentials Required

  • PostgreSQL Database: Stores credit tracking data
    • Credential: "Postgres account" (ID: EJPqF6MDH1ZwAzyv)
    • Required permissions: UPDATE and SELECT on creditTracking table

Environment Variables

No environment variables are explicitly used in this workflow. All configuration is handled through: - Schedule trigger settings (time and frequency) - Database credentials stored in n8n credential system

Data Flow

Input: - Scheduled trigger (no external input data) - Current date/time for Monday validation

Processing: - Timezone conversion to Africa/Nairobi - SQL UPDATE operation on creditTracking table - Historical data shifting and trend calculation

Output: - Updated database records for active credit users - Log entry with count of processed users - Returned data includes: phoneNumber, weekNumber, weeklyRecoveredSoFar, creditLockedTrend

Error Handling

This workflow has minimal error handling: - Monday Check: If not Monday, the workflow stops gracefully by returning an empty array - Database Errors: Will fail at the Postgres node if database is unavailable or query fails - No Retry Logic: Failed executions will not automatically retry

Consider adding error notification nodes for production use.

Known Limitations

  • Timezone Dependency: Relies on JavaScript's timezone conversion which may be affected by system timezone settings
  • Single Database: No failover or backup database handling
  • No Notification: Silent failures - no alerts if the reset doesn't complete
  • Fixed Schedule: Cannot easily adjust timing without modifying the workflow

No related workflows identified from the current context. This workflow likely works alongside: - Daily credit tracking workflows - Credit module progression workflows - User notification systems for credit updates

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance

  2. Configure Database Credential:

    • Create a PostgreSQL credential named "Postgres account"
    • Ensure connection to database containing creditTracking table
    • Verify the credential has UPDATE and SELECT permissions
  3. Verify Database Schema: Ensure your creditTracking table includes these columns:

    • weekNumber, creditLockedDay1/2/3, totalCreditLocked
    • creditLockedTrend, weeklyRecoveredSoFar
    • creditGivenToday, creditRecoveredToday
    • creditModuleActive, creditModuleStage, updatedAt
  4. Test Timezone: Verify the workflow correctly detects Monday in your deployment timezone

  5. Activate Workflow: Enable the workflow to start the weekly schedule

  6. Monitor Execution: Check execution logs on Mondays to confirm successful resets

The workflow will automatically begin running according to its schedule once activated.