[document] implement hh/mm/ss for ToNode HyperdataDocument instance

parent c0b775e0
Pipeline #7770 passed with stages
in 42 minutes and 40 seconds
......@@ -57,8 +57,9 @@ the concatenation of the parameters defined by @shaParameters@.
module Gargantext.Database.Query.Table.Node.Document.Insert
where
import Data.Fixed (Fixed(MkFixed))
import Data.Text qualified as DT (pack, concat, take, filter, toLower)
import Data.Time.Segment (jour)
import Data.Time.Segment qualified as DTS
import Database.PostgreSQL.Simple (FromRow, Query, Only(..))
import Database.PostgreSQL.Simple.FromRow (fromRow, field)
import Database.PostgreSQL.Simple.SqlQQ ( sql )
......@@ -115,7 +116,7 @@ instance InsertDb HyperdataContact
, toField u
, toField p
, toField $ maybe "Contact" (DT.take 255) (Just "Name") -- (_hc_name h)
, toField $ jour 0 1 1 -- TODO put default date
, toField $ DTS.jour (fromIntegral Defaults.year) (fromIntegral Defaults.month) (fromIntegral Defaults.day)
-- , (toField . toJSON) (addUniqId h)
]
......@@ -274,22 +275,32 @@ class ToNode a
toNode :: HasDBid NodeType => UserId -> Maybe ParentId -> a -> Node a
instance ToNode HyperdataDocument where
toNode u p h = Node 0 Nothing (toDBid NodeDocument) u p n date h
toNode u p h = Node { _node_id = 0
, _node_hash_id = Nothing
, _node_typename = toDBid NodeDocument
, _node_user_id = u
, _node_parent_id = p
, _node_name = n
, _node_date = date
, _node_hyperdata = h }
where
n = maybe "No Title" (DT.take 255) (_hd_title h)
date = jour y m d
date = DTS.date y m d hh mn s
-- NOTE: There is no year '0' in postgres, there is year 1 AD and beofre that year 1 BC:
-- select '0001-01-01'::date, '0001-01-01'::date - '1 day'::interval;
-- 0001-01-01 0001-12-31 00:00:00 BC
y = fromIntegral $ fromMaybe Defaults.day $ _hd_publication_year h
y = fromIntegral $ fromMaybe (fromIntegral Defaults.year) $ _hd_publication_year h
m = fromMaybe Defaults.month $ _hd_publication_month h
d = fromMaybe (fromIntegral Defaults.year) $ _hd_publication_day h
d = fromMaybe (fromIntegral Defaults.day) $ _hd_publication_day h
hh = fromMaybe (fromIntegral Defaults.hour) $ _hd_publication_hour h
mn = fromMaybe (fromIntegral Defaults.minute) $ _hd_publication_minute h
s = MkFixed $ fromIntegral $ fromMaybe Defaults.second $ _hd_publication_second h
-- TODO better Node
instance ToNode HyperdataContact where
toNode u p = Node 0 Nothing (toDBid NodeContact) u p "Contact" date
where
date = jour 2020 01 01
date = DTS.jour 2020 01 01
......@@ -21,3 +21,9 @@ month :: Int
month = 1
day :: Int
day = 1
hour :: Int
hour = 0
minute :: Int
minute = 0
second :: Int
second = 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment