Skip to content

Commit c64ed8c

Browse files
fix: Add duration to getTask, addTask, quickAddTask and UpdateTask (#242)
1 parent 433f05b commit c64ed8c

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

package-lock.json

Lines changed: 28 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"rimraf": "3.0.2",
5353
"ts-jest": "29.0.5",
5454
"ts-node": "10.9.1",
55+
"type-fest": "^4.5.0",
5556
"typescript": "4.9.5"
5657
},
5758
"prettier": "@doist/prettier-config",

src/testUtils/testDefaults.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
User,
88
Comment,
99
Attachment,
10+
Duration,
1011
} from '../types'
1112

1213
const DEFAULT_TASK_ID = '1234'
@@ -44,6 +45,11 @@ export const DEFAULT_DUE_DATE = {
4445
date: DEFAULT_DATE,
4546
}
4647

48+
export const DEFAULT_DURATION: Duration = {
49+
amount: 10,
50+
unit: 'minute',
51+
}
52+
4753
export const INVALID_DUE_DATE = {
4854
...DEFAULT_DUE_DATE,
4955
isRecurring: 'false',
@@ -63,6 +69,7 @@ export const DEFAULT_QUICK_ADD_RESPONSE: QuickAddTaskResponse = {
6369
checked: false,
6470
addedAt: DEFAULT_DATE,
6571
addedByUid: DEFAULT_CREATOR,
72+
duration: DEFAULT_DURATION,
6673
due: {
6774
date: DEFAULT_DATE,
6875
timezone: null,
@@ -89,6 +96,7 @@ export const DEFAULT_TASK: Task = {
8996
due: DEFAULT_DUE_DATE,
9097
assigneeId: DEFAULT_ASSIGNEE,
9198
creatorId: DEFAULT_CREATOR,
99+
duration: DEFAULT_DURATION,
92100
}
93101

94102
export const INVALID_TASK = {
@@ -103,6 +111,7 @@ export const TASK_WITH_OPTIONALS_AS_NULL: Task = {
103111
assignerId: null,
104112
parentId: null,
105113
sectionId: null,
114+
duration: null,
106115
}
107116

108117
export const DEFAULT_PROJECT: Project = {

src/types/entities.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export const DueDate = Record({
4040

4141
export type DueDate = Static<typeof DueDate>
4242

43+
export const Duration = Record({
44+
amount: NumberRunType.withConstraint((n) => n > 0 || 'Value should be greater than zero'),
45+
unit: Union(Literal('minute'), Literal('day')),
46+
})
47+
48+
export type Duration = Static<typeof Duration>
49+
4350
export const Task = Record({
4451
id: String,
4552
order: Int,
@@ -53,6 +60,7 @@ export const Task = Record({
5360
createdAt: String,
5461
url: String,
5562
creatorId: String,
63+
duration: Duration.Or(Null),
5664
}).And(
5765
Partial({
5866
due: DueDate.Or(Null),
@@ -187,6 +195,7 @@ export type QuickAddTaskResponse = {
187195
checked: boolean // completed
188196
addedAt: string // created
189197
addedByUid: string | null
198+
duration: Duration | null
190199
due: {
191200
date: string
192201
timezone: string | null

src/types/requests.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { RequireAllOrNone } from 'type-fest'
2+
import type { Duration } from './entities'
3+
14
export type AddTaskArgs = {
25
content: string
36
description?: string
@@ -12,7 +15,10 @@ export type AddTaskArgs = {
1215
dueDate?: string
1316
dueDatetime?: string
1417
assigneeId?: string
15-
}
18+
} & RequireAllOrNone<{
19+
duration?: Duration['amount']
20+
durationUnit?: Duration['unit']
21+
}>
1622

1723
export type QuickAddTaskArgs = {
1824
text: string
@@ -40,7 +46,10 @@ export type UpdateTaskArgs = {
4046
dueDate?: string | null
4147
dueDatetime?: string | null
4248
assigneeId?: string | null
43-
}
49+
} & RequireAllOrNone<{
50+
duration?: Duration['amount']
51+
durationUnit?: Duration['unit']
52+
}>
4453

4554
export type ProjectViewStyle = 'list' | 'board'
4655

src/utils/taskConverters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function getTaskFromQuickAddResponse(responseData: QuickAddTaskResponse):
3636
...(responseData.responsibleUid !== null && {
3737
assigneeId: responseData.responsibleUid,
3838
}),
39+
duration: responseData.duration,
3940
}
4041

4142
return task

0 commit comments

Comments
 (0)