"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUploadedFilesByField = exports.parseDatasetRowPayload = void 0;
const parseDatasetRowPayload = (req) => {
    const body = (req.body ?? {});
    let row = body.row;
    if (typeof row === 'string') {
        try {
            row = JSON.parse(row);
        }
        catch {
            return { parseError: 'Invalid row JSON' };
        }
    }
    if (row !== undefined && (typeof row !== 'object' || row === null || Array.isArray(row))) {
        return { parseError: 'row must be a JSON object' };
    }
    return {
        projectId: body.projectId,
        orgId: body.orgId,
        row: row,
    };
};
exports.parseDatasetRowPayload = parseDatasetRowPayload;
const getUploadedFilesByField = (req) => {
    const files = req.files;
    if (!Array.isArray(files) || files.length === 0) {
        return undefined;
    }
    const map = {};
    for (const f of files) {
        if (f?.fieldname) {
            map[f.fieldname] = f;
        }
    }
    return Object.keys(map).length > 0 ? map : undefined;
};
exports.getUploadedFilesByField = getUploadedFilesByField;
//# sourceMappingURL=parse-dataset-row-request.js.map