From 5f88f3d53b4170f0183f65c83568b4b1756b6715 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sat, 4 Jan 2020 19:03:20 -0500 Subject: [PATCH] creating entities basics --- src/_services/system.service.js | 19 ++++++++++++------- src/_store/system.module.js | 4 ++-- src/admin/ModelSetupPage.vue | 7 ++++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/_services/system.service.js b/src/_services/system.service.js index 22f965a..5c822c7 100644 --- a/src/_services/system.service.js +++ b/src/_services/system.service.js @@ -7,6 +7,7 @@ export const systemService = { loadSystemConfigs, loadEntityConfigs, search, + createEntity, loadMessages, loadTimezones, detectTimezone, @@ -47,19 +48,23 @@ function search(type, query) { .then(config => { return config; }); } -function createEntity(config, json, messages, errors) { +function createEntity(entityConfig, json, messages, errors) { + console.log('createEntity: sending json='+json); let requestOptions = null; - if (config.createMethod) { - if (config.createMethod === 'PUT') { + if (entityConfig.createMethod && entityConfig.createUri) { + if (entityConfig.createMethod === 'PUT') { requestOptions = util.putJsonWithAuth(json); - } else if (config.createMethod === 'POST') { + } else if (entityConfig.createMethod === 'POST') { requestOptions = util.putJsonWithAuth(json); + } else { + return Promise.reject("invalid createMethod: " + entityConfig.createMethod); } + } else { + return Promise.reject("no createMethod"); } - if (requestOptions === null) requestOptions = util.putJsonWithAuth(json); - return fetch(`${config.apiUrl}/${config.createUri}`, requestOptions) + return fetch(`${config.apiUrl}${entityConfig.createUri}`, requestOptions) .then(util.handleCrudResponse(messages, errors)) - .then(config => { return config; }); + .then(entity => { return entity; }); } function loadMessages(group, locale) { diff --git a/src/_store/system.module.js b/src/_store/system.module.js index b04e6b5..0d4106d 100644 --- a/src/_store/system.module.js +++ b/src/_store/system.module.js @@ -88,9 +88,9 @@ const actions = { error => commit('searchFailure', error) ); }, - createEntity({ commit }, type, json, messages, errors) { + createEntity({ commit }, {entityConfig, json, messages, errors}) { commit('createEntityRequest'); - systemService.createEntity(state.entityConfigs[type], json, messages, errors) + systemService.createEntity(entityConfig, json, messages, errors) .then( entity => commit('createEntitySuccess', entity), error => commit('createEntityFailure', error) diff --git a/src/admin/ModelSetupPage.vue b/src/admin/ModelSetupPage.vue index c77f9de..a14656d 100644 --- a/src/admin/ModelSetupPage.vue +++ b/src/admin/ModelSetupPage.vue @@ -13,7 +13,7 @@
- +
@@ -105,7 +105,8 @@ this.selectedEntity = null; }, createNewEntity() { - this.createEntity(this.type, this.newEntityJson, this.messages, this.errors); + console.log('this.newEntityJson='+this.newEntityJson); + this.createEntity({entityConfig: this.ec[this.lcType], json: this.newEntityJson, messages: this.messages, errors: this.errors}); } }, watch: { @@ -113,7 +114,7 @@ if (configs) this.ec = configs; }, searchResults (results) { - console.log('updating this.results='+JSON.stringify(results)); + // console.log('updating this.results='+JSON.stringify(results)); if (results) this.results = results; } }