Pull apart settings module

This commit is contained in:
Julia Friesel
2018-09-13 19:05:06 +02:00
parent 3c1653bc8c
commit 88fc3cad09
10 changed files with 317 additions and 286 deletions
+2 -1
View File
@@ -1,9 +1,10 @@
import objectPath from 'object-path'
import { Base64 } from 'js-base64'
import { cycleDaysSortedByDate } from '../../db'
import { getCycleDaysSortedByDate } from '../../db'
import getColumnNamesForCsv from './get-csv-column-names'
export default function makeDataURI() {
const cycleDaysSortedByDate = getCycleDaysSortedByDate()
if (!cycleDaysSortedByDate.length) return null
const csv = transformToCsv(cycleDaysSortedByDate)
+2 -1
View File
@@ -1,9 +1,10 @@
import { schema } from '../../db'
import { getSchema } from '../../db'
export default function getColumnNamesForCsv() {
return getPrefixedKeys('CycleDay')
function getPrefixedKeys(schemaName, prefix) {
const schema = getSchema()
const model = schema[schemaName]
return Object.keys(model).reduce((acc, key) => {
const prefixedKey = prefix ? [prefix, key].join('.') : key
+3 -1
View File
@@ -1,6 +1,6 @@
import csvParser from 'csvtojson'
import isObject from 'isobject'
import { schema, tryToImportWithDelete, tryToImportWithoutDelete } from '../../db'
import { getSchema, tryToImportWithDelete, tryToImportWithoutDelete } from '../../db'
import getColumnNamesForCsv from './get-csv-column-names'
export default async function importCsv(csv, deleteFirst) {
@@ -23,6 +23,7 @@ export default async function importCsv(csv, deleteFirst) {
return Number(val)
}
const schema = getSchema()
const config = {
ignoreEmpty: true,
colParser: getColumnNamesForCsv().reduce((acc, colName) => {
@@ -76,6 +77,7 @@ function putNullForEmptySymptoms(data) {
}
function getDbType(modelProperties, path) {
const schema = getSchema()
if (path.length === 1) return modelProperties[path[0]].type
const modelName = modelProperties[path[0]].objectType
return getDbType(schema[modelName], path.slice(1))