Skip to content

Commit

Permalink
fix: fixed wrong file property name
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarosław Wasiak committed Oct 11, 2022
1 parent 55836ec commit f4084c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/import.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFileFromRequest, getImporterByFileName } from './utils';
import { ActionHandler, ActionResponse } from 'adminjs';
import util from 'util';
import fs from 'fs';
import util from 'util';
import { getFileFromRequest, getImporterByFileName } from './utils';

const readFile = util.promisify(fs.readFile);

Expand All @@ -13,7 +13,7 @@ export const importHandler: ActionHandler<ActionResponse> = async (
const file = getFileFromRequest(request);
const importer = getImporterByFileName(file.name);

const fileContent = await readFile(file.name);
const fileContent = await readFile(file.path);
await importer(fileContent.toString(), context.resource);

return {};
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
BaseRecord,
BaseResource,
Filter,
ValidationError,
ValidationError
} from 'adminjs';
import { Importer } from './parsers';
import { jsonImporter } from './modules/json/json.importer';
import { csvImporter } from './modules/csv/csv.importer';
import { jsonImporter } from './modules/json/json.importer';
import { xmlImporter } from './modules/xml/xml.importer';
import { Importer } from './parsers';

export const saveRecords = async (
records: Record<string, any>[],
Expand Down Expand Up @@ -52,7 +52,7 @@ export const postActionHandler = (
return handler(request, response, context);
};

export const getFileFromRequest = (request: ActionRequest): File => {
export const getFileFromRequest = (request: ActionRequest) => {
const file = request.payload?.file;

if (!file?.path) {
Expand Down

0 comments on commit f4084c3

Please sign in to comment.