Skip to content

Commit

Permalink
refactor: clean code.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Sep 17, 2024
1 parent 16de5c7 commit 89a5f52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"decrypt": "./bin/decrypt",
"encrypt": "./bin/encrypt",
"db:build": "./bin/build-db && npm run db:check",
"db:check": "elm make src/CheckDb.elm --output=check-db-app.js 1> /dev/null && node check-db.js",
"db:check": "elm make src/CheckDb.elm --optimize --output=check-db-app.js 1> /dev/null && node check-db.js",
"lint:openapi": "npx swagger-cli validate openapi.yaml",
"lint:prettier": "prettier --config .prettierrc --check",
"lint:prettier:all": "npm run lint:prettier -- .",
Expand Down
43 changes: 23 additions & 20 deletions src/CheckDb.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
port module CheckDb exposing (main)

import Static.Db as StaticDb
import Static.Db as StaticDb exposing (Db)
import Static.Json as StaticJson


Expand All @@ -10,30 +10,33 @@ type alias Flags =
}


checkDbs : Flags -> Result String StaticDb.Db
checkDbs detailedRawProcessesJson =
StaticDb.db StaticJson.rawJsonProcesses
|> Result.mapError (\err -> "Non-detailed Db is invalid: " ++ err)
|> Result.andThen
(StaticDb.db detailedRawProcessesJson
|> Result.mapError (\err -> "Detailed Db is invalid: " ++ err)
|> always
)
init : Flags -> ( (), Cmd () )
init flags =
( ()
, case checkStaticDatabases flags of
Err error ->
logAndExit { message = error, status = 1 }

Ok _ ->
logAndExit { message = "Dbs look fine", status = 0 }
)


checkStaticDatabases : Flags -> Result String ( Db, Db )
checkStaticDatabases detailedRawJsonProcesses =
Result.map2 Tuple.pair
(StaticDb.db StaticJson.rawJsonProcesses
|> Result.mapError (\err -> "Non-detailed Db is invalid: " ++ err)
)
(StaticDb.db detailedRawJsonProcesses
|> Result.mapError (\err -> "Detailed Db is invalid: " ++ err)
)


main : Program Flags () ()
main =
Platform.worker
{ init =
\flags ->
( ()
, case checkDbs flags of
Err error ->
logAndExit { message = "Db is dubious: " ++ error, status = 1 }

Ok _ ->
logAndExit { message = "Db is fine", status = 0 }
)
{ init = init
, subscriptions = always Sub.none
, update = \_ _ -> ( (), Cmd.none )
}
Expand Down

0 comments on commit 89a5f52

Please sign in to comment.