validate input

This commit is contained in:
cupcakearmy 2021-11-23 01:49:20 +01:00
parent 2fbdea00a6
commit a4e0bf1532
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F

View File

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