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
4 changes: 3 additions & 1 deletion api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export const HTTP_TEXTS = {
ADMIN_LOGIN_ERROR:
"Sorry, You Don't have admin access in any of the Organisation",
PROJECT_DELETE:
"Project Deleted Successfully"
"Project Deleted Successfully",
PROJECT_REVERT:
"Project Reverted Successfully"
};

export const HTTP_RESPONSE_HEADERS = {
Expand Down
6 changes: 6 additions & 0 deletions api/src/controllers/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const deleteProject = async (req: Request, res: Response): Promise<void> => {
res.status(200).json(project);
};

const revertProject = async (req: Request, res: Response): Promise<void> => {
const project = await projectService.revertProject(req);
res.status(project.status).json(project);
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add validation

export const projectController = {
getAllProjects,
getProject,
Expand All @@ -72,4 +77,5 @@ export const projectController = {
updateDestinationStack,
updateCurrentStep,
deleteProject,
revertProject
};
3 changes: 3 additions & 0 deletions api/src/routes/projects.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ router.put(
// Delete a project route
router.delete("/:projectId", asyncRouter(projectController.deleteProject));

//revert Project Route
router.patch("/:projectId", asyncRouter(projectController.revertProject))

export default router;
44 changes: 44 additions & 0 deletions api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const getAllProjects = async (req: Request) => {
org_id: orgId,
region,
owner: user_id,
isDeleted:false
})
.value();

Expand Down Expand Up @@ -748,6 +749,48 @@ const deleteProject = async (req: Request) => {
};
};

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

await ProjectModelLowdb.read();
const projectIndex = (await getProjectUtil(
projectId,
{
id: projectId,
org_id: orgId,
region: region,
owner: user_id,
},
srcFunc,
true
)) as number;

const projects = ProjectModelLowdb.data.projects[projectIndex];
if (!projects){
throw new NotFoundError(HTTP_TEXTS.PROJECT_NOT_FOUND);
} else{
ProjectModelLowdb.update((data: any) => {
data.projects[projectIndex].isDeleted = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add validation

});
logger.info(
getLogMessage(
srcFunc,
`Project [Id : ${projectId}] Reverted Successfully`,
decodedToken
)
);
return {
status: HTTP_CODES.OK,
data: {
message: HTTP_TEXTS.PROJECT_REVERT,
Project:projects
},
};
}
}
export const projectService = {
getAllProjects,
getProject,
Expand All @@ -761,4 +804,5 @@ export const projectService = {
updateDestinationStack,
updateCurrentStep,
deleteProject,
revertProject
};