Skip to content

Commit b1c106a

Browse files
committed
refactor: Improve array handling and code consistency in WordPress service and migration libraries found by copilot
1 parent 5940632 commit b1c106a

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

api/src/services/wordpress.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const RteJsonConverter = (html: string) => {
129129
}
130130

131131
const getLocale = (master_locale: string, project: any) => {
132-
for (const [key, value] of Object.entries(project?.master_locale || {})) {
132+
for (const key of Object.keys(project?.master_locale || {})) {
133133
if (key === master_locale) {
134134
return key;
135135
}

upload-api/migration-wordpress/libs/extractAuthor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ const extractAuthor = async(item:any, type: string) => {
5454
}
5555
}]
5656
};
57-
if(typeof item === 'object'){
58-
const fields = await handleAuthorSchema(item);
57+
if(Array.isArray(item)){
58+
const fields = await handleAuthorSchema(item?.[0]);
5959
author?.fieldMapping?.push(...fields.map(field => ({
6060
...field,
6161
isDeleted: false,
6262
advanced: { ...field?.advanced, mandatory: field?.advanced?.mandatory ?? false }
6363
})));
64-
}else if(Array.isArray(item)){
65-
const fields = await handleAuthorSchema(item?.[0]);
64+
}
65+
else{
66+
const fields = await handleAuthorSchema(item);
6667
author?.fieldMapping?.push(...fields.map(field => ({
6768
...field,
6869
isDeleted: false,

upload-api/migration-wordpress/libs/extractItems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:
334334
// If this block has similar structures
335335
if (similarBlocks?.length > 0) {
336336
// Create a unique key based on the structure/name to track processed groups
337-
const groupKey = field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name)
337+
const groupKey = field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name);
338338
// Skip if we've already processed this group of similar blocks
339339
if (processedSimilarBlocks?.has?.(groupKey) || existingBlock) {
340340
continue;
@@ -539,7 +539,7 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:
539539
"contentstackUid": type?.toLowerCase(),
540540
"type": "content_type",
541541
"fieldMapping": CT
542-
}
542+
};
543543

544544
try {
545545
await helper.writeFileAsync(

upload-api/migration-wordpress/libs/extractTerms.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ const extractTerms = async(allTerms: any, type: string) => {
5656
}
5757
}]
5858
};
59-
if(typeof allTerms === 'object'){
60-
const fields = await handleAuthorSchema(allTerms);
59+
if(Array.isArray(allTerms)){
60+
const fields = await handleAuthorSchema(allTerms?.[0]);
6161
terms?.fieldMapping?.push(...fields.map(field => ({
6262
...field,
6363
isDeleted: false,
6464
advanced: { ...field?.advanced, mandatory: field?.advanced?.mandatory ?? false }
6565
})));
66-
}else if(Array.isArray(allTerms)){
67-
const fields = await handleAuthorSchema(allTerms?.[0]);
66+
}
67+
else{
68+
const fields = await handleAuthorSchema(allTerms);
6869
terms?.fieldMapping?.push(...fields.map(field => ({
6970
...field,
7071
isDeleted: false,

upload-api/migration-wordpress/libs/schemaMapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
198198
backupFieldType: 'json',
199199
backupFieldUid: rteUid,
200200
advanced: {}
201-
}
201+
};
202202
}
203203
break;
204204
case 'core/image':
@@ -217,7 +217,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
217217
backupFieldType: 'file',
218218
backupFieldUid: fileUid,
219219
advanced: {}
220-
}
220+
};
221221
}
222222
break;
223223

@@ -234,7 +234,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
234234
backupFieldType: 'single_line_text',
235235
backupFieldUid: textUid,
236236
advanced: {}
237-
}
237+
};
238238
}
239239
break;
240240
case 'core/social-link':
@@ -251,7 +251,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
251251
backupFieldType: 'link',
252252
backupFieldUid: LinkUid,
253253
advanced: {}
254-
}
254+
};
255255
}
256256
break;
257257
case 'core/list':

0 commit comments

Comments
 (0)