feat: add tenant import console

This commit is contained in:
Codex
2026-06-29 13:35:34 +08:00
parent 65905aaf8f
commit 93ec1a07d2
13 changed files with 623 additions and 30 deletions

View File

@@ -122,6 +122,47 @@ export interface ImportTemplateItem {
fields?: Record<string, unknown>[];
}
export interface ImportPreviewResult {
job?: {
id: string;
status?: string;
totalCount?: number;
validCount?: number;
errorCount?: number;
warningCount?: number;
};
items?: Array<{
rowNo?: number;
status?: string;
externalId?: string | null;
normalized?: Record<string, unknown> | null;
issues?: ImportIssueItem[];
}>;
issues?: ImportIssueItem[];
}
export type ImportType = 'questions' | 'vocabulary' | 'handbook' | 'scoreline' | 'videos';
export type ImportSourceFormat = 'json' | 'csv' | 'excel';
export interface ImportRequestBody {
sourceFormat?: ImportSourceFormat;
sourceName?: string;
payload?: unknown;
items?: unknown[];
csvText?: string;
fileBase64?: string;
allowPartial?: boolean;
executionMode?: 'sync' | 'async';
previewJobId?: string;
jobId?: string;
regionId?: string;
entryId?: string;
contentNodeId?: string;
collectionId?: string;
fieldMappingOverrides?: Record<string, string[]>;
fieldMappingPreset?: ImportFieldMapping | null;
}
export interface CouponItem {
id: string;
code: string;
@@ -239,6 +280,20 @@ export async function loadImportTemplate(importType: string, format: 'json' | 'c
});
}
export async function previewContentImport(importType: ImportType, body: ImportRequestBody) {
return apiRequest<ImportPreviewResult>(`/api/tenant-content/imports/preview/${importType}`, {
method: 'POST',
body,
});
}
export async function executeContentImport(importType: ImportType, body: ImportRequestBody) {
return apiRequest<{ item?: Record<string, unknown>; preview?: ImportPreviewResult }>(`/api/tenant-content/imports/${importType}`, {
method: 'POST',
body,
});
}
export async function loadCoupons() {
return apiRequest<{ items?: CouponItem[] }>('/api/tenant-admin/coupons');
}