Skip to content

Commit 5b2ad2f

Browse files
[api] accept time on createTask and updateTask mutations
1 parent e595a16 commit 5b2ad2f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

api/lib/atomic/project_management/project_management.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ defmodule Atomic.ProjectManagement do
128128
Project.changeset(project, %{})
129129
end
130130

131+
defp get_time(attrs) do
132+
133+
end
134+
131135
def create_task(attrs \\ %{}, user) do
132136
%{ project_id: project_id, description: description } = attrs
133137
_project = get_user_project!(user.id, project_id)
@@ -138,7 +142,7 @@ defmodule Atomic.ProjectManagement do
138142
description: description,
139143
timer_status: "running",
140144
timer_started_at: DateTime.utc_now,
141-
time: 0
145+
time: attrs["time"] || 0
142146
})
143147
|> Repo.insert()
144148
end

api/lib/atomic_web/schema.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ defmodule AtomicWeb.Schema do
8282
field :create_task, :task do
8383
arg :project_id, non_null(:id)
8484
arg :description, non_null(:string)
85+
arg :time, :integer
8586

8687
middleware AtomicWeb.AuthMiddleware
8788
resolve &ProjectManagementResolver.create_task/3
@@ -90,6 +91,7 @@ defmodule AtomicWeb.Schema do
9091
field :update_task, :task do
9192
arg :id, non_null(:id)
9293
arg :description, non_null(:string)
94+
arg :time, :integer
9395

9496
middleware AtomicWeb.AuthMiddleware
9597
resolve &ProjectManagementResolver.update_task/3

frontend/src/pages/Home/TaskModal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ const TimeMaskedInput = styled(MaskedInput)`
2929

3030

3131
const CREATE_TASK = gql`
32-
mutation CreateTaskMutation($projectId:ID!, $description: String!) {
33-
createTask(projectId: $projectId, description: $description) {
32+
mutation CreateTaskMutation($projectId:ID!, $description: String!, $time: Int) {
33+
createTask(projectId: $projectId, description: $description, time: $time) {
3434
id
3535
description
36+
time
3637
}
3738
}
3839
`
3940

4041
const UPDATE_TASK = gql`
41-
mutation UpdateTaskMutation($taskId:ID!, $description: String!) {
42-
updateTask(id: $taskId, description: $description) {
42+
mutation UpdateTaskMutation($taskId:ID!, $description: String!, $time: Int) {
43+
updateTask(id: $taskId, description: $description, time: $time) {
4344
id
4445
description
46+
time
4547
}
4648
}
4749
`
@@ -92,7 +94,9 @@ function TaskModal({ onClose, onTaskSaved, onTaskDeleted, task }) {
9294
}
9395
}
9496

95-
const createVars = ({ description, time }) => ({ projectId, description, time })
97+
const createVars = ({ description, time }) => ({
98+
variables: { projectId, description, time: formattedDurationToSeconds(time) }
99+
})
96100

97101
const projectId = useSelectedProjectId()
98102
const onSubmit = async (values) => {

0 commit comments

Comments
 (0)