Skip to content
Snippets Groups Projects
Commit 8701abb7 authored by Julia Friesel's avatar Julia Friesel
Browse files

Merge branch '151-in-import-error-when-future-edit-for-something-other-than-a-note' into 'master'

Show error message when future data edit

Closes #151

See merge request bloodyhealth/drip!161
parents ab3ca689 d8ce68d1
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,8 @@ export default { ...@@ -47,7 +47,8 @@ export default {
deleteOption: 'Import and delete existing', deleteOption: 'Import and delete existing',
errors: { errors: {
couldNotOpenFile: 'Could not open file', couldNotOpenFile: 'Could not open file',
postFix: 'No data was imported or changed' postFix: 'No data was imported or changed',
futureEdit: 'Future dates may only contain a note, no other symptoms'
}, },
success: { success: {
message: 'Data successfully imported' message: 'Data successfully imported'
......
...@@ -7,6 +7,8 @@ import { ...@@ -7,6 +7,8 @@ import {
updateCycleStartsForAllCycleDays updateCycleStartsForAllCycleDays
} from '../../db' } from '../../db'
import getColumnNamesForCsv from './get-csv-column-names' import getColumnNamesForCsv from './get-csv-column-names'
import { LocalDate } from 'js-joda'
import labels from '../../i18n/en/settings'
export default async function importCsv(csv, deleteFirst) { export default async function importCsv(csv, deleteFirst) {
const parseFuncs = { const parseFuncs = {
...@@ -48,6 +50,7 @@ export default async function importCsv(csv, deleteFirst) { ...@@ -48,6 +50,7 @@ export default async function importCsv(csv, deleteFirst) {
//remove symptoms where all fields are null //remove symptoms where all fields are null
putNullForEmptySymptoms(cycleDays) putNullForEmptySymptoms(cycleDays)
throwIfFutureData(cycleDays)
if (deleteFirst) { if (deleteFirst) {
tryToImportWithDelete(cycleDays) tryToImportWithDelete(cycleDays)
...@@ -87,4 +90,15 @@ function getDbType(modelProperties, path) { ...@@ -87,4 +90,15 @@ function getDbType(modelProperties, path) {
if (path.length === 1) return modelProperties[path[0]].type if (path.length === 1) return modelProperties[path[0]].type
const modelName = modelProperties[path[0]].objectType const modelName = modelProperties[path[0]].objectType
return getDbType(schema[modelName], path.slice(1)) return getDbType(schema[modelName], path.slice(1))
}
function throwIfFutureData(cycleDays) {
const today = LocalDate.now().toString()
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')) {
throw new Error(labels.import.errors.futureEdit)
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment