Skip to content

Commit

Permalink
fix: Add convertLegacyDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Nov 3, 2019
1 parent b5e930d commit 3785c4a
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions packages/ra-data-amplify-rest/src/index.ts
Expand Up @@ -4,6 +4,7 @@ import {
UPDATE,
DELETE,
LegacyDataProvider,
convertLegacyDataProvider,
} from 'ra-core';

import { buildDataRequest } from './build-data-request';
Expand All @@ -27,54 +28,56 @@ export interface DataProviderOptions extends Partial<BuildDataProviderOptions> {
export default (options: DataProviderOptions): LegacyDataProvider => {
const dataProvider = buildDataProvider({ ...defaultOptions, ...options });

return async (
type: string,
resource: string,
params: Params,
): Promise<any> => {
if (type === UPDATE_MANY) {
const { ids, data, ...otherParams } = params;

if (!ids) return;

const responses = await Promise.all(
ids.map(id =>
dataProvider(UPDATE, resource, {
data: {
return convertLegacyDataProvider(
async (
type: string,
resource: string,
params: Params,
): Promise<any> => {
if (type === UPDATE_MANY) {
const { ids, data, ...otherParams } = params;

if (!ids) return;

const responses = await Promise.all(
ids.map(id =>
dataProvider(UPDATE, resource, {
data: {
id,
...data,
},
...otherParams,
}),
),
);

return {
data: responses.map(response => response.data),
};
}

if (type === DELETE_MANY) {
const { ids, ...otherParams } = params;

if (!ids) return;

const responses = await Promise.all(
ids.map(id =>
dataProvider(DELETE, resource, {
id,
...data,
},
...otherParams,
}),
),
);

return {
data: responses.map(response => response.data),
};
}

if (type === DELETE_MANY) {
const { ids, ...otherParams } = params;

if (!ids) return;

const responses = await Promise.all(
ids.map(id =>
dataProvider(DELETE, resource, {
id,
...otherParams,
}),
),
);

return {
data: responses.map(response => response.data),
};
}

return dataProvider(type, resource, params);
};
...otherParams,
}),
),
);

return {
data: responses.map(response => response.data),
};
}

return dataProvider(type, resource, params);
},
);
};

export { buildDataRequest, parseResponse, buildDataProvider };
Expand Down

0 comments on commit 3785c4a

Please sign in to comment.