api: Support for decimal values in measures.

This commit is contained in:
Jonathan Bernard 2020-02-16 23:20:02 -06:00
parent 3e2faf9554
commit adddef3188
5 changed files with 12 additions and 7 deletions

View File

@ -17,5 +17,5 @@ requires @["nim >= 0.19.4", "bcrypt", "docopt >= 0.6.8", "isaac >= 0.1.3",
"jester >= 0.4.3", "jwt", "tempfile", "uuids >= 0.1.10" ]
requires "https://git.jdb-labs.com/jdb/nim-cli-utils.git >= 0.6.3"
requires "https://git.jdb-labs.com/jdb/nim-time-utils.git >= 0.5.0"
requires "https://git.jdb-labs.com/jdb-labs/fiber-orm-nim.git >= 0.2.0"
requires "https://git.jdb-labs.com/jdb/nim-time-utils.git >= 0.5.2"
requires "https://git.jdb-labs.com/jdb-labs/fiber-orm-nim.git >= 0.3.0"

View File

@ -1,7 +1,8 @@
import asyncdispatch, base64, jester, json, jwt, logging, options, sequtils,
strutils, times, uuids
times, uuids
from unicode import capitalize
import timeutils except `<`
import strutils except capitalize
import timeutils
import ./db, ./configuration, ./models, ./service, ./version
@ -476,7 +477,7 @@ proc start*(ctx: PMApiContext): void =
let newMeasurement = Measurement(
measureId: measure.id,
value: jsonBody.getOrFail("value").getInt,
value: jsonBody.getOrFail("value").getFloat,
timestamp:
if jsonBody.hasKey("timestamp"): jsonBody["timestamp"].getStr.parseIso8601.utc
else: getTime().utc,
@ -515,7 +516,7 @@ proc start*(ctx: PMApiContext): void =
let measure = ctx.getMeasureForSlug(session.user.id, @"slug")
var measurement = ctx.getMeasurementForMeasure(measure.id, parseUUID(@"id"))
let jsonBody = parseJson(request.body)
if jsonBody.hasKey("value"): measurement.value = jsonBody["value"].getInt
if jsonBody.hasKey("value"): measurement.value = jsonBody["value"].getFloat
if jsonBody.hasKey("timestamp"): measurement.timestamp = jsonBody["timestamp"].getStr.parseIso8601
if jsonBody.hasKey("extData"): measurement.extData = jsonBody["extData"]
jsonResp($(%ctx.db.updateMeasurement(measurement)))

View File

@ -28,7 +28,7 @@ type
Measurement* = object
id*: UUID
measureId*: UUID
value*: int
value*: float
timestamp*: DateTime
extData*: JsonNode

View File

@ -0,0 +1,2 @@
-- DOWN script for measure-value-is-numeric (20200216230431)
alter table "measurements" alter column "value" type integer;

View File

@ -0,0 +1,2 @@
-- UP script for measure-value-is-numeric (20200216230431)
alter table "measurements" alter column "value" type numeric;