Skip to content

Commit

Permalink
fix: Safer reads on entry fields properties inside getLinks() method …
Browse files Browse the repository at this point in the history
…for Offline API (#180)
  • Loading branch information
yanneves authored and Khaledgarbaya committed May 10, 2019
1 parent e93634a commit eda8096
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/offline-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { omit, compact } from 'lodash'
import { omit, compact, get } from 'lodash'
import FieldDeletionValidator from './validator/field-deletion'
import { ContentTypePayloadValidator } from './validator/content-type'
import { ContentType, EditorInterfaces } from '../entities/content-type'
Expand Down Expand Up @@ -421,14 +421,14 @@ class OfflineAPI {
const fields = entry.fields
for (let key of Object.keys(fields)) {
for (let locale of locales) {
const field = entry.fields[key][locale]
if (field instanceof Object && field.sys instanceof Object && field.sys.id === childId) {
const field = get(entry.fields, `${key}.${locale}`)
if (get(field, 'sys.id') === childId) {
links.push(new Link(entry, key, locale))
}
if (field instanceof Array) {
const fieldArray = field as any[]
fieldArray.forEach((fieldEntry, index) => {
if (fieldEntry instanceof Object && fieldEntry.sys instanceof Object && fieldEntry.sys.id === childId) {
if (get(fieldEntry, 'sys.id') === childId) {
links.push(new Link(entry, key, locale, index))
}
})
Expand Down

0 comments on commit eda8096

Please sign in to comment.