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
Next Next commit
feat: Added 2 new APIs for confirmations.
  • Loading branch information
hanoak20 committed Mar 13, 2024
commit d6c4d1cdbf8a844d8836bc20d71bdab11498a708
5 changes: 5 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const HTTP_TEXTS = {
PROJECT_CREATION_FAILED: "Error occurred while creating project.",
NO_PROJECT: "resource not found with the given ID(s).",
AFFIX_UPDATED: "Project's Affix updated successfully",
AFFIX_CONFIRMATION_UPDATED:
"Project's Affix confirmation updated successfully",
FILEFORMAT_CONFIRMATION_UPDATED:
"Project's Fileformat confirmation updated successfully",
CMS_UPDATED: "Project's migration cms updated successfully",
FILE_FORMAT_UPDATED: "Project's migration file format updated successfully",
DESTINATION_STACK_UPDATED:
Expand Down Expand Up @@ -81,6 +85,7 @@ export const VALIDATION_ERRORS = {
EMAIL_LIMIT: "Email's max limit reached.",
LENGTH_LIMIT: "$'s max limit reached.",
STRING_REQUIRED: "Provided $ should be a string.",
BOOLEAN_REQUIRED: "Provided $ should be a boolean.",
INVALID_REGION: "Provided region doesn't exists.",
FIELD_REQUIRED: "Field '$' is required.",
INVALID_AFFIX: "Invalid affix format",
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@ const updateAffix = async (req: Request, res: Response) => {
res.status(resp.status).json(resp.data);
};

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

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

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

const updateDestinationStack = async (req: Request, res: Response) => {
const resp = await projectService.updateDestinationStack(req);
res.status(resp.status).json(resp.data);
Expand All @@ -63,7 +73,9 @@ export const projectController = {
updateProject,
updateLegacyCMS,
updateAffix,
affixConfirmation,
updateFileFormat,
fileformatConfirmation,
updateDestinationStack,
updateCurrentStep,
deleteProject,
Expand Down
4 changes: 4 additions & 0 deletions src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
interface LegacyCMS {
cms: string;
affix: string;
affix_confirmation: boolean;
file_format: string;
file_format_confirmation: boolean;
file: {
id: string;
name: string;
Expand Down Expand Up @@ -70,7 +72,9 @@ const projectSchema = new Schema<ProjectDocument>(
legacy_cms: {
cms: { type: String },
affix: { type: String },
affix_confirmation: { type: Boolean },
file_format: { type: String },
file_format_confirmation: { type: Boolean },
file: {
id: { type: String },
name: { type: String },
Expand Down
14 changes: 14 additions & 0 deletions src/routes/projects.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,27 @@ router.put(
asyncRouter(projectController.updateAffix)
);

// Update project's Affix confirmation
router.put(
"/:projectId/affix_confirmation",
validator("affix_confirmation_validator"),
asyncRouter(projectController.affixConfirmation)
);

// Update project's file format
router.put(
"/:projectId/file-format",
validator("file_format"),
asyncRouter(projectController.updateFileFormat)
);

// Update project's fileformat confirmation
router.put(
"/:projectId/fileformat_confirmation",
validator("fileformat_confirmation_validator"),
asyncRouter(projectController.fileformatConfirmation)
);

// Update project's destination-cms
router.put(
"/:projectId/destination-stack",
Expand Down
56 changes: 56 additions & 0 deletions src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,33 @@ const updateAffix = async (req: Request) => {
};
};

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

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

project.legacy_cms.affix_confirmation = affix_confirmation;

await project.save();

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

const updateFileFormat = async (req: Request) => {
const { orgId, projectId } = req.params;
const { token_payload, file_format } = req.body;
Expand Down Expand Up @@ -382,6 +409,33 @@ const updateFileFormat = async (req: Request) => {
}
};

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

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

project.legacy_cms.file_format_confirmation = fileformat_confirmation;

await project.save();

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

const updateDestinationStack = async (req: Request) => {
const { orgId, projectId } = req.params;
const { token_payload, stack_api_key } = req.body;
Expand Down Expand Up @@ -584,7 +638,9 @@ export const projectService = {
updateProject,
updateLegacyCMS,
updateAffix,
affixConfirmation,
updateFileFormat,
fileformatConfirmation,
updateDestinationStack,
updateCurrentStep,
deleteProject,
Expand Down
15 changes: 15 additions & 0 deletions src/validators/affix-confirmation.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { checkSchema } from "express-validator";
import { VALIDATION_ERRORS } from "../constants";

export default checkSchema({
affix_confirmation: {
in: "body",
isBoolean: {
errorMessage: VALIDATION_ERRORS.BOOLEAN_REQUIRED.replace(
"$",
"affix_confirmation"
),
bail: true,
},
},
});
15 changes: 15 additions & 0 deletions src/validators/fileformat-confirmation.validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { checkSchema } from "express-validator";
import { VALIDATION_ERRORS } from "../constants";

export default checkSchema({
fileformat_confirmation: {
in: "body",
isBoolean: {
errorMessage: VALIDATION_ERRORS.BOOLEAN_REQUIRED.replace(
"$",
"fileformat_confirmation"
),
bail: true,
},
},
});
4 changes: 4 additions & 0 deletions src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import cmsValidator from "./cms.validator";
import fileFormatValidator from "./file-format.validator";
import destinationStackValidator from "./destination-stack.validator";
import affixValidator from "./affix.validator";
import affixConfirmationValidator from "./affix-confirmation.validator";
import fileformatConfirmationValidator from "./fileformat-confirmation.validator";

export default (route: string = "") =>
asyncRouter(async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -17,6 +19,8 @@ export default (route: string = "") =>
file_format: fileFormatValidator,
destination_stack: destinationStackValidator,
affix: affixValidator,
affix_confirmation_validator: affixConfirmationValidator,
fileformat_confirmation_validator: fileformatConfirmationValidator,
};

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