Skip to content

Commit c406439

Browse files
committed
fix:optional chaining comments in PR
1 parent db8494d commit c406439

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

api/src/services/wordpress.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ async function saveAuthors(authorDetails: any[], destinationStackId: string, pro
800800

801801
const message = getLogMessage(
802802
srcFunc,
803-
`${authorDetails.length} Authors exported successfully`,
803+
`${authorDetails?.length} Authors exported successfully`,
804804
{}
805805
)
806806
await customLogger(projectId, destinationStackId, 'info', message);
@@ -1927,7 +1927,7 @@ async function featuredImageMapping(postid: string, post: any, postdata: any) {
19271927
})
19281928
.filter(Boolean); // Filter out undefined matches
19291929

1930-
if (assetsDetails.length > 0) {
1930+
if (assetsDetails?.length > 0) {
19311931
postdata[postid]["featured_image"] = assetsDetails[0];
19321932
}
19331933
return postdata;
@@ -2031,11 +2031,11 @@ async function processChunkData(
20312031
);
20322032
const htmlDoc = dom.window.document.querySelector("body");
20332033
const jsonValue = htmlToJson(htmlDoc);
2034-
const postDate = new Date(data["wp:post_date_gmt"]).toISOString();
2034+
const postDate = new Date(data["wp:post_date_gmt"])?.toISOString();
20352035

2036-
const base = blog_base_url.split("/").filter(Boolean);
2037-
const blogname = base[base.length - 1];
2038-
const url = data["link"].split(blogname)[1];
2036+
const base = blog_base_url?.split("/")?.filter(Boolean);
2037+
const blogname = base[base?.length - 1];
2038+
const url = data["link"]?.split(blogname)[1];
20392039
//const title = data["title"] ?? `Posts - ${data["wp:post_id"]}`;
20402040
const uid = `posts_${data["wp:post_id"]}`
20412041
const customId = idCorrector(uid)

ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ const LoadFileFormat = (props: LoadFileFormatProps) => {
6161
};
6262

6363
const getFileExtension = (filePath: string): string => {
64-
const normalizedPath = filePath.replace(/\\/g, "/")?.replace(/\/$/, "");
64+
const normalizedPath = filePath?.replace(/\\/g, "/")?.replace(/\/$/, "");
6565

6666
// Use regex to extract the file extension
67-
const match = normalizedPath.match(/\.([a-zA-Z0-9]+)$/);
68-
const ext = match ? match[1].toLowerCase() : "";
67+
const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/);
68+
const ext = match ? match[1]?.toLowerCase() : "";
6969

7070
const fileName = filePath?.split('/')?.pop();
7171
//const ext = fileName?.split('.')?.pop();

upload-api/migration-sitecore/libs/extractLocales.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const extractLocales = (dir) => {
88
const items = fs.readdirSync(dir, { withFileTypes: true });
99

1010
for (const item of items) {
11-
const fullPath = path.join(dir, item.name);
11+
const fullPath = path.join(dir, item?.name);
1212

13-
if (item.isDirectory()) {
13+
if (item?.isDirectory()) {
1414
extractLocales(fullPath); // Proper recursion
15-
} else if (item.isFile() && item.name === 'data.json.json') {
15+
} else if (item?.isFile() && item?.name === 'data.json.json') {
1616
try {
1717
const rawData = fs.readFileSync(fullPath, 'utf8');
1818
const jsonData = JSON.parse(rawData);
@@ -22,7 +22,7 @@ const extractLocales = (dir) => {
2222
uniqueLanguages.add(language);
2323
}
2424
} catch (error) {
25-
console.error(`Error reading ${fullPath}:`, error.message);
25+
console.error(`Error reading ${fullPath}:`, error?.message);
2626
}
2727
}
2828
}

upload-api/src/routes/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
184184
//file ext from fileName
185185
const fileExt = fileName?.split?.('.')?.pop?.() ?? 'test';
186186

187-
if (!s3File.Body) {
187+
if (!s3File?.Body) {
188188
throw new Error('Empty response body from S3');
189189
}
190190

191-
const bodyStream: Readable = s3File.Body as Readable;
191+
const bodyStream: Readable = s3File?.Body as Readable;
192192

193193
// Create a writable stream to save the downloaded zip file
194194
const zipFileStream = createWriteStream(`${fileName}`);

0 commit comments

Comments
 (0)