92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
/**
|
|
* Script para verificar estrutura da tabela reports
|
|
*/
|
|
|
|
import axios from "axios";
|
|
|
|
const SUPABASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
|
const SUPABASE_ANON_KEY =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
|
|
|
const ADMIN_EMAIL = "riseup@popcode.com.br";
|
|
const ADMIN_PASSWORD = "riseup";
|
|
|
|
async function main() {
|
|
try {
|
|
console.log("🔐 Fazendo login...\n");
|
|
|
|
const loginResponse = await axios.post(
|
|
`${SUPABASE_URL}/auth/v1/token?grant_type=password`,
|
|
{
|
|
email: ADMIN_EMAIL,
|
|
password: ADMIN_PASSWORD,
|
|
},
|
|
{
|
|
headers: {
|
|
apikey: SUPABASE_ANON_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
}
|
|
);
|
|
|
|
const token = loginResponse.data.access_token;
|
|
console.log("✅ Login OK\n");
|
|
|
|
console.log("🔍 Listando relatórios existentes para ver estrutura...\n");
|
|
|
|
const listResponse = await axios.get(
|
|
`${SUPABASE_URL}/rest/v1/reports?select=*&limit=1`,
|
|
{
|
|
headers: {
|
|
apikey: SUPABASE_ANON_KEY,
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
);
|
|
|
|
if (listResponse.data.length > 0) {
|
|
console.log("✅ Estrutura encontrada:");
|
|
console.log(JSON.stringify(listResponse.data[0], null, 2));
|
|
console.log(
|
|
"\nCampos disponíveis:",
|
|
Object.keys(listResponse.data[0]).join(", ")
|
|
);
|
|
return;
|
|
}
|
|
|
|
console.log(
|
|
"⚠️ Nenhum relatório existente. Tentando criar com campos básicos...\n"
|
|
);
|
|
|
|
const relatorioMinimo = {
|
|
titulo: "Teste Estrutura",
|
|
tipo: "consultas",
|
|
};
|
|
|
|
const createResponse = await axios.post(
|
|
`${SUPABASE_URL}/rest/v1/reports`,
|
|
relatorioMinimo,
|
|
{
|
|
headers: {
|
|
apikey: SUPABASE_ANON_KEY,
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": "application/json",
|
|
Prefer: "return=representation",
|
|
},
|
|
}
|
|
);
|
|
|
|
console.log("✅ Relatório criado com sucesso!\n");
|
|
console.log("📋 Estrutura da tabela reports:");
|
|
console.log(JSON.stringify(createResponse.data, null, 2));
|
|
} catch (error) {
|
|
console.error("❌ ERRO:", error.response?.data || error.message);
|
|
if (error.response) {
|
|
console.error("Status:", error.response.status);
|
|
console.error("Data:", JSON.stringify(error.response.data, null, 2));
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|