V1 folder created For auth Data project, trash, home page based on the token and role based
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
RecentlyAdded,
|
||||
searchProject,
|
||||
searchTrashProject,
|
||||
} from "../../../../shared/services/v1home/v1homeservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
if (!userId || !organization || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RecentlyAdded({ userId, organization, role });
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Datas were empty":
|
||||
res.status(200).json({
|
||||
RecentlyViewed: [],
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
RecentlyViewed: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
searchName: string;
|
||||
userId: string;
|
||||
};
|
||||
if (!userId || !organization || !searchName) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await searchProject({
|
||||
searchName,
|
||||
organization,
|
||||
userId,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(200).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
projectData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchTrashProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
searchName: string;
|
||||
userId: string;
|
||||
};
|
||||
if (!userId || !organization || !searchName) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await searchTrashProject({
|
||||
searchName,
|
||||
organization,
|
||||
userId,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(200).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
projectData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,270 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
createProject,
|
||||
DeleteProject,
|
||||
GetAllProjects,
|
||||
updateProject,
|
||||
viewProject,
|
||||
} from "../../../../shared/services/v1Project/v1projectservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const createProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
console.log("req.user: ", req.user);
|
||||
const { projectUuid, thumbnail } = req.body;
|
||||
if (!req.user || !req.user.userId || !req.user.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectUuid || !thumbnail) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await createProject({ ...req.body, userId, organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "project_exists":
|
||||
res.status(403).json({
|
||||
message: "Project already exists",
|
||||
});
|
||||
break;
|
||||
|
||||
case "user_not_found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
message: "Project created Successfully",
|
||||
projectId: result.project._id,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const GetProjects = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
// const { userId, organization } = req.params;
|
||||
if (!userId || !organization || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await GetAllProjects({ userId, organization, role });
|
||||
switch (result?.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
Projects: result?.Datas,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const RemoveProject = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
// const { organization, userId } = req.body;
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectId || !organization || !userId || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
message: "Project Deleted Successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const updateProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
const { projectId } = req.params;
|
||||
const { projectName, thumbnail } = req.body;
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await updateProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
projectName,
|
||||
thumbnail,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Project updated Successfully",
|
||||
projectData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const ViewData = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
const { projectId } = req.params as {
|
||||
projectId: string;
|
||||
};
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await viewProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
projectData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
TrashDatas,
|
||||
RestoreTrashData,
|
||||
} from "../../../../shared/services/v1trash/v1trashservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const GetTrashList = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
if (!organization || !role || !userId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await TrashDatas({ organization, role, userId });
|
||||
|
||||
switch (result.status) {
|
||||
case "Trash is Empty":
|
||||
res.status(200).json({
|
||||
message: "Trash is Empty",
|
||||
TrashDatas: [],
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.ListDatas,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const RestoreTrash = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
const { projectId } = req.query as {
|
||||
projectId: string;
|
||||
};
|
||||
if (!organization || !projectId || !role || !userId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RestoreTrashData({
|
||||
organization,
|
||||
projectId,
|
||||
role,
|
||||
userId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Project Restore unsuccessfull":
|
||||
res.status(200).json({
|
||||
message: "Project Restore unsuccessfull",
|
||||
});
|
||||
break;
|
||||
case "Project Restored successfully":
|
||||
res.status(200).json({
|
||||
message: "Project Restored successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -7,20 +7,6 @@ import {
|
||||
SignupController,
|
||||
} from "../v1Controllers/authController/authControllers.ts";
|
||||
import { versioncontroller } from "../v1Controllers/versionController/versioncontroller.ts";
|
||||
import {
|
||||
createProjectController,
|
||||
GetProjects,
|
||||
RemoveProject,
|
||||
updateProjectController,
|
||||
ViewData,
|
||||
} from "../../controller/project/projectController.ts";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
import { recentDataController } from "../../controller/home/homeControllers.ts";
|
||||
import {
|
||||
GetTrashList,
|
||||
RestoreTrash,
|
||||
} from "../../controller/trash/trashcontrollers.ts";
|
||||
|
||||
const Authrouter = express.Router();
|
||||
Authrouter.post("/Auth/signup", SignupController);
|
||||
@@ -30,54 +16,4 @@ Authrouter.post("/Auth/forgetPassword", ForgetPasswordController);
|
||||
Authrouter.post("/Auth/reset-password/:resetToken", ResetPasswordController);
|
||||
Authrouter.post("/Auth/versionData", versioncontroller);
|
||||
|
||||
// project
|
||||
Authrouter.post("/Auth/upsertProject", tokenValidator, createProjectController);
|
||||
Authrouter.get(
|
||||
"/Auth/Projects",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetProjects
|
||||
);
|
||||
Authrouter.patch(
|
||||
"/Auth/Project/archive/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RemoveProject
|
||||
);
|
||||
|
||||
Authrouter.patch(
|
||||
"/Auth/Project/modify",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
updateProjectController
|
||||
);
|
||||
Authrouter.get(
|
||||
"/Auth/Project/view",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
ViewData
|
||||
);
|
||||
|
||||
//home-Page
|
||||
Authrouter.get(
|
||||
"/Auth/RecentlyViewed",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
recentDataController
|
||||
);
|
||||
|
||||
//trash
|
||||
Authrouter.get(
|
||||
"/Auth/Trash/Lists",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetTrashList
|
||||
);
|
||||
|
||||
Authrouter.patch(
|
||||
"/Auth/restore",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RestoreTrash
|
||||
);
|
||||
export default Authrouter;
|
||||
|
||||
16
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
16
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import express from "express";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
import { recentDataController } from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
||||
|
||||
const v1homeRoutes = express.Router();
|
||||
|
||||
//home-Page
|
||||
v1homeRoutes.get(
|
||||
"/RecentlyViewed",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
recentDataController
|
||||
);
|
||||
|
||||
export default v1homeRoutes;
|
||||
42
src/api-server/V1/v1Routes/v1-projectRoutes.ts
Normal file
42
src/api-server/V1/v1Routes/v1-projectRoutes.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createProjectController,
|
||||
GetProjects,
|
||||
RemoveProject,
|
||||
updateProjectController,
|
||||
ViewData,
|
||||
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
|
||||
const v1projectRouter = express.Router();
|
||||
|
||||
// project
|
||||
v1projectRouter.post("/upsertProject", tokenValidator, createProjectController);
|
||||
v1projectRouter.get(
|
||||
"/Projects",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetProjects
|
||||
);
|
||||
v1projectRouter.patch(
|
||||
"/Project/archive/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RemoveProject
|
||||
);
|
||||
|
||||
v1projectRouter.patch(
|
||||
"/Project/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
updateProjectController
|
||||
);
|
||||
v1projectRouter.get(
|
||||
"/Project/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
ViewData
|
||||
);
|
||||
|
||||
export default v1projectRouter;
|
||||
25
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
25
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import express from "express";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
import {
|
||||
GetTrashList,
|
||||
RestoreTrash,
|
||||
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
||||
|
||||
const v1TrashRoutes = express.Router();
|
||||
|
||||
//trash
|
||||
v1TrashRoutes.get(
|
||||
"/TrashItems ",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetTrashList
|
||||
);
|
||||
|
||||
v1TrashRoutes.patch(
|
||||
"/Trash/restore",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RestoreTrash
|
||||
);
|
||||
export default v1TrashRoutes;
|
||||
@@ -22,6 +22,9 @@ import trashRouter from "./Routes/trashRoutes.ts";
|
||||
import homePageRouter from "./Routes/homepageRoutes.ts";
|
||||
import redis from "../shared/redis/redis.ts";
|
||||
import Authrouter from "./V1/v1Routes/authRoutes.ts";
|
||||
import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
||||
import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
||||
import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||
redis;
|
||||
const app = express();
|
||||
@@ -90,7 +93,10 @@ app.use("/api/v1", projectRouter);
|
||||
app.use("/api/v1", trashRouter);
|
||||
app.use("/api/v1", homePageRouter);
|
||||
|
||||
//New versions
|
||||
app.use("/API/V1", Authrouter);
|
||||
//New versions--based on the token and role based
|
||||
app.use("/api", Authrouter);
|
||||
app.use("/api/v2", v1projectRouter);
|
||||
app.use("/api/v2", v1TrashRoutes);
|
||||
app.use("/api/v2", v1homeRoutes);
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
import { Request, Response } from "express";
|
||||
import { RecentlyAdded, searchProject, searchTrashProject } from "../../../shared/services/home/homeService.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
import {
|
||||
RecentlyAdded,
|
||||
searchProject,
|
||||
searchTrashProject,
|
||||
} from "../../../shared/services/home/homeService.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization,role } = req.user||{};
|
||||
if (!userId || !organization||!role) {
|
||||
const { userId, organization } = req.params;
|
||||
if (!userId || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RecentlyAdded({ userId, organization,role });
|
||||
const result = await RecentlyAdded({ userId, organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
@@ -45,7 +48,10 @@ export const recentDataController = async (
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -92,7 +98,10 @@ export const searchProjectController = async (req: Request, res: Response): Prom
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchTrashProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchTrashProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -138,4 +147,4 @@ export const searchTrashProjectController = async (req: Request, res: Response):
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,27 +6,20 @@ import {
|
||||
updateProject,
|
||||
viewProject,
|
||||
} from "../../../shared/services/project/project-Services.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
|
||||
export const createProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
console.log("req.user: ", req.user);
|
||||
const { projectUuid, thumbnail } = req.body;
|
||||
if (!req.user || !req.user.userId || !req.user.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectUuid || !thumbnail) {
|
||||
const { projectUuid, userId, thumbnail, organization } = req.body;
|
||||
if (!projectUuid || !userId || !thumbnail || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await createProject({ ...req.body, userId, organization });
|
||||
const result = await createProject(req.body);
|
||||
|
||||
switch (result.status) {
|
||||
case "project_exists":
|
||||
@@ -61,19 +54,18 @@ export const createProjectController = async (
|
||||
}
|
||||
};
|
||||
export const GetProjects = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
// const { userId, organization } = req.params;
|
||||
if (!userId || !organization || !role) {
|
||||
const { userId, organization } = req.params;
|
||||
if (!userId || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await GetAllProjects({ userId, organization, role });
|
||||
const result = await GetAllProjects({ userId, organization });
|
||||
switch (result?.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
@@ -100,34 +92,19 @@ export const GetProjects = async (
|
||||
}
|
||||
};
|
||||
export const RemoveProject = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
// const { organization, userId } = req.body;
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectId || !organization || !userId || !role) {
|
||||
const { organization, userId } = req.body;
|
||||
if (!projectId || !organization || !userId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
const result = await DeleteProject({ projectId, organization, userId });
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
@@ -158,13 +135,13 @@ export const RemoveProject = async (
|
||||
}
|
||||
};
|
||||
export const updateProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
const { projectId, projectName, thumbnail } = req.body;
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
const { projectId, organization, projectName, thumbnail, userId } =
|
||||
req.body;
|
||||
if (!userId || !organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -176,7 +153,6 @@ export const updateProjectController = async (
|
||||
userId,
|
||||
projectName,
|
||||
thumbnail,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
@@ -208,25 +184,14 @@ export const updateProjectController = async (
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const ViewData = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
export const ViewData = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
const { projectId } = req.query as {
|
||||
const { projectId, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
userId: string;
|
||||
};
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
if (!userId || !organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -236,7 +201,6 @@ export const ViewData = async (
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
|
||||
@@ -3,21 +3,20 @@ import {
|
||||
TrashDatas,
|
||||
RestoreTrashData,
|
||||
} from "../../../shared/services/trash/trashService.ts";
|
||||
import { AuthenticatedRequest } from "../../../shared/utils/token.ts";
|
||||
|
||||
export const GetTrashList = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
if (!organization || !role || !userId) {
|
||||
const { organization } = req.query as { organization: string };
|
||||
if (!organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await TrashDatas({ organization, role, userId });
|
||||
const result = await TrashDatas({ organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "Trash is Empty":
|
||||
@@ -29,6 +28,7 @@ export const GetTrashList = async (
|
||||
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
// message: "Project created Successfully",
|
||||
TrashDatas: result.ListDatas,
|
||||
});
|
||||
break;
|
||||
@@ -47,26 +47,22 @@ export const GetTrashList = async (
|
||||
};
|
||||
|
||||
export const RestoreTrash = async (
|
||||
req: AuthenticatedRequest,
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
const { projectId } = req.query as {
|
||||
const { organization, projectId } = req.query as {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
};
|
||||
if (!organization || !projectId || !role || !userId) {
|
||||
console.log("organization: ", organization);
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RestoreTrashData({
|
||||
organization,
|
||||
projectId,
|
||||
role,
|
||||
userId,
|
||||
});
|
||||
const result = await RestoreTrashData({ organization, projectId });
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
|
||||
Reference in New Issue
Block a user