Skip to content

Commit

Permalink
[api] accept time on createTask and updateTask mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonperassoli committed Jan 24, 2020
1 parent e595a16 commit 5b2ad2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion api/lib/atomic/project_management/project_management.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ defmodule Atomic.ProjectManagement do
Project.changeset(project, %{})
end

defp get_time(attrs) do

end

def create_task(attrs \\ %{}, user) do
%{ project_id: project_id, description: description } = attrs
_project = get_user_project!(user.id, project_id)
Expand All @@ -138,7 +142,7 @@ defmodule Atomic.ProjectManagement do
description: description,
timer_status: "running",
timer_started_at: DateTime.utc_now,
time: 0
time: attrs["time"] || 0
})
|> Repo.insert()
end
Expand Down
2 changes: 2 additions & 0 deletions api/lib/atomic_web/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ defmodule AtomicWeb.Schema do
field :create_task, :task do
arg :project_id, non_null(:id)
arg :description, non_null(:string)
arg :time, :integer

middleware AtomicWeb.AuthMiddleware
resolve &ProjectManagementResolver.create_task/3
Expand All @@ -90,6 +91,7 @@ defmodule AtomicWeb.Schema do
field :update_task, :task do
arg :id, non_null(:id)
arg :description, non_null(:string)
arg :time, :integer

middleware AtomicWeb.AuthMiddleware
resolve &ProjectManagementResolver.update_task/3
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/pages/Home/TaskModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ const TimeMaskedInput = styled(MaskedInput)`


const CREATE_TASK = gql`
mutation CreateTaskMutation($projectId:ID!, $description: String!) {
createTask(projectId: $projectId, description: $description) {
mutation CreateTaskMutation($projectId:ID!, $description: String!, $time: Int) {
createTask(projectId: $projectId, description: $description, time: $time) {
id
description
time
}
}
`

const UPDATE_TASK = gql`
mutation UpdateTaskMutation($taskId:ID!, $description: String!) {
updateTask(id: $taskId, description: $description) {
mutation UpdateTaskMutation($taskId:ID!, $description: String!, $time: Int) {
updateTask(id: $taskId, description: $description, time: $time) {
id
description
time
}
}
`
Expand Down Expand Up @@ -92,7 +94,9 @@ function TaskModal({ onClose, onTaskSaved, onTaskDeleted, task }) {
}
}

const createVars = ({ description, time }) => ({ projectId, description, time })
const createVars = ({ description, time }) => ({
variables: { projectId, description, time: formattedDurationToSeconds(time) }
})

const projectId = useSelectedProjectId()
const onSubmit = async (values) => {
Expand Down

0 comments on commit 5b2ad2f

Please sign in to comment.