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
1 changed files with 4 additions and 0 deletions

View File

@ -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)
}