Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/src/controllers/projects.contentMapper.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const resetContentType = async (req: Request, res: Response): Promise<void> => {
// res.status(200).json(resp);
// };

const getSingleContentTypes = async (
req: Request,
res: Response
): Promise<void> => {
const resp = await contentMapperService.getSingleContentTypes(req);
res.status(201).json(resp);
};

export const contentMapperController = {
getContentTypes,
getFieldMapping,
Expand All @@ -45,4 +53,5 @@ export const contentMapperController = {
putContentTypeFields,
resetContentType,
// removeMapping,
getSingleContentTypes
};
6 changes: 6 additions & 0 deletions api/src/routes/contentMapper.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ router.put(
"/resetFields/:orgId/:projectId/:contentTypeId",
asyncRouter(contentMapperController.resetContentType)
);
//get Single contenttype data
router.get(
"/:projectId/:contentTypeUid",
asyncRouter(contentMapperController.getSingleContentTypes)
);


export default router;
42 changes: 42 additions & 0 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,47 @@ const removeMapping = async (projectId: string) => {
);
}
};
const getSingleContentTypes = async (req: Request) => {
const projectId = req?.params?.projectId;
const contentTypeUID = req?.params?.contentTypeUid;
const { token_payload } = req.body;

const authtoken = await getAuthtoken(
token_payload?.region,
token_payload?.user_id
);
await ProjectModelLowdb.read();
const project = ProjectModelLowdb.chain
.get("projects")
.find({ id: projectId })
.value();
const stackId = project?.destination_stack_id;

const [err, res] = await safePromise(
https({
method: "GET",
url: `${config.CS_API[
token_payload?.region as keyof typeof config.CS_API
]!}/content_types/${contentTypeUID}`,
headers: {
api_key: stackId,
authtoken: authtoken,
},
})
);

if (err)
return {
data: err.response.data,
status: err.response.status,
};

return {
title: res?.data?.content_type?.title,
uid: res?.data?.content_type?.uid,
schema: res?.data?.content_type?.schema,
};
};

export const contentMapperService = {
putTestData,
Expand All @@ -645,4 +686,5 @@ export const contentMapperService = {
resetToInitialMapping,
resetAllContentTypesMapping,
removeMapping,
getSingleContentTypes
};