Skip to content

Commit 531a4b3

Browse files
committed
Fix the import function parameters
1 parent 4ee8795 commit 531a4b3

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

services/api/src/service/csvImport.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ export async function processCsvImport(props: ProcessCsvImportProps) {
149149
db: props.db,
150150
voteBuffer: props.voteBuffer,
151151
importedPolisConversation,
152-
polisUrl: "", // Empty for CSV imports
153-
polisUrlType: "conversation",
152+
importConfig: {
153+
method: "csv",
154+
},
154155
proof: props.proof,
155156
didWrite: props.didWrite,
156157
authorId: props.authorId,
157158
postAsOrganization: props.postAsOrganization,
158159
indexConversationAt: props.indexConversationAt,
159160
isLoginRequired: props.isLoginRequired,
160161
isIndexed: props.isIndexed,
161-
importMethod: "csv",
162162
});
163163
}

services/api/src/service/import.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,51 @@ import {
1111
MAX_LENGTH_TITLE,
1212
toUnionUndefined,
1313
} from "@/shared/shared.js";
14-
import {
15-
conversationTable,
16-
conversationUpdateQueueTable,
17-
} from "@/shared-backend/schema.js";
14+
import { conversationUpdateQueueTable } from "@/shared-backend/schema.js";
1815
import { nowZeroMs } from "@/shared/util.js";
19-
import { eq } from "drizzle-orm";
2016
import type { VoteBuffer } from "./voteBuffer.js";
2117

18+
// URL import configuration
19+
export interface UrlImportConfig {
20+
method: "url";
21+
polisUrl: string;
22+
polisUrlType: "report" | "conversation";
23+
}
24+
25+
// CSV import configuration
26+
export interface CsvImportConfig {
27+
method: "csv";
28+
}
29+
30+
// Discriminated union for import configuration
31+
export type ImportConfig = UrlImportConfig | CsvImportConfig;
32+
2233
interface LoadImportedPolisConversationProps {
2334
db: PostgresDatabase;
2435
voteBuffer: VoteBuffer;
25-
polisUrl: string;
26-
polisUrlType: "report" | "conversation";
2736
importedPolisConversation: ImportPolisResults;
37+
importConfig: ImportConfig;
2838
proof: string;
2939
didWrite: string;
3040
authorId: string;
3141
postAsOrganization: string | undefined;
3242
indexConversationAt?: string;
3343
isLoginRequired: boolean;
3444
isIndexed: boolean;
35-
importMethod: "url" | "csv";
3645
}
3746

3847
export async function loadImportedPolisConversation({
3948
db,
4049
voteBuffer,
4150
importedPolisConversation,
42-
polisUrl,
43-
polisUrlType,
51+
importConfig,
4452
proof,
4553
didWrite,
4654
authorId,
4755
postAsOrganization,
4856
indexConversationAt,
4957
isLoginRequired,
5058
isIndexed,
51-
importMethod,
5259
}: LoadImportedPolisConversationProps): Promise<ConversationIds> {
5360
const now = nowZeroMs();
5461
// create conversation
@@ -74,7 +81,7 @@ export async function loadImportedPolisConversation({
7481
let conversationBody = `${trimmedBody}<br /><br />--------------`;
7582

7683
// Handle messaging based on import method
77-
if (importMethod === "csv") {
84+
if (importConfig.method === "csv") {
7885
// CSV imports
7986
conversationBody = `${conversationBody}<br />This conversation was imported from Polis CSV files.`;
8087
// For CSV imports, link_url might be available from summary.csv
@@ -85,8 +92,8 @@ export async function loadImportedPolisConversation({
8592
}
8693
} else {
8794
// URL imports (existing behavior)
88-
if (polisUrlType === "conversation") {
89-
conversationUrl = polisUrl;
95+
if (importConfig.polisUrlType === "conversation") {
96+
conversationUrl = importConfig.polisUrl;
9097
conversationBody = `${conversationBody}<br />This conversation was initially imported from ${conversationUrl}.`;
9198
reportUrl =
9299
importedPolisConversation.report_id !== null
@@ -102,7 +109,7 @@ export async function loadImportedPolisConversation({
102109
null
103110
? `https://pol.is/${String(importedPolisConversation.conversation_data.conversation_id)}`
104111
: undefined); // should never be undefined, but as we rely on external systems we don't control, better safe than sorry
105-
reportUrl = polisUrl;
112+
reportUrl = importConfig.polisUrl;
106113
conversationBody = `${conversationBody}<br />This conversation was initially imported from ${reportUrl}.`;
107114
if (conversationUrl !== undefined) {
108115
conversationBody = `${conversationBody}<br />The original conversation url is ${conversationUrl}.`;
@@ -144,12 +151,15 @@ export async function loadImportedPolisConversation({
144151
isIndexed: isIndexed,
145152
isLoginRequired: isLoginRequired,
146153
seedOpinionList: [],
147-
importUrl: importMethod === "csv" ? undefined : polisUrl,
154+
importUrl:
155+
importConfig.method === "csv"
156+
? undefined
157+
: importConfig.polisUrl,
148158
importConversationUrl: conversationUrl,
149159
importExportUrl: reportUrl,
150160
importCreatedAt: importCreatedAt,
151161
importAuthor: toUnionUndefined(ownername),
152-
importMethod: importMethod,
162+
importMethod: importConfig.method,
153163
});
154164
try {
155165
const {

services/api/src/service/post.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { eq, sql, and } from "drizzle-orm";
1212
import type { ImportConversationResponse } from "@/shared/types/dto.js";
1313
import { generateRandomSlugId } from "@/crypto.js";
14-
import { log, config } from "@/app.js";
14+
import { log } from "@/app.js";
1515
import { useCommonPost } from "./common.js";
1616
import { httpErrors } from "@fastify/sensible";
1717
import type { ExtendedConversation, PolisUrl } from "@/shared/types/zod.js";
@@ -108,16 +108,18 @@ export async function importConversation({
108108
db,
109109
voteBuffer,
110110
importedPolisConversation,
111-
polisUrlType,
112-
polisUrl,
111+
importConfig: {
112+
method: "url",
113+
polisUrl,
114+
polisUrlType,
115+
},
113116
proof: proof,
114117
didWrite: didWrite,
115118
authorId: authorId,
116119
postAsOrganization: postAsOrganization,
117120
indexConversationAt,
118121
isLoginRequired,
119122
isIndexed,
120-
importMethod: "url",
121123
});
122124
return {
123125
conversationSlugId: conversationSlugId,

0 commit comments

Comments
 (0)