Skip to content

Commit

Permalink
feat(EditSpeaker): Register the video_id where the speaker was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Apr 12, 2019
1 parent 5feeb51 commit 3b003b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apps/cf/lib/actions/action_creator.ex
Expand Up @@ -105,6 +105,10 @@ defmodule CF.Actions.ActionCreator do
)
end

def action_update(user_id, %{data: %Speaker{id: id}, changes: changes}, video_id) do
action(user_id, :speaker, :update, speaker_id: id, video_id: video_id, changes: changes)
end

def action_update(user_id, %{data: %Speaker{id: id}, changes: changes}) do
action(user_id, :speaker, :update, speaker_id: id, changes: changes)
end
Expand Down
5 changes: 3 additions & 2 deletions apps/cf_rest_api/lib/channels/video_debate_channel.ex
Expand Up @@ -6,7 +6,7 @@ defmodule CF.RestApi.VideoDebateChannel do
only: [
action_add: 3,
action_create: 2,
action_update: 2,
action_update: 3,
action_remove: 3
]

Expand Down Expand Up @@ -156,6 +156,7 @@ defmodule CF.RestApi.VideoDebateChannel do

def handle_in_authenticated!("update_speaker", params, socket) do
user_id = socket.assigns.user_id
video_id = socket.assigns.video_id
UserPermissions.check!(user_id, :update, :speaker)
speaker = Repo.get!(Speaker, params["id"])
changeset = Speaker.changeset(speaker, params)
Expand All @@ -167,7 +168,7 @@ defmodule CF.RestApi.VideoDebateChannel do
_ ->
Multi.new()
|> Multi.update(:speaker, changeset)
|> Multi.insert(:action_update, action_update(user_id, changeset))
|> Multi.insert(:action_update, action_update(user_id, changeset, video_id))
|> Repo.transaction()
|> case do
{:ok, %{speaker: speaker}} ->
Expand Down

0 comments on commit 3b003b0

Please sign in to comment.