Move db operations back to db module

This commit is contained in:
Julia Friesel
2018-08-09 11:48:28 +02:00
parent 53328f608b
commit b07a2c8a53
3 changed files with 43 additions and 33 deletions
+4 -4
View File
@@ -1,13 +1,13 @@
import { db } from '../../db'
import { schema } from '../../db'
export default function getColumnNamesForCsv() {
return getPrefixedKeys('CycleDay')
function getPrefixedKeys(schemaName, prefix) {
const schema = db.schema.find(x => x.name === schemaName).properties
return Object.keys(schema).reduce((acc, key) => {
const model = schema[schemaName]
return Object.keys(model).reduce((acc, key) => {
const prefixedKey = prefix ? [prefix, key].join('.') : key
const childSchemaName = schema[key].objectType
const childSchemaName = model[key].objectType
if (!childSchemaName) {
acc.push(prefixedKey)
return acc