mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:45:23 +02:00
feat: remove MKT and Experiments tabs and all related code
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
9f9c0c2975
commit
76d901fcde
@@ -1,119 +0,0 @@
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import { Experiment, ExperimentCreateInput } from '../types';
|
||||
|
||||
const supabase = createClient(
|
||||
process.env.SUPABASE_URL || '',
|
||||
process.env.SUPABASE_SERVICE_KEY || '',
|
||||
{
|
||||
auth: {
|
||||
autoRefreshToken: false,
|
||||
persistSession: false
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||
|
||||
if (req.method === 'OPTIONS') return res.status(200).end();
|
||||
|
||||
try {
|
||||
// GET - List experiments or get single experiment
|
||||
if (req.method === 'GET') {
|
||||
const { id, status, type, marketplace, asin, dateFrom, dateTo } = req.query;
|
||||
|
||||
let query = supabase.from('experiments').select('*');
|
||||
|
||||
if (id) {
|
||||
const { data, error } = await query.eq('id', id).single();
|
||||
if (error) throw error;
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
// List with filters
|
||||
if (status) {
|
||||
const statuses = Array.isArray(status) ? status : [status];
|
||||
query = query.in('status', statuses);
|
||||
}
|
||||
if (type) {
|
||||
const types = Array.isArray(type) ? type : [type];
|
||||
query = query.in('type', types);
|
||||
}
|
||||
if (marketplace) {
|
||||
const markets = Array.isArray(marketplace) ? marketplace : [marketplace];
|
||||
query = query.in('marketplace', markets);
|
||||
}
|
||||
if (asin) {
|
||||
query = query.contains('asins', [asin]);
|
||||
}
|
||||
if (dateFrom) {
|
||||
query = query.gte('start_date', dateFrom as string);
|
||||
}
|
||||
if (dateTo) {
|
||||
query = query.lte('end_date', dateTo as string);
|
||||
}
|
||||
|
||||
const { data, error } = await query.order('created_at', { ascending: false });
|
||||
if (error) throw error;
|
||||
|
||||
return res.status(200).json(data || []);
|
||||
}
|
||||
|
||||
// POST - Create experiment
|
||||
if (req.method === 'POST') {
|
||||
const input: ExperimentCreateInput = req.body;
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('experiments')
|
||||
.insert([{
|
||||
...input,
|
||||
status: 'planned',
|
||||
created_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
}])
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
return res.status(201).json(data);
|
||||
}
|
||||
|
||||
// PUT - Update experiment
|
||||
if (req.method === 'PUT') {
|
||||
const { id } = req.query;
|
||||
const updates = req.body;
|
||||
console.log('Update payload for id', id, ':', updates);
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('experiments')
|
||||
.update({ ...updates, updated_at: new Date().toISOString() })
|
||||
.eq('id', id)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
// DELETE - Delete experiment
|
||||
if (req.method === 'DELETE') {
|
||||
const { id } = req.query;
|
||||
|
||||
const { error } = await supabase
|
||||
.from('experiments')
|
||||
.delete()
|
||||
.eq('id', id);
|
||||
|
||||
if (error) throw error;
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
|
||||
return res.status(405).json({ error: 'Method not allowed' });
|
||||
} catch (error: any) {
|
||||
console.error('Experiments API error:', error);
|
||||
return res.status(500).json({ error: error.message || 'Internal server error' });
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
|
||||
const FILE_URLS: Record<string, string> = {
|
||||
deals: "https://www.dropbox.com/scl/fi/3mm5m4e04myhqt59piefs/Deals-Amazon-2025.xlsx?rlkey=6llr0xhs6di0c3d8o96ashzmv&st=ggu0z7hu&dl=1",
|
||||
promos: "https://www.dropbox.com/scl/fi/ufhej9do9w839oyyfrpk3/Promos_Amazon_2025_all-countries.xlsx?rlkey=4foano9dt5h3sl58l35vqg89d&st=wu0t56wh&dl=1",
|
||||
chargebacks: "https://www.dropbox.com/scl/fi/m2qr2cxhtgkc48acjrrgx/Amazon-Operational-Chargebacks-2025.xlsx?rlkey=vlrz4qfydsjtikgh0ylivocjq&st=zdhmjvaz&dl=1",
|
||||
};
|
||||
|
||||
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
const file = req.query.file as string;
|
||||
const url = FILE_URLS[file];
|
||||
|
||||
if (!url) {
|
||||
return res.status(400).json({ error: `Unknown file: "${file}". Valid options: deals, promos, chargebacks` });
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`[fetch-mkt-data] Fetching ${file} from Dropbox...`);
|
||||
const response = await fetch(url, {
|
||||
cache: 'no-store',
|
||||
headers: { 'Pragma': 'no-cache', 'Cache-Control': 'no-cache' }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Dropbox responded with ${response.status}`);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
console.log(`[fetch-mkt-data] Successfully fetched ${file}, size:`, buffer.byteLength);
|
||||
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.status(200).send(Buffer.from(buffer));
|
||||
} catch (error: any) {
|
||||
console.error(`[fetch-mkt-data] Error fetching ${file}:`, error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user