feat: create org plan on server
This commit is contained in:
@@ -262,8 +262,9 @@ export async function createOrgPlan(params: {
|
|||||||
planName: string;
|
planName: string;
|
||||||
triggeredBy: number;
|
triggeredBy: number;
|
||||||
data: OrganizationPlan['lmz_data'];
|
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(),
|
activated_at: new Date().toDateString(),
|
||||||
org_id: params.orgId,
|
org_id: params.orgId,
|
||||||
triggered_by: params.triggeredBy,
|
triggered_by: params.triggeredBy,
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ import crypto from 'crypto';
|
|||||||
import { LEMON_SQUEEZY_WEBHOOK_SECRET } from '$env/static/private';
|
import { LEMON_SQUEEZY_WEBHOOK_SECRET } from '$env/static/private';
|
||||||
import { createOrgPlan, cancelOrgPlan } from '$lib/utils/services/org';
|
import { createOrgPlan, cancelOrgPlan } from '$lib/utils/services/org';
|
||||||
import { PLAN } from 'shared/src/plans/constants';
|
import { PLAN } from 'shared/src/plans/constants';
|
||||||
|
import { getServerSupabase } from '$lib/utils/functions/supabase.server';
|
||||||
|
|
||||||
export async function POST({ request }) {
|
export async function POST({ request }) {
|
||||||
try {
|
try {
|
||||||
|
const supabase = getServerSupabase();
|
||||||
|
|
||||||
// Catch the event type
|
// Catch the event type
|
||||||
const clonedReq = request.clone();
|
const clonedReq = request.clone();
|
||||||
const eventType = request.headers.get('X-Event-Name');
|
const eventType = request.headers.get('X-Event-Name');
|
||||||
@@ -37,6 +40,7 @@ export async function POST({ request }) {
|
|||||||
|
|
||||||
if (isSuccessful && orgId) {
|
if (isSuccessful && orgId) {
|
||||||
const { data, error } = await createOrgPlan({
|
const { data, error } = await createOrgPlan({
|
||||||
|
supabase,
|
||||||
orgId,
|
orgId,
|
||||||
triggeredBy: parseInt(triggeredBy),
|
triggeredBy: parseInt(triggeredBy),
|
||||||
planName: PLAN.EARLY_ADOPTER,
|
planName: PLAN.EARLY_ADOPTER,
|
||||||
|
|||||||
Reference in New Issue
Block a user