Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
stacks limit check
  • Loading branch information
RohitKini committed Sep 26, 2024
commit c456e3e341e654a61eda8882377abcec66c45b6e
15 changes: 14 additions & 1 deletion api/src/controllers/org.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@ const getStackLocale = async (req: Request, res: Response) => {
res.status(resp.status).json(resp.data);
};

/* Retrieves the org details.
*
* @param req - The request object.
* @param res - The response object.
* @returns A Promise that resolves to the org details response.
*/
const getOrgDetails = async (req: Request, res: Response) => {
const resp = await orgService.getOrgDetails(req);
res.status(resp.status).json(resp.data);
};



export const orgController = {
getAllStacks,
createStack,
getLocales,
getStackStatus,
getStackLocale
getStackLocale,
getOrgDetails,
};
9 changes: 9 additions & 0 deletions api/src/routes/org.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ router.post(
router.get("/get_stack_locales", asyncRouter(orgController.getStackLocale));


/**
* GET all contentstack org details route.
* @param req - Express request object.
* @param res - Express response object.
*/
router.get("/get_org_details", asyncRouter(orgController.getOrgDetails));



export default router;
58 changes: 58 additions & 0 deletions api/src/services/org.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,68 @@ const getStackLocale = async (req: Request) => {
}
};

/**
* Retrieves the plan details of a org.
* @param req - The request object containing the orgId, token_payload.
* @returns An object containing the org details.
* @throws ExceptionFunction if an error occurs while getting the org details.
*/
const getOrgDetails = async (req: Request) => {
const { orgId } = req.params;
const { token_payload } = req.body;
const srcFunc = "getOrgDetails";

const authtoken = await getAuthtoken(
token_payload?.region,
token_payload?.user_id
);

try {
const [stackErr, stackRes] = await safePromise(
https({
method: "GET",
url: `${config.CS_API[
token_payload?.region as keyof typeof config.CS_API
]!}/organizations/${orgId}?include_plan=true`,
headers: {
authtoken,
},
})
);

if (stackErr)
return {
data: {
message: HTTP_TEXTS.DESTINATION_STACK_ERROR,
},
status: stackErr.response.status,
};

return {
status: HTTP_CODES.OK,
data: stackRes.data,
};
} catch (error: any) {
logger.error(
getLogMessage(
srcFunc,
`Error occurred while getting locales a stack.`,
token_payload,
error
)
);
throw new ExceptionFunction(
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
error?.statusCode || error?.status || HTTP_CODES.SERVER_ERROR
);
}
};

export const orgService = {
getAllStacks,
getLocales,
createStack,
getStackStatus,
getStackLocale,
getOrgDetails,
};
11 changes: 10 additions & 1 deletion ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/src/components/TestMigration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const TestMigration = () => {
<div className='content-block'>
<div className='content-header'>Execution Logs</div>
<div>
<LogViewer serverPath="http://localhost:5000" />
<LogViewer serverPath="http://localhost:5001" />
</div>
</div>
</div>
Expand Down
22 changes: 21 additions & 1 deletion ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { RootState } from '../../store';
import { updateMigrationData, updateNewMigrationData } from '../../store/slice/migrationDataSlice';

// Services
import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, createTestStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation, updateStackDetails } from '../../services/api/migration.service';
import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, createTestStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation, updateStackDetails, getOrgDetails } from '../../services/api/migration.service';
import { getAllStacksInOrg } from '../../services/api/stacks.service';
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';

// Utilities
Expand Down Expand Up @@ -367,6 +368,25 @@ const Migration = () => {
const handleOnClickContentMapper = async (event: MouseEvent) => {
setIsModalOpen(true);

//get org plan details
const orgDetails = await getOrgDetails(selectedOrganisation?.value);
const stacks_details_key = Object.keys(orgDetails?.data?.organization?.plan?.features).find(key => orgDetails?.data?.organization?.plan?.features[key].uid === 'stacks') || '';

const max_stack_limit = orgDetails?.data?.organization?.plan?.features[stacks_details_key]?.max_limit;

const stackData = await getAllStacksInOrg(selectedOrganisation?.value, ''); // org id will always be there

const stack_count = stackData?.data?.stacks?.length;

if (stack_count >= max_stack_limit) {
setIsLoading(false);
Notification({
notificationContent: { text: 'You have reached the maximum limit of stacks for your organization' },
type: 'warning'
});
return;
}

if(newMigrationData?.content_mapping?.isDropDownChanged){
return cbModal({
component: (props: ModalObj) => (
Expand Down
12 changes: 11 additions & 1 deletion ui/src/services/api/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,14 @@ export const updateStackDetails = async(orgId: string, projectId: string, data:
return error;

}
}
}

export const getOrgDetails = async(orgId: string) => {
try {
return await getCall(`${API_VERSION}/org/${orgId}/get_org_details`, options);
} catch (error) {
return error;
}
}

// const { orgId } = req.params;
2 changes: 1 addition & 1 deletion upload-api/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PORT=4002
NODE_BACKEND_API =http://localhost:5000
NODE_BACKEND_API =http://localhost:5001
2 changes: 1 addition & 1 deletion upload-api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default {
bucketName: 'migartion-test',
buketKey: 'project/package 45.zip'
},
localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip'
localPath: '/Users/rohit/Desktop/package 45.zip'
};