Skip to content

Commit d097e62

Browse files
Merge pull request #556 from contentstack/feature/CMG-533-Bugs
code refac
2 parents 12a03db + 918a940 commit d097e62

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

upload-api/src/constants/index.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const HTTP_TEXTS = {
2323
ZIP_FILE_SAVE: 'Issue While Saving Zip File.',
2424
XML_FILE_SAVE: 'Issue While Saving XML File.',
2525
MAPPER_SAVED: 'Mapping process completed successfull.',
26-
LOCALE_SAVED: 'Source locales stored successfully'
26+
LOCALE_SAVED: 'Source locales stored successfully',
27+
LOCALE_FAILED: 'Unable to create source.',
2728
};
2829

2930
export const HTTP_RESPONSE_HEADERS = {
@@ -33,46 +34,46 @@ export const HTTP_RESPONSE_HEADERS = {
3334
};
3435

3536
export const MIGRATION_DATA_CONFIG = {
36-
DATA :"cmsMigrationData",
37+
DATA: "cmsMigrationData",
3738

3839
BACKUP_DATA: "migration-data",
3940
BACKUP_LOG_DIR: "logs",
4041
BACKUP_FOLDER_NAME: "import",
4142
BACKUP_FILE_NAME: "success.log",
4243

43-
LOCALE_DIR_NAME : "locale",
44-
LOCALE_FILE_NAME : "locales.json",
45-
LOCALE_MASTER_LOCALE : "master-locale.json",
46-
LOCALE_CF_LANGUAGE : "language.json",
44+
LOCALE_DIR_NAME: "locale",
45+
LOCALE_FILE_NAME: "locales.json",
46+
LOCALE_MASTER_LOCALE: "master-locale.json",
47+
LOCALE_CF_LANGUAGE: "language.json",
4748

48-
WEBHOOKS_DIR_NAME : "webhooks",
49-
WEBHOOKS_FILE_NAME : "webhooks.json",
49+
WEBHOOKS_DIR_NAME: "webhooks",
50+
WEBHOOKS_FILE_NAME: "webhooks.json",
5051

51-
ENVIRONMENTS_DIR_NAME : "environments",
52-
ENVIRONMENTS_FILE_NAME : "environments.json",
52+
ENVIRONMENTS_DIR_NAME: "environments",
53+
ENVIRONMENTS_FILE_NAME: "environments.json",
5354

54-
CONTENT_TYPES_DIR_NAME : "content_types",
55-
CONTENT_TYPES_FILE_NAME : "contenttype.json",
56-
CONTENT_TYPES_MASTER_FILE : "contenttypes.json",
57-
CONTENT_TYPES_SCHEMA_FILE : "schema.json",
55+
CONTENT_TYPES_DIR_NAME: "content_types",
56+
CONTENT_TYPES_FILE_NAME: "contenttype.json",
57+
CONTENT_TYPES_MASTER_FILE: "contenttypes.json",
58+
CONTENT_TYPES_SCHEMA_FILE: "schema.json",
5859

59-
REFERENCES_DIR_NAME : "reference",
60-
REFERENCES_FILE_NAME : "reference.json",
60+
REFERENCES_DIR_NAME: "reference",
61+
REFERENCES_FILE_NAME: "reference.json",
6162

62-
RTE_REFERENCES_DIR_NAME : "rteReference",
63-
RTE_REFERENCES_FILE_NAME : "rteReference.json",
63+
RTE_REFERENCES_DIR_NAME: "rteReference",
64+
RTE_REFERENCES_FILE_NAME: "rteReference.json",
6465

65-
ASSETS_DIR_NAME : "assets",
66-
ASSETS_FILE_NAME : "assets.json",
67-
ASSETS_SCHEMA_FILE : "index.json",
68-
ASSETS_FAILED_FILE : "cs_failed.json",
69-
ASSETS_METADATA_FILE :"metadata.json",
66+
ASSETS_DIR_NAME: "assets",
67+
ASSETS_FILE_NAME: "assets.json",
68+
ASSETS_SCHEMA_FILE: "index.json",
69+
ASSETS_FAILED_FILE: "cs_failed.json",
70+
ASSETS_METADATA_FILE: "metadata.json",
7071

71-
ENTRIES_DIR_NAME : "entries",
72-
ENTRIES_MASTER_FILE : "index.json",
72+
ENTRIES_DIR_NAME: "entries",
73+
ENTRIES_MASTER_FILE: "index.json",
7374

74-
GLOBAL_FIELDS_DIR_NAME : "global_fields",
75-
GLOBAL_FIELDS_FILE_NAME : "globalfields.json",
75+
GLOBAL_FIELDS_DIR_NAME: "global_fields",
76+
GLOBAL_FIELDS_FILE_NAME: "globalfields.json",
7677

7778
EXPORT_INFO_FILE: "export-info.json"
7879
}

upload-api/src/controllers/sitecore/index.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,39 @@ const {
1414
GLOBAL_FIELDS_FILE_NAME
1515
} = MIGRATION_DATA_CONFIG;
1616

17+
const createLocaleSource = async ({ app_token, localeData, projectId }: { app_token: string | string[], localeData: any, projectId: string | string[] }) => {
18+
const mapperConfig = {
19+
method: 'post',
20+
maxBodyLength: Infinity,
21+
url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`,
22+
headers: {
23+
app_token,
24+
'Content-Type': 'application/json'
25+
},
26+
data: {
27+
locale: Array?.from?.(localeData) ?? []
28+
},
29+
};
30+
const mapRes = await axios?.request?.(mapperConfig);
31+
if (mapRes?.status == 200) {
32+
logger.info('Legacy CMS', {
33+
status: HTTP_CODES?.OK,
34+
message: HTTP_TEXTS?.LOCALE_SAVED,
35+
});
36+
} else {
37+
logger.warn('Legacy CMS error:', {
38+
status: HTTP_CODES?.UNAUTHORIZED,
39+
message: HTTP_TEXTS?.LOCALE_FAILED,
40+
});
41+
}
42+
}
43+
1744
const createSitecoreMapper = async (filePath: string = "", projectId: string | string[], app_token: string | string[], affix: string | string[], config: object) => {
1845
try {
1946
const newPath = path.join(filePath, 'items');
2047
await ExtractFiles(newPath);
2148
const localeData = await extractLocales(path.join(filePath, 'items', 'master', 'sitecore', 'content'));
49+
await createLocaleSource?.({ app_token, localeData, projectId });
2250
await ExtractConfiguration(newPath);
2351
await contentTypes(newPath, affix, config);
2452
const infoMap = await reference();
@@ -56,25 +84,6 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s
5684
status: HTTP_CODES?.OK,
5785
message: HTTP_TEXTS?.MAPPER_SAVED,
5886
});
59-
const mapperConfig = {
60-
method: 'post',
61-
maxBodyLength: Infinity,
62-
url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`,
63-
headers: {
64-
app_token,
65-
'Content-Type': 'application/json'
66-
},
67-
data: {
68-
locale: Array?.from?.(localeData) ?? []
69-
},
70-
};
71-
const mapRes = await axios.request(mapperConfig);
72-
if (mapRes?.status == 200) {
73-
logger.info('Legacy CMS', {
74-
status: HTTP_CODES?.OK,
75-
message: HTTP_TEXTS?.LOCALE_SAVED,
76-
});
77-
}
7887
}
7988
}
8089
} catch (err: any) {

0 commit comments

Comments
 (0)