Skip to content
Merged

Dev #168

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a6ec05a
refactor:updated file format to show file format of cms
AishDani Jun 27, 2024
97ac8c7
refactor:legacy cms bugs
AishDani Jun 27, 2024
c43ad23
Merge branch 'dev' of github.com:contentstack/migration-v2-node-serve…
AishDani Jun 27, 2024
44e5b20
added profile card
RohitKini Jul 2, 2024
4d7423d
added profile card
RohitKini Jul 2, 2024
cc89f4a
Merge pull request #163 from contentstack/feature/profile-design
sreeneshkini Jul 2, 2024
f861ca5
Done functionality fixes for existing content type mapping
sayalijoshi27 Jul 2, 2024
2203b2f
Merge pull request #164 from contentstack/feature/CMG-57
v1shalpatel Jul 3, 2024
417515d
Content Type status modified functionality
sayalijoshi27 Jul 3, 2024
ce6b331
Removed code for search fieldsmapping as per content type
sayalijoshi27 Jul 4, 2024
00058d3
refactor:legacy cms bugs
AishDani Jul 4, 2024
9dab0fc
Merge pull request #165 from contentstack/feature/CMG-57
v1shalpatel Jul 4, 2024
a45ee93
Merge branch 'dev' of github.com:contentstack/migration-v2-node-serve…
AishDani Jul 4, 2024
9b64a54
Merge branch 'dev' of github.com:contentstack/migration-v2-node-serve…
AishDani Jul 4, 2024
1867387
refactor:resolved legacy cms bugs
AishDani Jul 4, 2024
9e4653c
refactor:removed search from getAllProject api
AishDani Jul 4, 2024
0765dfc
Merge pull request #166 from contentstack/feature/legacy-cms
v1shalpatel Jul 4, 2024
3bec73b
added destination bugs
snehalsankhe Jul 4, 2024
ec50c84
merged from dev
snehalsankhe Jul 4, 2024
690c223
Merge pull request #167 from contentstack/layout-changes
v1shalpatel Jul 4, 2024
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
8 changes: 7 additions & 1 deletion api/src/controllers/projects.contentMapper.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const resetContentType = async (req: Request, res: Response): Promise<void> => {
// res.status(200).json(resp);
// };

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

const getSingleContentTypes = async (
req: Request,
res: Response
Expand All @@ -53,5 +58,6 @@ export const contentMapperController = {
putContentTypeFields,
resetContentType,
// removeMapping,
getSingleContentTypes
getSingleContentTypes,
removeContentMapper
};
2 changes: 1 addition & 1 deletion api/src/models/contentTypesMapper-lowdb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONFile } from "lowdb/node";
import LowWithLodash from "../utils/lowdb-lodash.utils.js";

interface ContentTypesMapper {
export interface ContentTypesMapper {
id: string;
otherCmsTitle: string;
otherCmsUid: string;
Expand Down
5 changes: 5 additions & 0 deletions api/src/routes/contentMapper.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ router.get(
"/:projectId/:contentTypeUid",
asyncRouter(contentMapperController.getSingleContentTypes)
);
//remove content mapper
router.get(
"/:orgId/:projectId/content-mapper",
asyncRouter(contentMapperController.removeContentMapper)
);


export default router;
95 changes: 93 additions & 2 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ProjectModelLowdb from "../models/project-lowdb.js";
import FieldMapperModel from "../models/FieldMapper.js";
import { v4 as uuidv4 } from "uuid";
import ContentTypesMapperModelLowdb from "../models/contentTypesMapper-lowdb.js";
import { ContentTypesMapper } from "../models/contentTypesMapper-lowdb.js";

// Developer service to create dummy contentmapping data
const putTestData = async (req: Request) => {
Expand Down Expand Up @@ -524,7 +525,7 @@ const resetAllContentTypesMapping = async (projectId: string) => {
try {
const contentTypes = cData;
for (const contentType of contentTypes) {
if (!isEmpty(contentType.fieldMapping)) {
if (contentType && !isEmpty(contentType.fieldMapping)) {
for (const field of contentType.fieldMapping) {
await FieldMapperModel.read();
const fieldData = FieldMapperModel.chain
Expand Down Expand Up @@ -561,8 +562,10 @@ const resetAllContentTypesMapping = async (projectId: string) => {
});
}
}

}


return projectDetails;
} catch (error: any) {
logger.error(
Expand Down Expand Up @@ -610,7 +613,7 @@ const removeMapping = async (projectId: string) => {
//TODO: remove fieldMapping ids in ContentTypesMapperModel for each content types

for (const contentType of contentTypes) {
if (!isEmpty(contentType.fieldMapping)) {
if (contentType && !isEmpty(contentType.fieldMapping)) {
for (const field of contentType.fieldMapping) {
await FieldMapperModel.read();
const fieldIndex = FieldMapperModel.chain
Expand Down Expand Up @@ -706,6 +709,93 @@ const getSingleContentTypes = async (req: Request) => {
schema: res?.data?.content_type?.schema,
};
};
const removeContentMapper = async (req: Request) => {
const projectId = req?.params?.projectId;
const srcFunc = "removeMapping";
await ProjectModelLowdb.read();
const projectDetails = ProjectModelLowdb.chain
.get("projects")
.find({ id: projectId })
.value();

if (isEmpty(projectDetails)) {
logger.error(
getLogMessage(
srcFunc,
`${HTTP_TEXTS.PROJECT_NOT_FOUND} projectId: ${projectId}`
)
);
throw new BadRequestError(HTTP_TEXTS.PROJECT_NOT_FOUND);
}
await ContentTypesMapperModelLowdb.read();
const cData: ContentTypesMapper[] = projectDetails?.content_mapper.map((cId: string) => {
const contentTypeData: ContentTypesMapper = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.find({ id: cId })
.value();
return contentTypeData;
});

try {
const contentTypes: ContentTypesMapper[] = cData;
//TODO: remove fieldMapping ids in ContentTypesMapperModel for each content types

for (const contentType of contentTypes) {
if (contentType && !isEmpty(contentType.fieldMapping)) {
for (const field of contentType.fieldMapping) {
await FieldMapperModel.read();
const fieldIndex = FieldMapperModel.chain
.get("field_mapper")
.findIndex({ id: field })
.value();
if (fieldIndex > -1) {
await FieldMapperModel.update((fData: any) => {
delete fData.field_mapper[fieldIndex];
});
}
}
}
await ContentTypesMapperModelLowdb.read();
if (!isEmpty(contentType?.id)) {
const cIndex = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.findIndex({ id: contentType?.id })
.value();
if (cIndex > -1) {
await ContentTypesMapperModelLowdb.update((data: any) => {
delete data.ContentTypesMappers[cIndex];
});
}
}
}

await ProjectModelLowdb.read();
const projectIndex = ProjectModelLowdb.chain
.get("projects")
.findIndex({ id: projectId })
.value();

if (projectIndex > -1) {
ProjectModelLowdb.update((data: any) => {
data.projects[projectIndex].content_mapper = [];
});
}
return projectDetails;
} catch (error: any) {
logger.error(
getLogMessage(
srcFunc,
`Error occurred while removing the content mapping for the Project [Id: ${projectId}]`,
{},
error
)
);
throw new ExceptionFunction(
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
error?.statusCode || error?.status || HTTP_CODES.SERVER_ERROR
);
}
};

export const contentMapperService = {
putTestData,
Expand All @@ -715,6 +805,7 @@ export const contentMapperService = {
updateContentType,
resetToInitialMapping,
resetAllContentTypesMapping,
removeContentMapper,
removeMapping,
getSingleContentTypes
};
5 changes: 3 additions & 2 deletions api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { v4 as uuidv4 } from "uuid";

const getAllProjects = async (req: Request) => {
const orgId = req?.params?.orgId;
const decodedToken = req.body.token_payload;
const { user_id = "", region = "" } = decodedToken;

const decodedToken = req.body.token_payload;
const { user_id = "", region = "" } = decodedToken;

await ProjectModelLowdb.read();
const projects = ProjectModelLowdb.chain
.get("projects")
Expand Down
Loading