-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathupdatePost.ts
More file actions
47 lines (39 loc) · 1.03 KB
/
updatePost.ts
File metadata and controls
47 lines (39 loc) · 1.03 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
import type { TaskHandler } from 'payload'
export const updatePostStep1: TaskHandler<'UpdatePost'> = async ({ req, input }) => {
const postID =
typeof input.post === 'string' || typeof input.post === 'number' ? input.post : input.post.id
if (!postID) {
throw new Error('No post ID provided')
}
await req.payload.update({
collection: 'posts',
id: postID,
req,
data: {
jobStep1Ran: input.message,
},
})
return {
output: {
messageTwice: input.message + input.message,
},
}
}
export const updatePostStep2: TaskHandler<'UpdatePostStep2'> = async ({ req, input, job }) => {
const postID =
typeof input.post === 'string' || typeof input.post === 'number' ? input.post : input.post.id
if (!postID) {
throw new Error('No post ID provided')
}
await req.payload.update({
collection: 'posts',
id: postID,
req,
data: {
jobStep2Ran: input.messageTwice + job.taskStatus.UpdatePost?.['1']?.output?.messageTwice,
},
})
return {
output: null,
}
}