Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge changes to fetch.js
Browse files Browse the repository at this point in the history
  • Loading branch information
denisgoryaynov committed Sep 11, 2020
2 parents 39d9553 + a0410ee commit 688f5f5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios'
import { isObject, startsWith, forEach, set, castArray } from 'lodash'
import { isObject, forEach, set, castArray, startsWith } from 'lodash'
import pluralize from 'pluralize'

module.exports = async ({ apiURL, contentType, singleType, jwtToken, queryLimit, reporter }) => {
Expand All @@ -26,12 +26,17 @@ module.exports = async ({ apiURL, contentType, singleType, jwtToken, queryLimit,
*/
const clean = item => {
forEach(item, (value, key) => {
if (startsWith(key, `__`)) {
if (key === `__v`) {
// Remove mongo's __v
delete item[key]
item['strapi' + key] = value
} else if (startsWith(key, `_`)) {
} else if (key === `_id`) {
// Rename mongo's "_id" key to "id".
delete item[key]
item[key.slice(1)] = value
item.id = value
} else if (startsWith(key, '__')) {
// Gatsby reserves double-underscore prefixes – replace prefix with "strapi"
delete item[key]
item[`strapi_${key.slice(2)}`] = value
} else if (isObject(value)) {
item[key] = clean(value)
}
Expand Down

0 comments on commit 688f5f5

Please sign in to comment.