mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
update
This commit is contained in:
29
dashboard/server/api/integrations/supabase/add.post.ts
Normal file
29
dashboard/server/api/integrations/supabase/add.post.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { SupabaseIntegrationModel } from "@schema/integrations/SupabaseIntegrationSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const project_id = getHeader(event, 'x-pid');
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
if (!project) return;
|
||||
|
||||
const { chart_type, table_name, xField, yMode, from, to, slice, name } = await readBody(event);
|
||||
|
||||
if (!project.premium) {
|
||||
const supabaseIntegrationsCount = await SupabaseIntegrationModel.countDocuments({ project_id });
|
||||
if (supabaseIntegrationsCount > 0) return setResponseStatus(event, 400, 'LIMIT_REACHED');
|
||||
}
|
||||
|
||||
await SupabaseIntegrationModel.create({
|
||||
name,
|
||||
project_id, chart_type,
|
||||
table_name, xField, yMode,
|
||||
from, to, slice,
|
||||
});
|
||||
|
||||
return { ok: true };
|
||||
|
||||
});
|
||||
18
dashboard/server/api/integrations/supabase/get.ts
Normal file
18
dashboard/server/api/integrations/supabase/get.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { SupabaseIntegrationModel } from '@schema/integrations/SupabaseIntegrationSchema';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const project_id = getHeader(event, 'x-pid');
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
if (!project) return;
|
||||
|
||||
const integration_id = getHeader(event, 'x-integration');
|
||||
|
||||
const integration = await SupabaseIntegrationModel.findOne({ _id: integration_id });
|
||||
return integration;
|
||||
|
||||
});
|
||||
16
dashboard/server/api/integrations/supabase/list.ts
Normal file
16
dashboard/server/api/integrations/supabase/list.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { SupabaseIntegrationModel } from '@schema/integrations/SupabaseIntegrationSchema';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const project_id = getHeader(event, 'x-pid');
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
if (!project) return;
|
||||
|
||||
const integrations = await SupabaseIntegrationModel.find({ project_id });
|
||||
return integrations;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user