0

I`m trying to change restClient to support mongoDB(replace id to _id).

This is documantation https://marmelab.com/admin-on-rest/FAQ.html#can-i-have-custom-identifiers-primary-keys-for-my-resources. I tried different variants, but with this one it shows "Unexpected token"

This is the screenshot of error

const convertHTTPResponseToREST = (response, type, resource, params) => { const { headers, json } = response; switch (type) { case GET_LIST: return { data: json.map(resource => { ...resource, id: resource._id } ), // here an error with "...resource" total: parseInt(headers.get('content-range').split('/').pop(), 10), }; case UPDATE: case DELETE: case GET_ONE: return { ...json, id: json._id }; case CREATE: return { ...params.data, id: json._id }; default: return json; } }; <Admin title="Dashboard" restClient={convertHTTPResponseToREST('/api')}> </Admin> 

When I use jsonServerRestClient() it works. Maybe there is other way to change id to _id?

2
  • answer - admin-on-rest outdated, use react-admin ... use graphql (over/instead rest) Commented May 26, 2019 at 22:32
  • Property 'restClient' does not exist on type 'IntrinsicAttributes & AdminProps error is apper on my document. Do you know the reason? Commented Feb 8, 2022 at 11:56

1 Answer 1

1

Edited answer:

You need to replace:

data: json.map(resource => { ...resource, id: resource._id }), 

by

data: json.map(resource => ({ ...resource, id: resource._id })), 

Note the additional parenthesis around the returned object

Sign up to request clarification or add additional context in comments.

2 Comments

Actually this problem is not connected with the spread operator because this error appears only on that line. And when I changed values everything was ok, but functionality didn`t work properly. This question is more connected with admin-on-rest.
Edited my answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.