Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed wrong file property name #10

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
Filter,
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