Skip to content

Commit 8a4a84c

Browse files
committed
refactor: Improve code formatting and type casting in bulk action handlers
1 parent 0a8731d commit 8a4a84c

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

src/handlers/bulk-action-handlers.ts

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -40,65 +40,65 @@ export const bulkActionHandlers = {
4040
const environmentId = process.env.ENVIRONMENT_ID || args.environmentId
4141

4242
const contentfulClient = await getContentfulClient()
43-
43+
4444
// Create the bulk action
4545
const bulkAction = await contentfulClient.bulkAction.publish(
4646
{
4747
spaceId,
4848
environmentId,
49-
},
49+
},
5050
{
5151
entities: {
5252
sys: {
5353
type: "Array",
5454
},
55-
items: args.entities.map(entity => ({
55+
items: args.entities.map((entity) => ({
5656
sys: {
5757
type: "Link",
5858
linkType: entity.sys.type,
59-
id: entity.sys.id
60-
}
59+
id: entity.sys.id,
60+
},
6161
})),
6262
},
63-
}
63+
},
6464
)
65-
65+
6666
// Wait for the bulk action to complete
67-
let action = await contentfulClient.bulkAction.get({
67+
let action = (await contentfulClient.bulkAction.get({
6868
spaceId,
6969
environmentId,
70-
bulkActionId: bulkAction.sys.id
71-
}) as unknown as BulkActionResponse
72-
70+
bulkActionId: bulkAction.sys.id,
71+
})) as unknown as BulkActionResponse
72+
7373
while (action.sys.status === "inProgress" || action.sys.status === "created") {
74-
await new Promise(resolve => setTimeout(resolve, 1000))
75-
action = await contentfulClient.bulkAction.get({
74+
await new Promise((resolve) => setTimeout(resolve, 1000))
75+
action = (await contentfulClient.bulkAction.get({
7676
spaceId,
7777
environmentId,
78-
bulkActionId: bulkAction.sys.id
79-
}) as unknown as BulkActionResponse
78+
bulkActionId: bulkAction.sys.id,
79+
})) as unknown as BulkActionResponse
8080
}
81-
81+
8282
return {
8383
content: [
84-
{
85-
type: "text",
84+
{
85+
type: "text",
8686
text: `Bulk publish completed with status: ${action.sys.status}. ${
87-
action.sys.status === "failed"
88-
? `Error: ${JSON.stringify(action.error)}`
87+
action.sys.status === "failed"
88+
? `Error: ${JSON.stringify(action.error)}`
8989
: `Successfully processed ${action.succeeded?.length || 0} items.`
90-
}`
91-
}
90+
}`,
91+
},
9292
],
9393
}
9494
},
95-
95+
9696
bulkUnpublish: async (args: BulkUnpublishParams) => {
9797
const spaceId = process.env.SPACE_ID || args.spaceId
9898
const environmentId = process.env.ENVIRONMENT_ID || args.environmentId
9999

100100
const contentfulClient = await getContentfulClient()
101-
101+
102102
// Create the bulk action
103103
const bulkAction = await contentfulClient.bulkAction.unpublish(
104104
{
@@ -110,53 +110,53 @@ export const bulkActionHandlers = {
110110
sys: {
111111
type: "Array",
112112
},
113-
items: args.entities.map(entity => ({
113+
items: args.entities.map((entity) => ({
114114
sys: {
115115
type: "Link",
116116
linkType: entity.sys.type,
117-
id: entity.sys.id
118-
}
117+
id: entity.sys.id,
118+
},
119119
})),
120120
},
121-
}
121+
},
122122
)
123-
123+
124124
// Wait for the bulk action to complete
125-
let action = await contentfulClient.bulkAction.get({
125+
let action = (await contentfulClient.bulkAction.get({
126126
spaceId,
127127
environmentId,
128-
bulkActionId: bulkAction.sys.id
129-
}) as unknown as BulkActionResponse
130-
128+
bulkActionId: bulkAction.sys.id,
129+
})) as unknown as BulkActionResponse
130+
131131
while (action.sys.status === "inProgress" || action.sys.status === "created") {
132-
await new Promise(resolve => setTimeout(resolve, 1000))
133-
action = await contentfulClient.bulkAction.get({
132+
await new Promise((resolve) => setTimeout(resolve, 1000))
133+
action = (await contentfulClient.bulkAction.get({
134134
spaceId,
135135
environmentId,
136-
bulkActionId: bulkAction.sys.id
137-
}) as unknown as BulkActionResponse
136+
bulkActionId: bulkAction.sys.id,
137+
})) as unknown as BulkActionResponse
138138
}
139-
139+
140140
return {
141141
content: [
142-
{
143-
type: "text",
142+
{
143+
type: "text",
144144
text: `Bulk unpublish completed with status: ${action.sys.status}. ${
145-
action.sys.status === "failed"
146-
? `Error: ${JSON.stringify(action.error)}`
145+
action.sys.status === "failed"
146+
? `Error: ${JSON.stringify(action.error)}`
147147
: `Successfully processed ${action.succeeded?.length || 0} items.`
148-
}`
149-
}
148+
}`,
149+
},
150150
],
151151
}
152152
},
153-
153+
154154
bulkValidate: async (args: BulkValidateParams) => {
155155
const spaceId = process.env.SPACE_ID || args.spaceId
156156
const environmentId = process.env.ENVIRONMENT_ID || args.environmentId
157157

158158
const contentfulClient = await getContentfulClient()
159-
159+
160160
// Create the bulk action
161161
const bulkAction = await contentfulClient.bulkAction.validate(
162162
{
@@ -168,44 +168,44 @@ export const bulkActionHandlers = {
168168
sys: {
169169
type: "Array",
170170
},
171-
items: args.entryIds.map(id => ({
171+
items: args.entryIds.map((id) => ({
172172
sys: {
173173
type: "Link",
174174
linkType: "Entry",
175-
id
176-
}
175+
id,
176+
},
177177
})),
178178
},
179-
}
179+
},
180180
)
181-
181+
182182
// Wait for the bulk action to complete
183-
let action = await contentfulClient.bulkAction.get({
183+
let action = (await contentfulClient.bulkAction.get({
184184
spaceId,
185185
environmentId,
186-
bulkActionId: bulkAction.sys.id
187-
}) as unknown as BulkActionResponse
188-
186+
bulkActionId: bulkAction.sys.id,
187+
})) as unknown as BulkActionResponse
188+
189189
while (action.sys.status === "inProgress" || action.sys.status === "created") {
190-
await new Promise(resolve => setTimeout(resolve, 1000))
191-
action = await contentfulClient.bulkAction.get({
190+
await new Promise((resolve) => setTimeout(resolve, 1000))
191+
action = (await contentfulClient.bulkAction.get({
192192
spaceId,
193193
environmentId,
194-
bulkActionId: bulkAction.sys.id
195-
}) as unknown as BulkActionResponse
194+
bulkActionId: bulkAction.sys.id,
195+
})) as unknown as BulkActionResponse
196196
}
197-
197+
198198
return {
199199
content: [
200-
{
201-
type: "text",
200+
{
201+
type: "text",
202202
text: `Bulk validation completed with status: ${action.sys.status}. ${
203-
action.sys.status === "failed"
204-
? `Error: ${JSON.stringify(action.error)}`
203+
action.sys.status === "failed"
204+
? `Error: ${JSON.stringify(action.error)}`
205205
: `Successfully validated ${action.succeeded?.length || 0} entries.`
206-
}`
207-
}
206+
}`,
207+
},
208208
],
209209
}
210-
}
210+
},
211211
}

0 commit comments

Comments
 (0)