Skip to content

Commit

Permalink
fix: Add duration to getTask, addTask, quickAddTask and UpdateTask (#242
Browse files Browse the repository at this point in the history
)
  • Loading branch information
thales-fukuda authored Oct 18, 2023
1 parent 433f05b commit c64ed8c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
35 changes: 28 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"rimraf": "3.0.2",
"ts-jest": "29.0.5",
"ts-node": "10.9.1",
"type-fest": "^4.5.0",
"typescript": "4.9.5"
},
"prettier": "@doist/prettier-config",
Expand Down
9 changes: 9 additions & 0 deletions src/testUtils/testDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
User,
Comment,
Attachment,
Duration,
} from '../types'

const DEFAULT_TASK_ID = '1234'
Expand Down Expand Up @@ -44,6 +45,11 @@ export const DEFAULT_DUE_DATE = {
date: DEFAULT_DATE,
}

export const DEFAULT_DURATION: Duration = {
amount: 10,
unit: 'minute',
}

export const INVALID_DUE_DATE = {
...DEFAULT_DUE_DATE,
isRecurring: 'false',
Expand All @@ -63,6 +69,7 @@ export const DEFAULT_QUICK_ADD_RESPONSE: QuickAddTaskResponse = {
checked: false,
addedAt: DEFAULT_DATE,
addedByUid: DEFAULT_CREATOR,
duration: DEFAULT_DURATION,
due: {
date: DEFAULT_DATE,
timezone: null,
Expand All @@ -89,6 +96,7 @@ export const DEFAULT_TASK: Task = {
due: DEFAULT_DUE_DATE,
assigneeId: DEFAULT_ASSIGNEE,
creatorId: DEFAULT_CREATOR,
duration: DEFAULT_DURATION,
}

export const INVALID_TASK = {
Expand All @@ -103,6 +111,7 @@ export const TASK_WITH_OPTIONALS_AS_NULL: Task = {
assignerId: null,
parentId: null,
sectionId: null,
duration: null,
}

export const DEFAULT_PROJECT: Project = {
Expand Down
9 changes: 9 additions & 0 deletions src/types/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const DueDate = Record({

export type DueDate = Static<typeof DueDate>

export const Duration = Record({
amount: NumberRunType.withConstraint((n) => n > 0 || 'Value should be greater than zero'),
unit: Union(Literal('minute'), Literal('day')),
})

export type Duration = Static<typeof Duration>

export const Task = Record({
id: String,
order: Int,
Expand All @@ -53,6 +60,7 @@ export const Task = Record({
createdAt: String,
url: String,
creatorId: String,
duration: Duration.Or(Null),
}).And(
Partial({
due: DueDate.Or(Null),
Expand Down Expand Up @@ -187,6 +195,7 @@ export type QuickAddTaskResponse = {
checked: boolean // completed
addedAt: string // created
addedByUid: string | null
duration: Duration | null
due: {
date: string
timezone: string | null
Expand Down
13 changes: 11 additions & 2 deletions src/types/requests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { RequireAllOrNone } from 'type-fest'
import type { Duration } from './entities'

export type AddTaskArgs = {
content: string
description?: string
Expand All @@ -12,7 +15,10 @@ export type AddTaskArgs = {
dueDate?: string
dueDatetime?: string
assigneeId?: string
}
} & RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>

export type QuickAddTaskArgs = {
text: string
Expand Down Expand Up @@ -40,7 +46,10 @@ export type UpdateTaskArgs = {
dueDate?: string | null
dueDatetime?: string | null
assigneeId?: string | null
}
} & RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>

export type ProjectViewStyle = 'list' | 'board'

Expand Down
1 change: 1 addition & 0 deletions src/utils/taskConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function getTaskFromQuickAddResponse(responseData: QuickAddTaskResponse):
...(responseData.responsibleUid !== null && {
assigneeId: responseData.responsibleUid,
}),
duration: responseData.duration,
}

return task
Expand Down

0 comments on commit c64ed8c

Please sign in to comment.