Skip to content

Commit 65827c7

Browse files
authored
Merge pull request #518 from contentstack/feature/ds-store
Resolved comments
2 parents 3f3bfd1 + 78807f2 commit 65827c7

File tree

4 files changed

+56
-56
lines changed

4 files changed

+56
-56
lines changed

api/src/services/contentful.service.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ const transformCloudinaryObject = (input: any) => {
9494
for (const metaData of input ?? []) {
9595
if (metaData?.public_id) {
9696
result?.push({
97-
public_id: metaData.public_id,
98-
resource_type: metaData.resource_type,
99-
type: metaData.type,
100-
format: metaData.format,
101-
version: metaData.version,
102-
url: metaData.original_url,
103-
secure_url: metaData.original_secure_url,
104-
width: metaData.width,
105-
height: metaData.height,
106-
bytes: metaData.bytes,
107-
duration: metaData.duration,
108-
tags: metaData.tags,
109-
metadata: metaData.metadata,
110-
created_at: metaData.created_at,
97+
public_id: metaData?.public_id,
98+
resource_type: metaData?.resource_type,
99+
type: metaData?.type,
100+
format: metaData?.format,
101+
version: metaData?.version,
102+
url: metaData?.original_url,
103+
secure_url: metaData?.original_secure_url,
104+
width: metaData?.width,
105+
height: metaData?.height,
106+
bytes: metaData?.bytes,
107+
duration: metaData?.duration,
108+
tags: metaData?.tags,
109+
metadata: metaData?.metadata,
110+
created_at: metaData?.created_at,
111111
access_mode: "public",
112112
access_control: [],
113113
created_by: {

api/src/services/migration.service.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ const startTestMigration = async (req: Request): Promise<any> => {
244244
await wordpressService?.extractChunks(file_path, packagePath, project?.current_test_stack_id, projectId)
245245
await wordpressService?.getAllAuthors(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
246246
//await wordpressService?.extractContentTypes(projectId, project?.current_test_stack_id, contentTypes)
247-
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
248-
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
249-
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
250-
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
247+
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
248+
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
249+
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
250+
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
251251
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
252252
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
253253
}
@@ -318,12 +318,12 @@ const startMigration = async (req: Request): Promise<any> => {
318318
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
319319
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
320320
await wordpressService?.extractChunks(file_path, packagePath, project?.destination_stack_id, projectId)
321-
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
321+
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
322322
//await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
323323
await wordpressService?.getAllTerms(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
324-
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
325-
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
326-
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
324+
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
325+
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
326+
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
327327
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
328328
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
329329

@@ -426,23 +426,23 @@ export const createSourceLocales = async (req: Request) => {
426426

427427
try {
428428
// Check if the project.json file exists
429-
if (!fs.existsSync(projectFilePath)) {
429+
if (!fs?.existsSync?.(projectFilePath)) {
430430
console.error(`project.json not found at ${projectFilePath}`);
431431
throw new Error(`project.json not found.`);
432432
}
433-
433+
434434
// Find the project with the specified projectId
435-
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
435+
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value?.();
436436
if (project) {
437-
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
437+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value();
438438
if (index > -1) {
439-
440-
ProjectModelLowdb.update((data: any) => {
439+
440+
ProjectModelLowdb?.update((data: any) => {
441441
data.projects[index].source_locales = locales;
442442
});
443443
} // Write back the updated projects
444444
} else {
445-
logger.error(`Project with ID: ${projectId} not found`,{
445+
logger.error(`Project with ID: ${projectId} not found`, {
446446
status: HTTP_CODES?.NOT_FOUND,
447447
message: HTTP_TEXTS?.INVALID_ID
448448
})
@@ -467,30 +467,30 @@ export const createSourceLocales = async (req: Request) => {
467467
* @return - void
468468
* @throws Exception if the project ID is invalid or the when the path to project.json is incorrect
469469
*/
470-
export const updateLocaleMapper = async (req:Request) =>{
471-
const mapperObject = req.body;
472-
const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json
473-
const projectId = req.params.projectId;
470+
export const updateLocaleMapper = async (req: Request) => {
471+
const mapperObject = req?.body;
472+
const projectFilePath = path?.join?.(process?.cwd(), 'database', 'project.json'); // Adjusted path to project.json
473+
const projectId = req?.params?.projectId;
474474

475475
try {
476476
// Check if the project.json file exists
477-
if (!fs.existsSync(projectFilePath)) {
477+
if (!fs?.existsSync?.(projectFilePath)) {
478478
console.error(`project.json not found at ${projectFilePath}`);
479479
throw new Error(`project.json not found.`);
480480
}
481-
481+
482482
// Find the project with the specified projectId
483-
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
483+
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
484484
if (project) {
485-
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
485+
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();
486486
if (index > -1) {
487-
ProjectModelLowdb.update((data: any) => {
487+
ProjectModelLowdb?.update((data: any) => {
488488
data.projects[index].master_locale = mapperObject?.master_locale;
489489
data.projects[index].locales = mapperObject?.locales;
490490
});
491491
} // Write back the updated projects
492492
} else {
493-
logger.error(`Project with ID: ${projectId} not found`,{
493+
logger.error(`Project with ID: ${projectId} not found`, {
494494
status: HTTP_CODES?.NOT_FOUND,
495495
message: HTTP_TEXTS?.INVALID_ID
496496
})

upload-api/migration-contentful/libs/extractLocale.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ const fs = require("fs");
1313
*/
1414
const extractLocale = async (jsonFilePath) => {
1515
try {
16-
const rawData = fs.readFileSync(jsonFilePath, "utf8");
17-
const jsonData = JSON.parse(rawData);
18-
16+
const rawData = fs?.readFileSync?.(jsonFilePath, "utf8");
17+
const jsonData = JSON?.parse?.(rawData);
18+
1919
// Extract unique language codes from locales array
2020
const uniqueLanguages = new Set();
21-
if (Array.isArray(jsonData.locales)) {
22-
jsonData.locales.forEach(locale => {
23-
if (locale.code) {
24-
uniqueLanguages.add(locale.code.toLowerCase()); // Normalize to lowercase
21+
if (Array?.isArray?.(jsonData?.locales)) {
22+
jsonData?.locales?.forEach?.(locale => {
23+
if (locale?.code) {
24+
uniqueLanguages.add(locale?.code?.toLowerCase?.()); // Normalize to lowercase
2525
}
2626
});
2727
}
28-
28+
2929
return [...uniqueLanguages]; // Convert Set to array for output
3030
} catch (error) {
3131
console.error(`Error reading JSON file:`, error.message);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ const path = require("path");
66
const uniqueLanguages = new Set(); // Define uniqueLanguages globally or pass it as a parameter
77

88
const extractLocales = (dir) => {
9-
const items = fs.readdirSync(dir, { withFileTypes: true });
9+
const items = fs?.readdirSync?.(dir, { withFileTypes: true });
1010

1111
for (const item of items) {
12-
const fullPath = path.join(dir, item.name);
13-
12+
const fullPath = path?.join?.(dir, item?.name);
13+
1414
if (item.isDirectory()) {
15-
extractLocales(fullPath); // Proper recursion
16-
} else if (item.isFile() && item.name === "data.json.json") {
15+
extractLocales?.(fullPath); // Proper recursion
16+
} else if (item?.isFile() && item?.name === "data.json.json") {
1717
try {
18-
const rawData = fs.readFileSync(fullPath, "utf8");
19-
const jsonData = JSON.parse(rawData);
18+
const rawData = fs?.readFileSync?.(fullPath, "utf8");
19+
const jsonData = JSON?.parse?.(rawData);
2020
const language = jsonData?.item?.$?.language;
2121

2222
if (language) {
23-
uniqueLanguages.add(language);
23+
uniqueLanguages?.add?.(language);
2424
}
2525
} catch (error) {
26-
console.error(`Error reading ${fullPath}:`, error.message);
26+
console.error(`Error reading ${fullPath}:`, error?.message);
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)