Skip to content

Commit 095b866

Browse files
committed
2 parents 2fc8000 + fcd2d92 commit 095b866

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ export const constants = {
6767
};
6868
export const PROJECT_POPULATE_FIELDS = "migration.modules.content_mapper";
6969
export const CONTENT_TYPE_POPULATE_FIELDS =
70-
"otherCmsTitle otherCmsUid isUpdated updateAt contentstackTitle contnetStackUid";
70+
"otherCmsTitle otherCmsUid isUpdated updateAt contentstackTitle contentStackUid";

src/models/contentTypesMapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ContentTypesMapper extends Document {
66
isUpdated: boolean;
77
updateAt: Date;
88
contentstackTitle: string;
9-
contnetStackUid: string;
9+
contentStackUid: string;
1010
fieldMapping: [];
1111
}
1212

@@ -16,7 +16,7 @@ const contentTypesMapperSchema = new Schema<ContentTypesMapper>({
1616
isUpdated: { type: Boolean, default: false },
1717
updateAt: { type: Date },
1818
contentstackTitle: { type: String },
19-
contnetStackUid: { type: String },
19+
contentStackUid: { type: String },
2020
fieldMapping: [{ type: Schema.Types.ObjectId, ref: "FieldMapping" }],
2121
});
2222

src/routes/contentMapper.routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ router.get(
1717
);
1818
//Get FieldMapping List
1919
router.get(
20-
"/fieldMappnig/:contentTypeId/:skip/:limit/:searchText?",
20+
"/fieldMapping/:contentTypeId/:skip/:limit/:searchText?",
2121
asyncRouter(contentMapperController.getFieldMapping)
2222
);
2323
//Get Existing ContentTypes List
24-
//To Do
24+
2525
router.get(
26-
"/:projectId/:stackUid",
26+
"/:projectId",
2727
asyncRouter(contentMapperController.getExistingContentTypes)
2828
);
2929
//Update FieldMapping or contentType

src/services/contentMapper.service.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Request } from "express";
22
import ContentTypesMapperModel from "../models/contentTypesMapper";
33
import FieldMapperModel from "../models/FieldMapper";
44
import ProjectModel from "../models/project";
5-
import { getLogMessage, isEmpty } from "../utils";
5+
import { getLogMessage, isEmpty, safePromise } from "../utils";
66
import {
77
BadRequestError,
88
ExceptionFunction,
@@ -13,6 +13,9 @@ import {
1313
constants,
1414
} from "../constants";
1515
import logger from "../utils/logger";
16+
import { config } from "../config";
17+
import https from "../utils/https.utils";
18+
import getAuthtoken from "../utils/auth.utils";
1619

1720
// Developer service to create dummy contentmapping data
1821
const putTestData = async (req: Request) => {
@@ -161,13 +164,46 @@ const getFieldMapping = async (req: Request) => {
161164
};
162165

163166
const getExistingContentTypes = async (req: Request) => {
164-
const orgId = req?.params?.orgId;
165167
const projectId = req?.params?.projectId;
166168

169+
const { token_payload } = req.body;
170+
171+
const authtoken = await getAuthtoken(
172+
token_payload?.region,
173+
token_payload?.user_id
174+
);
175+
const project = await ProjectModel.findById(projectId);
176+
const stackId = project?.migration?.modules?.destination_cms?.stack_id;
177+
const [err, res] = await safePromise(
178+
https({
179+
method: "GET",
180+
url: `${config.CS_API[
181+
token_payload?.region as keyof typeof config.CS_API
182+
]!}/content_types`,
183+
headers: {
184+
api_key: stackId,
185+
authtoken: authtoken,
186+
},
187+
})
188+
);
189+
190+
if (err)
191+
return {
192+
data: err.response.data,
193+
status: err.response.status,
194+
};
195+
196+
const contentTypes = res.data.content_types.map((singleCT: any) => {
197+
return {
198+
title: singleCT.title,
199+
uid: singleCT.uid,
200+
schema: singleCT.schema,
201+
};
202+
});
203+
167204
//Add logic to get Project from DB
168-
return { orgId, projectId };
205+
return { contentTypes };
169206
};
170-
171207
const udateContentType = async (req: Request) => {
172208
const srcFun = "udateContentType";
173209
const contentTypeId = req?.params?.contentTypeId;
@@ -196,7 +232,7 @@ const udateContentType = async (req: Request) => {
196232
isUpdated: contentTypeData?.isUpdated,
197233
updateAt: contentTypeData?.updateAt,
198234
contentstackTitle: contentTypeData?.contentstackTitle,
199-
contnetStackUid: contentTypeData?.contnetStackUid,
235+
contentStackUid: contentTypeData?.contentStackUid,
200236
},
201237
{ new: true, upsert: true, setDefaultsOnInsert: true }
202238
);

0 commit comments

Comments
 (0)