Chore/prettify for joda
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
getSchema,
|
||||
tryToImportWithDelete,
|
||||
tryToImportWithoutDelete,
|
||||
updateCycleStartsForAllCycleDays
|
||||
updateCycleStartsForAllCycleDays,
|
||||
} from '../../db'
|
||||
import getColumnNamesForCsv from './get-csv-column-names'
|
||||
import { LocalDate } from 'js-joda'
|
||||
@@ -12,7 +12,7 @@ import labels from '../../i18n/en/settings'
|
||||
|
||||
export default async function importCsv(csv, deleteFirst) {
|
||||
const parseFuncs = {
|
||||
bool: val => {
|
||||
bool: (val) => {
|
||||
if (val.toLowerCase() === 'true') return true
|
||||
if (val.toLowerCase() === 'false') return false
|
||||
return val
|
||||
@@ -20,7 +20,7 @@ export default async function importCsv(csv, deleteFirst) {
|
||||
int: parseNumberIfPossible,
|
||||
float: parseNumberIfPossible,
|
||||
double: parseNumberIfPossible,
|
||||
string: val => val
|
||||
string: (val) => val,
|
||||
}
|
||||
|
||||
function parseNumberIfPossible(val) {
|
||||
@@ -36,12 +36,12 @@ export default async function importCsv(csv, deleteFirst) {
|
||||
colParser: getColumnNamesForCsv().reduce((acc, colName) => {
|
||||
const path = colName.split('.')
|
||||
const dbType = getDbType(schema.CycleDay, path)
|
||||
acc[colName] = item => {
|
||||
acc[colName] = (item) => {
|
||||
if (item === '') return null
|
||||
return parseFuncs[dbType](item)
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
}, {}),
|
||||
}
|
||||
|
||||
const cycleDays = await csvParser(config)
|
||||
@@ -62,9 +62,11 @@ export default async function importCsv(csv, deleteFirst) {
|
||||
|
||||
function validateHeaders(headers) {
|
||||
const expectedHeaders = getColumnNamesForCsv()
|
||||
if (!headers.every(header => {
|
||||
return expectedHeaders.indexOf(header) > -1
|
||||
})) {
|
||||
if (
|
||||
!headers.every((header) => {
|
||||
return expectedHeaders.indexOf(header) > -1
|
||||
})
|
||||
) {
|
||||
const msg = `Expected CSV column titles to be ${expectedHeaders.join()}`
|
||||
throw new Error(msg)
|
||||
}
|
||||
@@ -76,7 +78,7 @@ function putNullForEmptySymptoms(data) {
|
||||
function replaceWithNullIfAllPropertiesAreNull(obj) {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
if (!isObject(obj[key])) return
|
||||
if (Object.values(obj[key]).every(val => val === null)) {
|
||||
if (Object.values(obj[key]).every((val) => val === null)) {
|
||||
obj[key] = null
|
||||
return
|
||||
}
|
||||
@@ -97,8 +99,11 @@ function throwIfFutureData(cycleDays) {
|
||||
for (const i in cycleDays) {
|
||||
const day = cycleDays[i]
|
||||
// notes are allowed for future dates but everything else isn't
|
||||
if (day.date > today && Object.keys(day).some(symptom => symptom != 'date' && symptom != 'note')) {
|
||||
if (
|
||||
day.date > today &&
|
||||
Object.keys(day).some((symptom) => symptom != 'date' && symptom != 'note')
|
||||
) {
|
||||
throw new Error(labels.import.errors.futureEdit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user