Skip to content

Commit

Permalink
PR remark #719
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent FAYOLLE committed Nov 17, 2023
1 parent 870bf3a commit 91090bf
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions app/server/lib/ExportTableSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from 'express';
import {ApiError} from 'app/common/ApiError';
import {ActiveDoc} from 'app/server/lib/ActiveDoc';
import {DownloadOptions, ExportColumn, ExportHeader, exportTable} from 'app/server/lib/Export';
import {DownloadOptions, ExportColumn, exportTable} from 'app/server/lib/Export';

interface FrictionlessFormat {
name: string;
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function collectTableSchemaInFrictionlessFormat(
req: express.Request,
options: DownloadOptions
): Promise<FrictionlessFormat> {
const {tableId} = options;
const {tableId, header} = options;
if (!activeDoc.docData) {
throw new Error('No docData in active document');
}
Expand All @@ -50,24 +50,15 @@ export async function collectTableSchemaInFrictionlessFormat(
throw new ApiError(`Table ${tableId} not found.`, 404);
}

const data = await exportTable(activeDoc, tableRef, req);
const tableSchema = columnsToTableSchema(tableId, data, {locale: settings.locale, header: options.header});
return tableSchema;
}

function columnsToTableSchema(
tableId: string,
{tableName, columns}: {tableName: string, columns: ExportColumn[]},
{locale, header = "label"}: {locale: string, header?: ExportHeader},
): FrictionlessFormat {
const {tableName, columns} = await exportTable(activeDoc, tableRef, req);
return {
name: tableId.toLowerCase().replace(/_/g, '-'),
title: tableName,
schema: {
fields: columns.map(col => ({
name: col[header],
name: col[header || "label"],
...(col.description ? {description: col.description} : {}),
...buildTypeField(col, locale),
...buildTypeField(col, settings.locale),
})),
}
};
Expand Down

0 comments on commit 91090bf

Please sign in to comment.