From 0a978354fae1eecb4d5fac7f253d12982aee237e Mon Sep 17 00:00:00 2001 From: Joel Abshier Date: Sun, 3 Oct 2021 22:36:30 -0500 Subject: [PATCH] Add Update Preferences --- lib/gql_preferences_web/resolvers/preferences.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/gql_preferences_web/resolvers/preferences.ex diff --git a/lib/gql_preferences_web/resolvers/preferences.ex b/lib/gql_preferences_web/resolvers/preferences.ex new file mode 100644 index 0000000..6ae07e7 --- /dev/null +++ b/lib/gql_preferences_web/resolvers/preferences.ex @@ -0,0 +1,15 @@ +defmodule UserPreferencesWeb.Resolvers.Preferences do + alias UserPreferences.{Repo, Preferences} + + def get_preferences(parent, _args, _) do + Preferences + |> Repo.get_by(user_id: parent.id) + |> then(&{:ok, &1}) + end + + def update_preferences_by_id(_, args, _) do + Repo.get_by(Preferences, user_id: args.user_id) + |> Preferences.changeset(args) + |> Repo.update() + end +end