# Payout Notification System

## Overview

This feature adds support for sending email notifications to both admin and finance team members when a payout request is submitted by a user.

## Features

- Send notification emails to both admin and finance team email addresses
- Toggle notifications on/off for each recipient type through settings
- Test notification emails through a dedicated endpoint

## Configuration

### Settings

The following settings have been added to control notification behavior:

1. `notify_admin_on_payout_request` - Boolean flag (stored as 'true'/'false') to control admin notifications
2. `notify_finance_on_payout_request` - Boolean flag (stored as 'true'/'false') to control finance team notifications
3. `finance_email` - Email address for the finance team (already existed)

### API Endpoints

#### Get Notification Settings

```
GET /settings/notifications
```

Returns:
```json
{
  "emails": {
    "adminEmail": "admin@example.com",
    "financeEmail": "finance@example.com"
  },
  "notifications": {
    "notifyAdminOnPayoutRequest": true,
    "notifyFinanceOnPayoutRequest": true
  }
}
```

#### Update Notification Emails

```
POST /settings/notifications/email
```

Body:
```json
{
  "adminEmail": "new-admin@example.com",
  "financeEmail": "new-finance@example.com"
}
```

#### Update Notification Preferences

```
POST /settings/notifications/preferences
```

Body:
```json
{
  "notifyAdminOnPayoutRequest": true,
  "notifyFinanceOnPayoutRequest": false
}
```

#### Test Notification Email

```
POST /email/test-payout-notification
```

Body:
```json
{
  "email": "test@example.com"
}
```

## Implementation Details

1. Updated `earnings.service.ts` to check notification preferences before sending emails
2. Added `getSetting` and `setSetting` methods to `settings.service.ts`
3. Added new endpoints to `settings.controller.ts` for managing notification preferences
4. Created `email.controller.ts` with a test endpoint
5. Created migration file and script for adding the new settings
