Skip to content

Commit

Permalink
chore(#307): update to use CRUD methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Oct 9, 2021
1 parent 84cc74c commit de763d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-games-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-entity": minor
---

Updated DruxtEntityForm to use new DruxtClient methods
31 changes: 10 additions & 21 deletions packages/entity/src/components/DruxtEntityForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,23 @@ export default {
if (this.submitting) return false
this.submitting = true
let url = this.schema.config.href
let method = 'post'
if (this.entity.id) {
// @todo - Reduce size of payload by only sending changed data.
url = [url, this.entity.id].join('/')
method = 'patch'
let method = 'createResource'
if (this.model.id) {
method = 'updateResource'
}
this.response = await this.$druxt[method](this.model)
// Try to send data to backend, and catch any resulting errors.
try {
this.response = await this.$druxt.axios[method](
url,
{ data: this.model },
{
headers: {
'Content-Type': 'application/vnd.api+json',
},
}
)
// Update the Vuex store.
// Handle the response
if (!this.response.errors) {
const resource = this.response.data.data
// Update the Vuex store.
this.$store.commit('druxt/addResource', { resource })
this.$emit('submit', resource)
} catch (e) {
this.response = (e.response || {}).data || e.message
}
else {
this.$emit('error', this.response)
}
this.submitting = false
},
},
Expand Down

0 comments on commit de763d6

Please sign in to comment.