Skip to content

Commit 348be33

Browse files
committed
Update with schema changes
1 parent c018a0e commit 348be33

File tree

8 files changed

+528
-528
lines changed

8 files changed

+528
-528
lines changed

apps/website/app/api/supabase/insert/account/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const getOrCreateAccount = async (
6565
} else if (result.details.includes("Account_platform_id_fkey")) {
6666
return {
6767
...result,
68-
error: `Invalid platform_id: No DiscoursePlatform record found for ID ${platform_id}.`,
68+
error: `Invalid platform_id: No Space record found for ID ${platform_id}.`,
6969
};
7070
}
7171
}

apps/website/app/api/supabase/insert/content-embedding/batch/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
outputProcessing,
1515
type ApiInputEmbeddingItem,
1616
type ApiOutputEmbeddingRecord,
17-
} from "../routes";
17+
} from "../route";
1818

1919
const batchInsertEmbeddingsProcess = async (
2020
supabase: Awaited<ReturnType<typeof createClient>>,

apps/website/app/api/supabase/insert/content/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const processAndUpsertContentEntry = async (
104104
// Be more general with FK name if it changes
105105
return {
106106
...result,
107-
error: `Invalid space_id: No DiscourseSpace record found for ID ${space_id}.`,
107+
error: `Invalid space_id: No Space record found for ID ${space_id}.`,
108108
};
109109
}
110110
if (

apps/website/app/api/supabase/insert/person/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const getOrCreateAccountInternal = async (
9393
if (result.details.includes("Account_platform_id_fkey")) {
9494
return {
9595
...result,
96-
error: `Invalid platform_id for Account: No DiscoursePlatform record found for ID ${platformId}.`,
96+
error: `Invalid platform_id for Account: No Space record found for ID ${platformId}.`,
9797
};
9898
}
9999
}

apps/website/app/api/supabase/insert/discourse-platform/route.ts renamed to apps/website/app/api/supabase/insert/platform/route.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
} from "~/utils/supabase/apiUtils";
1212
import { Tables, TablesInsert } from "~/utils/supabase/types.gen";
1313

14-
type DiscoursePlatformDataInput = TablesInsert<"DiscoursePlatform">;
15-
type DiscoursePlatformRecord = Tables<"DiscoursePlatform">;
14+
type SpaceDataInput = TablesInsert<"Space">;
15+
type SpaceRecord = Tables<"Space">;
1616

17-
const getOrCreateDiscoursePlatformFromURL = async (
17+
const getOrCreateSpaceFromURL = async (
1818
supabase: ReturnType<typeof createClient>,
1919
url: string,
20-
): Promise<GetOrCreateEntityResult<DiscoursePlatformRecord>> => {
20+
): Promise<GetOrCreateEntityResult<SpaceRecord>> => {
2121
let platformName: string | null = null;
2222
let platformUrl: string | null = null;
2323
const lowerCaseURL = url.toLowerCase();
@@ -45,21 +45,21 @@ const getOrCreateDiscoursePlatformFromURL = async (
4545
}
4646

4747
const resolvedSupabaseClient = await supabase;
48-
return getOrCreateEntity<"DiscoursePlatform">(
48+
return getOrCreateEntity<"Space">(
4949
resolvedSupabaseClient,
50-
"DiscoursePlatform",
50+
"Space",
5151
"id, name, url",
5252
{ url: platformUrl },
5353
{ name: platformName, url: platformUrl },
54-
"DiscoursePlatform",
54+
"Space",
5555
);
5656
};
5757

5858
export const POST = async (request: NextRequest): Promise<NextResponse> => {
5959
const supabase = createClient();
6060

6161
try {
62-
const body: DiscoursePlatformDataInput = await request.json();
62+
const body: SpaceDataInput = await request.json();
6363
const { url } = body;
6464

6565
if (!url || typeof url !== "string") {
@@ -69,7 +69,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
6969
});
7070
}
7171

72-
const result = await getOrCreateDiscoursePlatformFromURL(supabase, url);
72+
const result = await getOrCreateSpaceFromURL(supabase, url);
7373

7474
return createApiResponse(request, {
7575
data: result.entity,
@@ -79,11 +79,7 @@ export const POST = async (request: NextRequest): Promise<NextResponse> => {
7979
created: result.created,
8080
});
8181
} catch (e: unknown) {
82-
return handleRouteError(
83-
request,
84-
e,
85-
"/api/supabase/insert/discourse-platform",
86-
);
82+
return handleRouteError(request, e, "/api/supabase/insert/platform");
8783
}
8884
};
8985

apps/website/app/api/supabase/insert/discourse-space/route.ts renamed to apps/website/app/api/supabase/insert/space/route.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
} from "~/utils/supabase/apiUtils";
1212
import { 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

Comments
 (0)