Edits history of script submission #22279 for ' Get sales metrics (example) (stripe)'

  • bun
    // Give sales metrics, and allow you to manipulate them on specific date ranges.
    // We use mock data to keep things simple for this example
    // But you can can easily create a script that gets this data from your own database
    
    export async function main() {
      const today = new Date();
      const results = [];
    
      // Sales values that create realistic patterns (weekends lower, some spikes for promotions)
      const baseSales = [1200, 850, 720, 1150, 1180, 1220, 1190, 3850, 3620, 3290,
                         1450, 1280, 890, 1100, 6420, 5890, 5240, 1520, 1380, 1050,
                         920, 1180, 1240, 1210, 1290, 1350, 1180, 1220, 1340, 1410];
    
      for (let i = 29; i >= 0; i--) {
        const date = new Date(today);
        date.setDate(today.getDate() - i);
        const dateStr = date.toISOString().split('T')[0];
        results.push({
          date: dateStr,
          sales: baseSales[29 - i]
        });
      }
    
      return results;
    }
    

    Submitted by tristan795 40 days ago