feat: create org plan on server

This commit is contained in:
Rotimi Best
2024-07-31 07:18:53 +01:00
parent 8cef8ae651
commit 5af4fd08cd
2 changed files with 6 additions and 1 deletions
@@ -262,8 +262,9 @@ export async function createOrgPlan(params: {
planName: string;
triggeredBy: number;
data: OrganizationPlan['lmz_data'];
supabase: typeof supabase;
}) {
return await supabase.from('organization_plan').insert({
return await params.supabase.from('organization_plan').insert({
activated_at: new Date().toDateString(),
org_id: params.orgId,
triggered_by: params.triggeredBy,
@@ -3,9 +3,12 @@ import crypto from 'crypto';
import { LEMON_SQUEEZY_WEBHOOK_SECRET } from '$env/static/private';
import { createOrgPlan, cancelOrgPlan } from '$lib/utils/services/org';
import { PLAN } from 'shared/src/plans/constants';
import { getServerSupabase } from '$lib/utils/functions/supabase.server';
export async function POST({ request }) {
try {
const supabase = getServerSupabase();
// Catch the event type
const clonedReq = request.clone();
const eventType = request.headers.get('X-Event-Name');
@@ -37,6 +40,7 @@ export async function POST({ request }) {
if (isSuccessful && orgId) {
const { data, error } = await createOrgPlan({
supabase,
orgId,
triggeredBy: parseInt(triggeredBy),
planName: PLAN.EARLY_ADOPTER,