diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/app/Main.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/backend/app/Main.hs b/backend/app/Main.hs index 917a6d9..0985a3a 100644 --- a/backend/app/Main.hs +++ b/backend/app/Main.hs @@ -349,13 +349,15 @@ restApi root ref repoT app req resp = do o <- J.throwDecode @J.Object =<< W.lazyRequestBody req resp . W.responseLBS W.status200 [] . J.encode . headMay =<< ( Q.withStore root ref do - Q.query (fromString (printf "UPDATE %s SET %s WHERE %s.$fileName == \"%s\"" c (LB.toString (J.encode o)) c i)) + _ <- Q.query (fromString (printf "UPDATE %s SET %s WHERE %s.$fileName == \"%s\"" c (LB.toString (J.encode o)) c i)) + [J.Object r] <- Q.query (fromString (printf "SELECT %s FROM %s WHERE %s.$fileName == \"%s\"" c c c i)) + _ <- Q.query (fromString (printf "INSERT %s INTO %s" (LB.toString (J.encode (dropNulls r))) c)) Q.query (fromString (printf "SELECT %s FROM %s WHERE %s.$fileName == \"%s\"" c c c i)) ) ("POST", ["collection", c]) -> do when (not (sameCommit lastCompatibleCommit lastCommit)) $ error "not implemented" i <- ((<> ".json") . U.toText) <$> getUUID - o <- J.throwDecode @J.Object =<< W.lazyRequestBody req + o <- fmap dropNulls . J.throwDecode @J.Object =<< W.lazyRequestBody req resp . W.responseLBS W.status200 [] . J.encode =<< ( Q.withStore root ref do _ <- Q.query (fromString (printf "INSERT %s INTO %s" (LB.toString (J.encode (JM.insert "$fileName" (J.String i) o))) c)) @@ -380,3 +382,13 @@ lastCompatible (Just v) commits isCompatible :: Version -> Commit -> Bool isCompatible v c = c.schemaVersion <= v + +dropNulls :: J.Object -> J.Object +dropNulls = + JM.mapMaybe + ( \v -> + case v of + J.Null -> Nothing + (J.Object v') -> Just (J.Object (dropNulls v')) + _ -> Just v + ) |