api: Support for decimal values in measures.
This commit is contained in:
parent
3e2faf9554
commit
adddef3188
@ -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"
|
||||
|
@ -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)))
|
||||
|
@ -28,7 +28,7 @@ type
|
||||
Measurement* = object
|
||||
id*: UUID
|
||||
measureId*: UUID
|
||||
value*: int
|
||||
value*: float
|
||||
timestamp*: DateTime
|
||||
extData*: JsonNode
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- DOWN script for measure-value-is-numeric (20200216230431)
|
||||
alter table "measurements" alter column "value" type integer;
|
@ -0,0 +1,2 @@
|
||||
-- UP script for measure-value-is-numeric (20200216230431)
|
||||
alter table "measurements" alter column "value" type numeric;
|
Loading…
x
Reference in New Issue
Block a user