mirror of
https://github.com/cupcakearmy/ora.git
synced 2024-12-22 08:06:28 +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 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user