@@ -11,14 +11,14 @@ import {
1111} from "~/utils/supabase/apiUtils" ;
1212import { Tables , TablesInsert } from "~/utils/supabase/types.gen" ;
1313
14- type DiscourseSpaceDataInput = TablesInsert < "DiscourseSpace " > ;
15- type DiscourseSpaceRecord = Tables < "DiscourseSpace " > ;
14+ type SpaceDataInput = TablesInsert < "Space " > ;
15+ type SpaceRecord = Tables < "Space " > ;
1616
1717// Renamed and refactored helper function
18- const processAndGetOrCreateDiscourseSpace = async (
18+ const processAndGetOrCreateSpace = async (
1919 supabasePromise : ReturnType < typeof createClient > ,
20- data : DiscourseSpaceDataInput ,
21- ) : Promise < GetOrCreateEntityResult < DiscourseSpaceRecord > > => {
20+ data : SpaceDataInput ,
21+ ) : Promise < GetOrCreateEntityResult < SpaceRecord > > => {
2222 const { name, url, discourse_platform_id } = data ;
2323
2424 // --- Start of validation ---
@@ -56,17 +56,17 @@ const processAndGetOrCreateDiscourseSpace = async (
5656 const trimmedName = name . trim ( ) ;
5757 const supabase = await supabasePromise ;
5858
59- const result = await getOrCreateEntity < "DiscourseSpace " > (
59+ const result = await getOrCreateEntity < "Space " > (
6060 supabase ,
61- "DiscourseSpace " ,
61+ "Space " ,
6262 "id, name, url, discourse_platform_id" ,
6363 { url : normalizedUrl , discourse_platform_id : discourse_platform_id } ,
6464 {
6565 name : trimmedName ,
6666 url : normalizedUrl ,
6767 discourse_platform_id : discourse_platform_id ,
6868 } ,
69- "DiscourseSpace " ,
69+ "Space " ,
7070 ) ;
7171
7272 // Custom handling for specific foreign key error related to discourse_platform_id
@@ -79,12 +79,12 @@ const processAndGetOrCreateDiscourseSpace = async (
7979 if (
8080 result . details
8181 . toLowerCase ( )
82- . includes ( "discoursespace_discourse_platform_id_fkey " ) ||
82+ . includes ( "Space_discourse_platform_id_fkey " ) ||
8383 result . details . toLowerCase ( ) . includes ( "discourse_platform_id" )
8484 ) {
8585 return {
8686 ...result ,
87- error : `Invalid discourse_platform_id: No DiscoursePlatform record found for ID ${ discourse_platform_id } .` ,
87+ error : `Invalid discourse_platform_id: No Space record found for ID ${ discourse_platform_id } .` ,
8888 } ;
8989 }
9090 }
@@ -96,7 +96,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
9696 const supabasePromise = createClient ( ) ;
9797
9898 try {
99- const body : DiscourseSpaceDataInput = await request . json ( ) ;
99+ const body : SpaceDataInput = await request . json ( ) ;
100100
101101 // Minimal validation here, more detailed in the helper
102102 if ( ! body || typeof body !== "object" ) {
@@ -106,10 +106,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
106106 } ) ;
107107 }
108108
109- const result = await processAndGetOrCreateDiscourseSpace (
110- supabasePromise ,
111- body ,
112- ) ;
109+ const result = await processAndGetOrCreateSpace ( supabasePromise , body ) ;
113110
114111 return createApiResponse ( request , {
115112 data : result . entity ,
@@ -119,7 +116,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
119116 created : result . created ,
120117 } ) ;
121118 } catch ( e : unknown ) {
122- return handleRouteError ( request , e , "/api/supabase/insert/discourse- space" ) ;
119+ return handleRouteError ( request , e , "/api/supabase/insert/space" ) ;
123120 }
124121} ;
125122
0 commit comments