Skip to content

Commit efbc305

Browse files
Update game_states.ex
1 parent 0f59ab0 commit efbc305

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/cadet/accounts/game_states.ex

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule Cadet.GameStates do
88
user.game_states
99
end
1010

11+
@spec user_collectibles(atom | %{game_states: nil | maybe_improper_list | map}) :: any
1112
def user_collectibles(user) do
1213
user.game_states["collectibles"]
1314
end
@@ -17,18 +18,26 @@ defmodule Cadet.GameStates do
1718
end
1819

1920
def update(user, new_game_states) do
20-
changeset =
21-
Ecto.Changeset.cast(user, %{game_states:
22-
new_game_states},[:game_states])
23-
Cadet.Repo.update!(changeset)
24-
{:ok, nil}
21+
if user.role == "student" do
22+
changeset =
23+
Ecto.Changeset.cast(user, %{game_states:
24+
new_game_states},[:game_states])
25+
Cadet.Repo.update!(changeset)
26+
{:ok, nil}
27+
else
28+
{:error, {:forbidden, "Please try again later."}}
29+
end
2530
end
2631

2732
def clear(user) do
28-
changeset =
29-
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{},
30-
completed_quests: []}},[:game_states])
31-
Cadet.Repo.update!(changeset)
32-
{:ok, nil}
33+
if user.role == "student" do
34+
changeset =
35+
Ecto.Changeset.cast(user, %{game_states: %{collectibles: %{},
36+
completed_quests: []}},[:game_states])
37+
Cadet.Repo.update!(changeset)
38+
{:ok, nil}
39+
else
40+
{:error, {:forbidden, "Please try again later."}}
41+
end
3342
end
3443
end

0 commit comments

Comments
 (0)