Skip to content

Commit c65f9b4

Browse files
committed
refactor(appengine): extract complex queries
- create a new module `Data`, which holds complex database operations - the device_status_from device query has been refactored under DeviceStatus. Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
1 parent cd6ceb3 commit c65f9b4

8 files changed

Lines changed: 1368 additions & 1646 deletions

File tree

apps/astarte_appengine_api/lib/astarte_appengine_api/device/astarte_value.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of Astarte.
33
#
4-
# Copyright 2018 Ispirata Srl
4+
# Copyright 2018 - 2025 SECO Mind Srl
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -51,10 +51,15 @@ defmodule Astarte.AppEngine.API.Device.AstarteValue do
5151
end
5252

5353
def to_json_friendly(value, :datetime, opts) do
54-
if opts[:keep_milliseconds] do
55-
value
56-
else
57-
DateTime.from_unix!(value, :millisecond)
54+
cond do
55+
opts[:keep_milliseconds] ->
56+
value
57+
58+
is_integer(value) ->
59+
DateTime.from_unix!(value, :millisecond)
60+
61+
true ->
62+
DateTime.truncate(value, :millisecond)
5863
end
5964
end
6065

0 commit comments

Comments
 (0)