diff --git a/src/shared/db.js b/src/shared/db.js index 11f17b8..c635d17 100644 --- a/src/shared/db.js +++ b/src/shared/db.js @@ -4,6 +4,8 @@ import Duration from 'dayjs/plugin/duration' import Dexie from 'dexie' import 'dexie-export-import' +import { LogValidator, checkForErrors } from '../shared/validation' + dj.extend(Duration) dj.extend(RelativeTime) @@ -33,6 +35,8 @@ export async function insertLog({ timestamp, host, seconds }) { const saved = await DB.logs.where({ host, timestamp }).first() const data = Object.assign({ host, timestamp, seconds: 0 }, saved) data.seconds += seconds + const error = checkForErrors(LogValidator, data) + if (error) throw new Error(error) await DB.logs.put(data) }