Skip to main content
Version: 1.0.0

monthlyPublishedVariantsReport

Monthly Published Variants Report Template

Function Names: monthlyPublishedVariantsReport / testMonthlyPublishedVariantsReport

Trigger: Scheduler (onSchedule - every Friday at 17:50) / HTTPS (onRequest)

Purpose: Executes a weekly notification (every Friday at 17:50) to monitor SKUs in 'In Pubblicazione' and 'Rev. Cliente' status grouped by brand and batch. Sends summary emails only to Validators and Clients associated with specific brands, avoiding generic notifications to the entire system.

Detailed Functionality​

This Firebase Function performs the following operations in sequence:

1. MainBrands Data Collection​

  • Retrieves all brands from the MainBrands collection in the database
  • For each brand, processes all associated variants to count status occurrences

2. Variants Grouping and Counting​

  • For each brand, groups Variants by batch field
  • Counts variants with status 'In Pubblicazione' (skuPublication)
  • Counts variants with status 'Rev. Cliente' (skuRevClient)
  • Creates brand/batch combinations for reporting

3. Profile Filtering and Brand Association​

  • Retrieves only profiles with role 'Validator' and 'Cliente' from Profiles collection
  • Filters profiles by brand using the list_main_brands field
  • Associates each user with their specific brands for targeted notifications

4. Conditional Email Sending Logic​

Emails are sent ONLY if:

  • There are SKUs to report (skuPublication > 0 OR skuRevClient > 0)
  • There are recipients for that specific brand
  • Brand has associated Validators or Clients in their list_main_brands

5. Email Configuration and Recipients​

  • Primary Recipients (TO): Validators who have the specific brand in their list_main_brands
  • Copy Recipients (CC): Clients who have the specific brand in their list_main_brands
  • Email Service: ZeptoMail with predefined template (MAIL_TEMPLATE_KEY: 13ef.8598f19fbcc5adb.k1.afbab030-45ff-11f0-832a-66e0c45c7bae.1975a0d02b3)
  • Fallback: Nodemailer for error cases

6. Template Data Variables​

The email template receives these merge variables:

  • brandName: Name of the brand
  • batch: Batch identifier
  • skuPublication: Number of SKUs in 'In Pubblicazione' status
  • skuRevClient: Number of SKUs in 'Rev. Cliente' status

7. Automatic Scheduling​

  • Schedule: Every Friday at 17:50 CET (50 17 * * 5)
  • Region: europe-central2
  • Timezone: Europe/Rome

8. Testing Function​

  • HTTP Endpoint: testMonthlyPublishedVariantsReport
  • Method: GET (no parameters required)
  • Purpose: Manual testing with detailed JSON response
  • Behavior: Identical logic but returns comprehensive debugging information

Input (Payload):​

For monthlyPublishedVariantsReport (Scheduled):

Automatic execution - no input required

For testMonthlyPublishedVariantsReport (HTTP):

Method: GET
No body parameters required

Output (Success):​

{
"success": true,
"message": "🧪 Report TEST generato con successo",
"timestamp": "2024-01-19T16:50:00.000Z",
"statistics": {
"totalBrands": 5,
"totalBrandBatchCombinations": 12,
"brandsWithSkuToReport": 8,
"totalProfiles": {
"validators": 3,
"clients": 2
},
"emailResults": {
"sent": 6,
"skipped": 2,
"errors": 0
}
},
"results": [
{
"brandId": "brand123",
"brandName": "Ray-Ban",
"batch": "2024-Q1",
"skuPublication": 15,
"skuRevClient": 3
}
],
"profilesByBrand": {
"brand123": {
"validators": ["validator1@example.com"],
"clients": ["client1@example.com"]
}
},
"emailResults": [
{
"brand": "Ray-Ban",
"batch": "2024-Q1",
"status": "sent",
"skuPublication": 15,
"skuRevClient": 3,
"recipients": {
"to": 1,
"cc": 1,
"validators": ["validator1@example.com"],
"clients": ["client1@example.com"]
}
}
]
}

This output is returned in the HTTP response (Postman, browser, curl)

Testing​

URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/europe-central2/testMonthlyPublishedVariantsReport

Test with Emulator:

  1. Start the Firebase emulator: firebase emulators:start --only functions
  2. Ensure you're using Node.js version 20: nvm use 20
  3. Test with curl:
curl "http://127.0.0.1:5001/arshadesstaging/europe-central2/testMonthlyPublishedVariantsReport"

Postman Testing:

Deploy Command:​

firebase deploy --only functions:monthlyPublishedVariantsReport,functions:testMonthlyPublishedVariantsReport

Production URL:​

monthlyPublishedVariantsReport: https://europe-central2-arshades-7e18a.cloudfunctions.net/monthlyPublishedVariantsReport

Note: This function runs automatically every Friday at 17:50. The URL is for reference only as scheduled functions cannot be called directly.

testMonthlyPublishedVariantsReport: Not deployed to production (test function only)