forked from linuxfoundation/crowd.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskUpdate.ts
More file actions
60 lines (56 loc) · 1.7 KB
/
Copy pathtaskUpdate.ts
File metadata and controls
60 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Permissions from '../../security/permissions'
import TaskService from '../../services/taskService'
import PermissionChecker from '../../services/user/permissionChecker'
import track from '../../segment/track'
/**
* PUT /tenant/{tenantId}/task/{id}
* @summary Update an task
* @tag Tasks
* @security Bearer
* @description Update a task
* @pathParam {string} tenantId - Your workspace/tenant ID
* @pathParam {string} id - The ID of the task
* @bodyContent {TaskInput} application/json
* @response 200 - Ok
* @responseContent {Task} 200.application/json
* @responseExample {Task} 200.application/json.Task
* @response 401 - Unauthorized
* @response 404 - Not found
* @response 429 - Too many requests
*/
export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.taskEdit)
const taskBeforeUpdate = await new TaskService(req).findById(req.params.id)
const payload = await new TaskService(req).update(req.params.id, req.body)
if (taskBeforeUpdate.type === 'suggested') {
track(
'Task Created (from suggestion)',
{ id: payload.id, dueDate: payload.dueDate, members: payload.members },
{ ...req },
)
}
if (taskBeforeUpdate.status === 'in-progress' && payload.status === 'done') {
track(
'Task Completed',
{
id: payload.id,
dueDate: payload.dueDate,
members: payload.members,
status: payload.status,
},
{ ...req },
)
} else {
track(
'Task Updated',
{
id: payload.id,
dueDate: payload.dueDate,
members: payload.members,
status: payload.status,
},
{ ...req },
)
}
await req.responseHandler.success(req, res, payload)
}