This commit is contained in:
Martin McKeaveney 2020-06-25 22:43:10 +01:00
parent 63fc10e1e0
commit fb382329b8
2 changed files with 5 additions and 6 deletions

View File

@ -1,7 +1,6 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import api from "../api" import api from "../api"
import { update } from "lodash"
export const getBackendUiStore = () => { export const getBackendUiStore = () => {
const INITIAL_BACKEND_UI_STATE = { const INITIAL_BACKEND_UI_STATE = {
@ -82,7 +81,7 @@ export const getBackendUiStore = () => {
} }
const SAVE_MODEL_URL = `/api/models` const SAVE_MODEL_URL = `/api/models`
console.log(updatedModel); console.log(updatedModel)
const response = await api.post(SAVE_MODEL_URL, updatedModel) const response = await api.post(SAVE_MODEL_URL, updatedModel)
const savedModel = await response.json() const savedModel = await response.json()
await store.actions.models.fetch() await store.actions.models.fetch()

View File

@ -24,12 +24,12 @@ exports.save = async function(ctx) {
...ctx.request.body, ...ctx.request.body,
} }
// update renamed record fields when model is updated // update renamed record fields when model is updated
const { _rename } = modelToSave const { _rename } = modelToSave
if (_rename) { if (_rename) {
const records = await db.query(`database/all_${modelToSave._id}`, { const records = await db.query(`database/all_${modelToSave._id}`, {
include_docs: true include_docs: true,
}); })
const docs = records.rows.map(({ doc }) => { const docs = records.rows.map(({ doc }) => {
doc[_rename.updated] = doc[_rename.old] doc[_rename.updated] = doc[_rename.old]
delete doc[_rename.old] delete doc[_rename.old]
@ -55,7 +55,7 @@ exports.save = async function(ctx) {
modelId: modelToSave._id, modelId: modelToSave._id,
constraints: { constraints: {
type: "array", type: "array",
} },
} }
await db.put(linkedModel) await db.put(linkedModel)
} }