Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update document example from documentation doesn't seem to work #354

Closed
Emixam23 opened this issue Jun 16, 2020 · 1 comment
Closed

Update document example from documentation doesn't seem to work #354

Emixam23 opened this issue Jun 16, 2020 · 1 comment

Comments

@Emixam23
Copy link

Emixam23 commented Jun 16, 2020

Expected behavior

My document's fields should get updated when I update/edit them

Actual behavior

It doesn't update anything..

Failure Logs

No failure code, getting 304 however since the document doesn't get updated

Context

// Update a Outfit
router.put('/outfitsCollection/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
  console.log(request.params)
  console.log(request.body)
  
  const recordUpdater = new RecordUpdater(outfitsCollection);
  recordUpdater.deserialize(request.body)
    .then(recordToUpdate => {
      console.log("record to update")
      console.log(recordToUpdate)
      return recordUpdater.update(recordToUpdate, request.params.recordId)
    })
    .then(record => {
      console.log("record")
      console.log(record)
      return recordUpdater.serialize(record)
    })
    .then(recordSerialized => {
      console.log("recordSerialized")
      console.log(recordSerialized)
      return response.send(recordSerialized)
    })
    .catch(next);
});

recordToUpdate does contain the fields updated, but it seems that the record updater doesn't do anything, maybe I didn't understand something

Output:

[start] GET /forest/outfitsCollection/5ee736bdddad69bf1041e1d0 200 533 - 74.064 ms
[start] { recordId: '5ee736bdddad69bf1041e1d0' }
[start] {
  data: {
    id: '5ee736bdddad69bf1041e1d0',
    attributes: { Name: 'CarettaVintage - steampunk sunglass' },
    type: 'outfitsCollections'
  }
}
[start] record to update
[start] {
  Name: 'CarettaVintage - steampunk sunglass',
  _id: '5ee736bdddad69bf1041e1d0'
}
[start] record
[start] {
  _id: 5ee736bdddad69bf1041e1d0,
  user_id: 'yyy',
  price: 22500,
  name: 'CarettaVintage - steampunk sunglasses',
  image_url: 'https://i.etsystatic.com/6841870/r/il/0e1dc0/2186442965/il_1588xN.2186442965_6ua2.jpg',
  store_url: 'https://www.etsy.com/fr/listing/767124625/lunettes-de-soleil-steampunk-hommes-chai?awc=7432_1592208804_7986328ba72c5e810e8f82a2043e7bba&utm_medium=affiliate&utm_source=affiliate_window&utm_campaign=fr_buyer&utm_content=433093&utm_term=146067'
}
[start] recordSerialized
[start] {
  data: {
    type: 'outfitsCollection',
    id: '5ee736bdddad69bf1041e1d0',
    attributes: {
      Name: 'CarettaVintage - steampunk sunglasses',
      Price: '225€',
      Store: 'https://www.etsy.com/fr/listing/767124625/lunettes-de-soleil-steampunk-hommes-chai?awc=7432_1592208804_7986328ba72c5e810e8f82a2043e7bba&utm_medium=affiliate&utm_source=affiliate_window&utm_campaign=fr_buyer&utm_content=433093&utm_term=146067',
      'Image URL': 'https://i.etsystatic.com/6841870/r/il/0e1dc0/2186442965/il_1588xN.2186442965_6ua2.jpg',
      _id: 5ee736bdddad69bf1041e1d0
    }
  }
}
[start] PUT /forest/outfitsCollection/5ee736bdddad69bf1041e1d0 200 533 - 86.272 ms
@Emixam23
Copy link
Author

Was missing "Import RecordUpdater"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant