@@ -2,7 +2,7 @@ import { Request } from "express";
22import ContentTypesMapperModel from "../models/contentTypesMapper" ;
33import FieldMapperModel from "../models/FieldMapper" ;
44import ProjectModel from "../models/project" ;
5- import { getLogMessage , isEmpty } from "../utils" ;
5+ import { getLogMessage , isEmpty , safePromise } from "../utils" ;
66import {
77 BadRequestError ,
88 ExceptionFunction ,
@@ -13,6 +13,9 @@ import {
1313 constants ,
1414} from "../constants" ;
1515import 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
1821const putTestData = async ( req : Request ) => {
@@ -161,13 +164,46 @@ const getFieldMapping = async (req: Request) => {
161164} ;
162165
163166const 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-
171207const 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