mirror of
https://github.com/cupcakearmy/ora.git
synced 2024-12-21 23:56:31 +00:00
validate input
This commit is contained in:
parent
2fbdea00a6
commit
a4e0bf1532
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user