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
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const constants = {
MIGRATION_UPDATED: "Project's migration updated successfully.",
CMS_UPDATED: "Project's migration cms updated successfully",
FILE_FORMAT_UPDATED: "Project's migration file format updated successfully",
DESTINATION_CMS_UPDATED:
"Project's migration destination cms updated successfully",
MIGRATION_DELETED: "Project's migration deleted successfully.",
INVALID_ID: "Provided $ ID is invalid.",
MIGRATION_EXISTS: "Project's migration already exists.",
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/projects.migrations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const updateMigrationFileFormat = async (req: Request, res: Response) => {
res.status(resp.status).json(resp.data);
};

const updateMigrationDestinationCMS = async (req: Request, res: Response) => {
const resp = await migrationService.updateMigrationDestinationCMS(req);
res.status(resp.status).json(resp.data);
};

const deleteMigration = async (req: Request, res: Response) => {
const resp = await migrationService.deleteMigration(req);
res.status(resp.status).json(resp.data);
Expand All @@ -37,4 +42,5 @@ export const migrationController = {
deleteMigration,
updateMigrationLegacyCMS,
updateMigrationFileFormat,
updateMigrationDestinationCMS,
};
7 changes: 7 additions & 0 deletions src/routes/projects.migrations.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ router.put(
asyncRouter(migrationController.updateMigrationFileFormat)
);

// Update project's destination-cms
router.put(
"/destination-cms",
validator("destination_cms"),
asyncRouter(migrationController.updateMigrationDestinationCMS)
);

// Delete project's migration route
router.delete("/", asyncRouter(migrationController.deleteMigration));

Expand Down
25 changes: 25 additions & 0 deletions src/services/projects.migrations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ const updateMigrationFileFormat = async (req: Request) => {
};
};

const updateMigrationDestinationCMS = async (req: Request) => {
const { orgId, projectId } = req.params;
const { token_payload, stack_api_key } = req.body;

const project = await _getProject(projectId, {
_id: projectId,
org_id: orgId,
region: token_payload?.region,
owner: token_payload?.user_id,
});

project.migration.modules.destination_cms.stack_id = stack_api_key;
project.migration.modules.destination_cms.org_id = orgId;

await project.save();

return {
status: constants.HTTP_CODES.OK,
data: {
message: constants.HTTP_TEXTS.DESTINATION_CMS_UPDATED,
},
};
};

const deleteMigration = async (req: Request) => {
const orgId = req?.params?.orgId;
const projectId = req?.params?.projectId;
Expand Down Expand Up @@ -208,4 +232,5 @@ export const migrationService = {
deleteMigration,
updateMigrationLegacyCMS,
updateMigrationFileFormat,
updateMigrationDestinationCMS,
};
27 changes: 27 additions & 0 deletions src/validators/destination-cms.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { checkSchema } from "express-validator";
import { constants } from "../constants";

export default checkSchema({
stack_api_key: {
in: "body",
isString: {
errorMessage: constants.VALIDATION_ERRORS.STRING_REQUIRED.replace(
"$",
"stack_api_key"
),
bail: true,
},
trim: true,
isLength: {
errorMessage: constants.VALIDATION_ERRORS.LENGTH_LIMIT.replace(
"$",
"stack_api_key"
),
options: {
min: 1,
max: 400,
},
bail: true,
},
},
});
2 changes: 2 additions & 0 deletions src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import authValidator from "./auth.validator";
import projectValidator from "./project.validator";
import cmsValidator from "./cms.validator";
import fileFormatValidator from "./file-format.validator";
import destinationCmsValidator from "./destination-cms.validator";

export default (route: string = "") =>
asyncRouter(async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -13,6 +14,7 @@ export default (route: string = "") =>
project: projectValidator,
cms: cmsValidator,
file_format: fileFormatValidator,
destination_cms: destinationCmsValidator,
};

const validator = appValidators[route as keyof typeof appValidators];
Expand Down