RBAC, jwt implemented in Projects,home and collections routing
This commit is contained in:
2
.env
2
.env
@@ -14,4 +14,4 @@ REDIS_PORT=6379
|
|||||||
|
|
||||||
EMAIL_USER=nivetha@hexrfactory.com
|
EMAIL_USER=nivetha@hexrfactory.com
|
||||||
EMAIL_PASS=tikq fjry hzgr ootn
|
EMAIL_PASS=tikq fjry hzgr ootn
|
||||||
CLIENT_URL=http://192.168.0.104:9696
|
CLIENT_URL=http://192.168.0.102:9696
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import projectRoutes from "./routes/projectRoutes";
|
|||||||
import collectionNodeRoutes from "./routes/collectionRoutes";
|
import collectionNodeRoutes from "./routes/collectionRoutes";
|
||||||
import edgeRoutes from "./routes/edgeRoutes";
|
import edgeRoutes from "./routes/edgeRoutes";
|
||||||
import authRoutes from "./routes/authRoutes";
|
import authRoutes from "./routes/authRoutes";
|
||||||
|
import homeRoutes from "./routes/homeRoutes";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -18,5 +19,6 @@ app.use("/api/v1", authRoutes);
|
|||||||
app.use("/api/v1", projectRoutes);
|
app.use("/api/v1", projectRoutes);
|
||||||
app.use("/api/v1", collectionNodeRoutes);
|
app.use("/api/v1", collectionNodeRoutes);
|
||||||
app.use("/api/v1", edgeRoutes);
|
app.use("/api/v1", edgeRoutes);
|
||||||
|
app.use("/api/v1", homeRoutes);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ export const signinController = async (
|
|||||||
password,
|
password,
|
||||||
};
|
};
|
||||||
const result = await signinService(data);
|
const result = await signinService(data);
|
||||||
console.log("result: ", result);
|
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found!!! Kindly Signup":
|
case "User not found!!! Kindly Signup":
|
||||||
@@ -123,7 +122,6 @@ export const forgetPasswordController = async (
|
|||||||
email,
|
email,
|
||||||
};
|
};
|
||||||
const result = await forgetPassword(data);
|
const result = await forgetPassword(data);
|
||||||
console.log("result: ", result);
|
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found!!! Kindly Signup":
|
case "User not found!!! Kindly Signup":
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ import {
|
|||||||
SetCollectionName,
|
SetCollectionName,
|
||||||
UpdateAttributes,
|
UpdateAttributes,
|
||||||
} from "../../shared/services/collectionService";
|
} from "../../shared/services/collectionService";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
export const NodeCreationController = async (
|
export const NodeCreationController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, position } = req.body;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId || !position) {
|
const { projectId, position } = req.body;
|
||||||
|
if (!organization || !projectId || !position || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -27,6 +28,7 @@ export const NodeCreationController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
position,
|
position,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
const result = await Nodecreation(data);
|
const result = await Nodecreation(data);
|
||||||
|
|
||||||
@@ -59,19 +61,21 @@ export const NodeCreationController = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SetCollectionNameController = async (
|
export const SetCollectionNameController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const {
|
const { organization, userId } = req.user || {};
|
||||||
organization,
|
const { projectId, collectionNodeId, collectionName, position } = req.body;
|
||||||
projectId,
|
if (
|
||||||
collectionNodeId,
|
!organization ||
|
||||||
collectionName,
|
!projectId ||
|
||||||
position,
|
!userId ||
|
||||||
} = req.body;
|
!collectionName ||
|
||||||
if (!organization || !projectId || !collectionName || !collectionNodeId) {
|
!collectionNodeId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -80,6 +84,7 @@ export const SetCollectionNameController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
collectionName,
|
collectionName,
|
||||||
position,
|
position,
|
||||||
@@ -114,13 +119,15 @@ export const SetCollectionNameController = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CollectionDatas = async (
|
export const CollectionDatas = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, organization, collectionNodeId } = req.params;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId || !collectionNodeId) {
|
const { projectId, collectionNodeId } = req.params;
|
||||||
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -129,6 +136,7 @@ export const CollectionDatas = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
};
|
};
|
||||||
const result = await GetcollectionNode(data);
|
const result = await GetcollectionNode(data);
|
||||||
@@ -159,13 +167,15 @@ export const CollectionDatas = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteCollectionsController = async (
|
export const DeleteCollectionsController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, collectionNodeId } = req.params;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId || !collectionNodeId) {
|
const { projectId, collectionNodeId } = req.params;
|
||||||
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -174,6 +184,7 @@ export const DeleteCollectionsController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
};
|
};
|
||||||
const result = await delCollection(data);
|
const result = await delCollection(data);
|
||||||
@@ -203,15 +214,16 @@ export const DeleteCollectionsController = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DuplicateNodeCollectionController = async (
|
export const DuplicateNodeCollectionController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId } = req.params;
|
const { collectionNodeId } = req.params;
|
||||||
const { projectId, organization, collectionName, position, attributes } =
|
const { projectId, collectionName, position, attributes } = req.body;
|
||||||
req.body;
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
if (!organization || !projectId || !collectionNodeId) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -220,6 +232,7 @@ export const DuplicateNodeCollectionController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionName,
|
collectionName,
|
||||||
position,
|
position,
|
||||||
attributes,
|
attributes,
|
||||||
@@ -253,14 +266,14 @@ export const DuplicateNodeCollectionController = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const NodesCollectionsBasedOnproject = async (
|
export const NodesCollectionsBasedOnproject = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, organization } = req.params;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId) {
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !projectId || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -269,6 +282,7 @@ export const NodesCollectionsBasedOnproject = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
const result = await GetNodesInProject(data);
|
const result = await GetNodesInProject(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -300,13 +314,20 @@ export const NodesCollectionsBasedOnproject = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AddAttributesController = async (
|
export const AddAttributesController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId } = req.params;
|
const { collectionNodeId } = req.params;
|
||||||
const { organization, projectId, attributes } = req.body;
|
const { projectId, attributes } = req.body;
|
||||||
if (!organization || !projectId || !attributes || !collectionNodeId) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!attributes ||
|
||||||
|
!userId ||
|
||||||
|
!collectionNodeId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -315,6 +336,7 @@ export const AddAttributesController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
attributes,
|
attributes,
|
||||||
};
|
};
|
||||||
@@ -347,23 +369,23 @@ export const AddAttributesController = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateAttributesCollections = async (
|
export const updateAttributesCollections = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId, attributeId } = req.params;
|
const { collectionNodeId, attributeId } = req.params;
|
||||||
const {
|
const { projectId, required, defaultValue, unique, index, key, type } =
|
||||||
organization,
|
req.body;
|
||||||
projectId,
|
if (
|
||||||
required,
|
!organization ||
|
||||||
defaultValue,
|
!userId ||
|
||||||
unique,
|
!projectId ||
|
||||||
index,
|
!collectionNodeId ||
|
||||||
key,
|
!attributeId
|
||||||
type,
|
) {
|
||||||
} = req.body;
|
|
||||||
if (!organization || !projectId || !collectionNodeId || !attributeId) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -372,6 +394,7 @@ export const updateAttributesCollections = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
attributeId,
|
attributeId,
|
||||||
required,
|
required,
|
||||||
@@ -410,13 +433,20 @@ export const updateAttributesCollections = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const delAttributesCollections = async (
|
export const delAttributesCollections = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId } = req.params;
|
const { collectionNodeId } = req.params;
|
||||||
const { organization, projectId, AttributeId } = req.body;
|
const { projectId, AttributeId } = req.body;
|
||||||
if (!organization || !projectId || !collectionNodeId || !AttributeId) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!collectionNodeId ||
|
||||||
|
!AttributeId ||
|
||||||
|
!userId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -424,6 +454,7 @@ export const delAttributesCollections = async (
|
|||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
AttributeId,
|
AttributeId,
|
||||||
@@ -456,4 +487,3 @@ export const delAttributesCollections = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
45
src/api-server/controller/homePageController.ts
Normal file
45
src/api-server/controller/homePageController.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
import { recentlyViewedServices } from "../../shared/services/homePageService";
|
||||||
|
|
||||||
|
export const homePageRecentlyViewedController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
if (!organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await recentlyViewedServices(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(403).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
datas: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import {
|
import {
|
||||||
|
DeleteProject,
|
||||||
GetNodesInProject,
|
GetNodesInProject,
|
||||||
projectCreationService,
|
projectCreationService,
|
||||||
projectDatas,
|
projectDatas,
|
||||||
|
ViewProjectService,
|
||||||
} from "../../shared/services/projectService";
|
} from "../../shared/services/projectService";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
|
||||||
export const projectCreationController = async (
|
export const projectCreationController = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
@@ -26,7 +29,8 @@ export const projectCreationController = async (
|
|||||||
!projectName ||
|
!projectName ||
|
||||||
!userId ||
|
!userId ||
|
||||||
!apiType ||
|
!apiType ||
|
||||||
!architecture|| !application
|
!architecture ||
|
||||||
|
!application
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -37,7 +41,8 @@ export const projectCreationController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectName,
|
projectName,
|
||||||
useableLanguage,
|
useableLanguage,
|
||||||
description,application,
|
description,
|
||||||
|
application,
|
||||||
userId,
|
userId,
|
||||||
apiType,
|
apiType,
|
||||||
architecture,
|
architecture,
|
||||||
@@ -85,18 +90,19 @@ export const projectCreationController = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getProjects = async (
|
export const getProjects = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization } = req.body;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization) {
|
if (!organization || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await projectDatas(organization);
|
const result = await projectDatas({ organization, userId });
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "No project found":
|
case "No project found":
|
||||||
@@ -104,7 +110,7 @@ export const getProjects = async (
|
|||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Project created successfully",
|
// message: "Projec",
|
||||||
projectDatas: result.data,
|
projectDatas: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -121,7 +127,6 @@ export const getProjects = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const NodesCollectionsBasedOnproject = async (
|
export const NodesCollectionsBasedOnproject = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
@@ -165,4 +170,100 @@ export const NodesCollectionsBasedOnproject = async (
|
|||||||
message: "Unknown error",
|
message: "Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const accessAproject = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ViewProjectService({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "No project found":
|
||||||
|
res.status(200).json({});
|
||||||
|
break;
|
||||||
|
case "Datas not found":
|
||||||
|
res.status(200).json({ message: "Datas not found" });
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectDatas: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteProject({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(200).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({ message: "Project not found" });
|
||||||
|
break;
|
||||||
|
case "No access granted to delete this project":
|
||||||
|
res
|
||||||
|
.status(200)
|
||||||
|
.json({ message: "No access granted to delete this project" });
|
||||||
|
break;
|
||||||
|
case "Project Delete unsuccessfull":
|
||||||
|
res.status(200).json({ message: "Project Delete unsuccessfull" });
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -10,49 +10,72 @@ import {
|
|||||||
SetCollectionNameController,
|
SetCollectionNameController,
|
||||||
updateAttributesCollections,
|
updateAttributesCollections,
|
||||||
} from "../controller/collectionNodeController";
|
} from "../controller/collectionNodeController";
|
||||||
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
|
|
||||||
const collectionNodeRoutes = express.Router();
|
const collectionNodeRoutes = express.Router();
|
||||||
//Node creation
|
//Node creation
|
||||||
collectionNodeRoutes.post("/nodes", NodeCreationController);
|
collectionNodeRoutes.post(
|
||||||
|
"/nodes",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
NodeCreationController
|
||||||
|
);
|
||||||
//collection Added
|
//collection Added
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/collectionName",
|
"/nodes/collectionName",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
SetCollectionNameController
|
SetCollectionNameController
|
||||||
);
|
);
|
||||||
//duplicate collection
|
//duplicate collection
|
||||||
collectionNodeRoutes.post(
|
collectionNodeRoutes.post(
|
||||||
"/nodes/:collectionNodeId/duplicate",
|
"/nodes/:collectionNodeId/duplicate",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
DuplicateNodeCollectionController
|
DuplicateNodeCollectionController
|
||||||
);
|
);
|
||||||
//particular collection data
|
//particular collection data
|
||||||
collectionNodeRoutes.get(
|
collectionNodeRoutes.get(
|
||||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
"/nodes/:projectId/:collectionNodeId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
CollectionDatas
|
CollectionDatas
|
||||||
);
|
);
|
||||||
//delete collection
|
//delete collection
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
"/nodes/:projectId/:collectionNodeId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
DeleteCollectionsController
|
DeleteCollectionsController
|
||||||
);
|
);
|
||||||
|
|
||||||
//Add fields
|
//Add fields
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes",
|
"/nodes/:collectionNodeId/attributes",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
AddAttributesController
|
AddAttributesController
|
||||||
);
|
);
|
||||||
//Collections and fiels based on the project
|
//Collections and fiels based on the project
|
||||||
collectionNodeRoutes.get(
|
collectionNodeRoutes.get(
|
||||||
"/nodes/:organization/:projectId",
|
"/nodes//:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
NodesCollectionsBasedOnproject
|
NodesCollectionsBasedOnproject
|
||||||
);
|
);
|
||||||
//update fields
|
//update fields
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes/:attributeId",
|
"/nodes/:collectionNodeId/attributes/:attributeId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
updateAttributesCollections
|
updateAttributesCollections
|
||||||
);
|
);
|
||||||
//delete fields
|
//delete fields
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes/softDelete",
|
"/nodes/:collectionNodeId/attributes/softDelete",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
delAttributesCollections
|
delAttributesCollections
|
||||||
);
|
);
|
||||||
export default collectionNodeRoutes;
|
export default collectionNodeRoutes;
|
||||||
|
|||||||
8
src/api-server/routes/homeRoutes.ts
Normal file
8
src/api-server/routes/homeRoutes.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { homePageRecentlyViewedController } from "../controller/homePageController";
|
||||||
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
|
const homeRoutes = express.Router();
|
||||||
|
|
||||||
|
homeRoutes.get("/home",tokenValidator,authorizedRoles("Admin","Editor","Viewer"), homePageRecentlyViewedController);
|
||||||
|
export default homeRoutes;
|
||||||
@@ -1,12 +1,47 @@
|
|||||||
import express from "express";
|
import express, { Response, NextFunction } from "express";
|
||||||
import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController";
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
import {
|
||||||
|
accessAproject,
|
||||||
|
getProjects,
|
||||||
|
NodesCollectionsBasedOnproject,
|
||||||
|
projectCreationController,
|
||||||
|
} from "../controller/projectController";
|
||||||
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
|
||||||
const projectRoutes = express.Router();
|
const projectRoutes = express.Router();
|
||||||
|
|
||||||
projectRoutes.post("/Newproject", projectCreationController);
|
projectRoutes.post(
|
||||||
|
"/Newproject",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor"),
|
||||||
|
projectCreationController
|
||||||
|
);
|
||||||
projectRoutes.get(
|
projectRoutes.get(
|
||||||
"/nodes/:organization/:projectId",
|
"/nodes/:organization/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Viewer", "Admin", "Editor"),
|
||||||
NodesCollectionsBasedOnproject
|
NodesCollectionsBasedOnproject
|
||||||
);
|
);
|
||||||
// appRoutes.post("/createfileModel", fileModelCreatecontroller);
|
|
||||||
|
projectRoutes.get(
|
||||||
|
"/Allprojects/:organization",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
getProjects
|
||||||
|
);
|
||||||
|
|
||||||
|
projectRoutes.get(
|
||||||
|
"/Aproject/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
accessAproject
|
||||||
|
);
|
||||||
|
|
||||||
|
projectRoutes.put(
|
||||||
|
"/node/deleteproject/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor"),
|
||||||
|
accessAproject
|
||||||
|
);
|
||||||
export default projectRoutes;
|
export default projectRoutes;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Redis from "ioredis";
|
import Redis from "ioredis";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
dotenv.config({quiet:true});
|
dotenv.config({});
|
||||||
const redis = new Redis({
|
const redis = new Redis({
|
||||||
host:
|
host:
|
||||||
process.env.REDIS_ENV === "true"
|
process.env.REDIS_ENV === "true"
|
||||||
|
|||||||
13
src/shared/middleware/rbacMiddleware.ts
Normal file
13
src/shared/middleware/rbacMiddleware.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Response, NextFunction } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
type Role = "Admin" | "Viewer" | "Editor";
|
||||||
|
const authorizedRoles = (...allowedRoles: Role[]) => {
|
||||||
|
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.user || !allowedRoles.includes(req.user.role as Role)) {
|
||||||
|
res.status(403).json({ message: "Access Denied" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export default authorizedRoles;
|
||||||
@@ -12,6 +12,11 @@ const folderSchema: Schema = new Schema({
|
|||||||
export interface IMVCPrject extends Document {
|
export interface IMVCPrject extends Document {
|
||||||
projectId: IProject["_id"];
|
projectId: IProject["_id"];
|
||||||
controllers: boolean;
|
controllers: boolean;
|
||||||
|
// env:boolean;
|
||||||
|
// src:boolean;
|
||||||
|
// package_json:boolean;
|
||||||
|
// node_modules:boolean;
|
||||||
|
// gitignore:boolean;
|
||||||
routes: boolean;
|
routes: boolean;
|
||||||
models: boolean;
|
models: boolean;
|
||||||
services: boolean;
|
services: boolean;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ const UserSchema: Schema = new Schema({
|
|||||||
},
|
},
|
||||||
role: {
|
role: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "User",
|
default: "Viewer",
|
||||||
enum: ["User", "Admin"],
|
enum: ["Editor", "Admin", "Viewer"],
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import redis from "../connection/redis";
|
import redis from "../connection/redis";
|
||||||
import tokenModel from "../model/tokenModel";
|
import tokenModel from "../model/tokenModel";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
|
|
||||||
import userModel from "../model/userModel";
|
import userModel from "../model/userModel";
|
||||||
import { hashGenerate, hashValidator } from "../utils/hashing";
|
import { hashGenerate, hashValidator } from "../utils/hashing";
|
||||||
import { tokenGenerator, tokenRefreshGenerator } from "../utils/token";
|
import { tokenGenerator, tokenRefreshGenerator } from "../utils/token";
|
||||||
import { text } from "body-parser";
|
import userDataModel from "../model/userDataModel";
|
||||||
|
|
||||||
interface Iresponse {
|
interface Iresponse {
|
||||||
status: string;
|
status: string;
|
||||||
@@ -45,7 +44,7 @@ export const signupService = async (data: Isignup): Promise<Iresponse> => {
|
|||||||
let role;
|
let role;
|
||||||
const passwordHashed = await hashGenerate(password);
|
const passwordHashed = await hashGenerate(password);
|
||||||
const userCount = await userModel(organization).countDocuments({});
|
const userCount = await userModel(organization).countDocuments({});
|
||||||
role = userCount === 0 ? "Admin" : "User";
|
role = userCount === 0 ? "Admin" : "Viewer";
|
||||||
const newUser = await userModel(organization).create({
|
const newUser = await userModel(organization).create({
|
||||||
userName,
|
userName,
|
||||||
email: mailCaseChange,
|
email: mailCaseChange,
|
||||||
@@ -81,6 +80,15 @@ export const signinService = async (data: Isignin): Promise<Iresponse> => {
|
|||||||
);
|
);
|
||||||
if (!comparePassword)
|
if (!comparePassword)
|
||||||
return { status: "Password is invalid...Check the credentials" };
|
return { status: "Password is invalid...Check the credentials" };
|
||||||
|
const userDataExistence = await userDataModel(organization).findOne({
|
||||||
|
userId: mailExistance._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!userDataExistence) {
|
||||||
|
const userDatacreation = await userDataModel(organization).create({
|
||||||
|
userId: mailExistance._id,
|
||||||
|
});
|
||||||
|
}
|
||||||
const tokenValidation = tokenGenerator(
|
const tokenValidation = tokenGenerator(
|
||||||
mailExistance.email,
|
mailExistance.email,
|
||||||
mailExistance.role,
|
mailExistance.role,
|
||||||
@@ -145,13 +153,10 @@ export const forgetPassword = async ({
|
|||||||
email,
|
email,
|
||||||
}: IforGotPassword): Promise<{ status: string }> => {
|
}: IforGotPassword): Promise<{ status: string }> => {
|
||||||
try {
|
try {
|
||||||
console.log("hi forgetpassword");
|
|
||||||
const mailCaseChange = email.toLocaleLowerCase();
|
const mailCaseChange = email.toLocaleLowerCase();
|
||||||
const organization = email.split("@")[1].split(".")[0];
|
const organization = email.split("@")[1].split(".")[0];
|
||||||
const Existing_User = await existingUserData(mailCaseChange, organization);
|
const Existing_User = await existingUserData(mailCaseChange, organization);
|
||||||
console.log("Existing_User: ", Existing_User);
|
|
||||||
if (Existing_User) {
|
if (Existing_User) {
|
||||||
console.log("if");
|
|
||||||
// if (Existing_User.lastPasswordReset) {
|
// if (Existing_User.lastPasswordReset) {
|
||||||
// console.log("if2");
|
// console.log("if2");
|
||||||
// const lastPasswordReset = Existing_User.lastPasswordReset;
|
// const lastPasswordReset = Existing_User.lastPasswordReset;
|
||||||
@@ -163,8 +168,6 @@ export const forgetPassword = async ({
|
|||||||
// status: "You can only reset your password once every 24 hours.",
|
// status: "You can only reset your password once every 24 hours.",
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
console.log("process.env.EMAIL_USER: ", process.env.EMAIL_USER);
|
|
||||||
console.log("process.env.EMAIL_PASS: ", process.env.EMAIL_PASS);
|
|
||||||
const transport = nodemailer.createTransport({
|
const transport = nodemailer.createTransport({
|
||||||
service: "gmail",
|
service: "gmail",
|
||||||
secure: true,
|
secure: true,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface Iresponse {
|
|||||||
}
|
}
|
||||||
interface IcollectionNode {
|
interface IcollectionNode {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
position: [number];
|
position: [number];
|
||||||
}
|
}
|
||||||
@@ -16,6 +17,7 @@ interface IAttribute {
|
|||||||
}
|
}
|
||||||
interface IcollectionNodeName {
|
interface IcollectionNodeName {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
@@ -23,21 +25,25 @@ interface IcollectionNodeName {
|
|||||||
}
|
}
|
||||||
interface IcollectionAttributes {
|
interface IcollectionAttributes {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
attributes: IAttribute[];
|
attributes: IAttribute[];
|
||||||
}
|
}
|
||||||
interface IcollectionNodes {
|
interface IcollectionNodes {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
interface IcollectionNodeById {
|
interface IcollectionNodeById {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
|
userId: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
}
|
}
|
||||||
interface IAttributesEdit {
|
interface IAttributesEdit {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
attributeId: string;
|
attributeId: string;
|
||||||
@@ -50,6 +56,7 @@ interface IAttributesEdit {
|
|||||||
}
|
}
|
||||||
interface IAttributesDel {
|
interface IAttributesDel {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
AttributeId: string;
|
AttributeId: string;
|
||||||
@@ -57,10 +64,12 @@ interface IAttributesDel {
|
|||||||
interface ICollectionDelete {
|
interface ICollectionDelete {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
|
userId: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
}
|
}
|
||||||
interface IDuplicateCollectionNode {
|
interface IDuplicateCollectionNode {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
@@ -71,7 +80,7 @@ interface IDuplicateCollectionNode {
|
|||||||
export const Nodecreation = async (
|
export const Nodecreation = async (
|
||||||
data: IcollectionNode
|
data: IcollectionNode
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, position } = data;
|
const { organization, projectId, position, userId } = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -111,6 +120,7 @@ export const SetCollectionName = async (
|
|||||||
position,
|
position,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
collectionName,
|
collectionName,
|
||||||
|
userId,
|
||||||
} = data;
|
} = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
@@ -157,7 +167,8 @@ export const SetCollectionName = async (
|
|||||||
export const addAttributes = async (
|
export const addAttributes = async (
|
||||||
data: IcollectionAttributes
|
data: IcollectionAttributes
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, collectionNodeId, attributes } = data;
|
const { organization, projectId, userId, collectionNodeId, attributes } =
|
||||||
|
data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -218,7 +229,7 @@ export const addAttributes = async (
|
|||||||
export const GetNodesInProject = async (
|
export const GetNodesInProject = async (
|
||||||
data: IcollectionNodes
|
data: IcollectionNodes
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId } = data;
|
const { organization, userId, projectId } = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -264,6 +275,7 @@ export const UpdateAttributes = async (
|
|||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const {
|
const {
|
||||||
organization,
|
organization,
|
||||||
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
attributeId,
|
attributeId,
|
||||||
@@ -329,7 +341,8 @@ export const UpdateAttributes = async (
|
|||||||
export const DelAttributes = async (
|
export const DelAttributes = async (
|
||||||
data: IAttributesDel
|
data: IAttributesDel
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, collectionNodeId, AttributeId } = data;
|
const { organization, userId, projectId, collectionNodeId, AttributeId } =
|
||||||
|
data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -383,7 +396,7 @@ export const DelAttributes = async (
|
|||||||
export const delCollection = async (
|
export const delCollection = async (
|
||||||
data: ICollectionDelete
|
data: ICollectionDelete
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, collectionNodeId } = data;
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -429,7 +442,7 @@ export const delCollection = async (
|
|||||||
export const GetcollectionNode = async (
|
export const GetcollectionNode = async (
|
||||||
data: IcollectionNodeById
|
data: IcollectionNodeById
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, collectionNodeId } = data;
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
@@ -499,7 +512,7 @@ const generateUniqueCollectionName = async (
|
|||||||
export const DuplicateCollection = async (
|
export const DuplicateCollection = async (
|
||||||
data: IDuplicateCollectionNode
|
data: IDuplicateCollectionNode
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, position, collectionNodeId } = data;
|
const { organization, userId, projectId, position, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
|
|||||||
51
src/shared/services/homePageService.ts
Normal file
51
src/shared/services/homePageService.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import ProjectType from "../../shared/model/projectmodel";
|
||||||
|
import userDataModel from "../model/userDataModel";
|
||||||
|
import userModel from "../model/userModel";
|
||||||
|
|
||||||
|
interface IrecentlyViewed {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface Iresponse {
|
||||||
|
status: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
||||||
|
export const recentlyViewedServices = async (
|
||||||
|
data: IrecentlyViewed
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, userId } = data;
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const userDatas = await userDataModel(organization)
|
||||||
|
.findOne({ userId: userId, isArchive: false })
|
||||||
|
.select("recentlyViewed userId");
|
||||||
|
const populatedProjects = userDatas.recentlyViewed;
|
||||||
|
const RecentDatas = await Promise.all(
|
||||||
|
populatedProjects.map(async (projectId: any) => {
|
||||||
|
const projectExisting = await ProjectType(organization)
|
||||||
|
.findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("_id projectName createdBy thumbnail createdAt isViewed");
|
||||||
|
return projectExisting;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const filteredProjects = RecentDatas.filter(Boolean);
|
||||||
|
return { status: "Success", data: filteredProjects };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -29,6 +29,11 @@ interface IProjectstructure {
|
|||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IgetProject {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const projectCreationService = async (
|
export const projectCreationService = async (
|
||||||
data: IProject
|
data: IProject
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
@@ -43,6 +48,10 @@ export const projectCreationService = async (
|
|||||||
architecture,
|
architecture,
|
||||||
} = data;
|
} = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
projectName: projectName,
|
projectName: projectName,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
@@ -121,13 +130,30 @@ export const projectCreationService = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const projectDatas = async (data: IProject): Promise<Iresponse> => {
|
export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
|
||||||
const { organization } = data;
|
const { organization, userId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
let query: any = { isArchive: false };
|
||||||
|
if (ExistingUser.role === "Editor") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
$or: [{ createdBy: userId }, { members: userId }],
|
||||||
|
};
|
||||||
|
} else if (ExistingUser.role === "Viewer") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
members: userId,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
query;
|
||||||
|
}
|
||||||
|
console.log("query: ", query);
|
||||||
const projectDatas = await ProjectType(organization)
|
const projectDatas = await ProjectType(organization)
|
||||||
.findOne({
|
.find(query)
|
||||||
isArchive: false,
|
|
||||||
})
|
|
||||||
.select("-__v -isArchive -createdAt -updatedAt");
|
.select("-__v -isArchive -createdAt -updatedAt");
|
||||||
if (!projectDatas) return { status: "No project found" };
|
if (!projectDatas) return { status: "No project found" };
|
||||||
return { status: "Success", data: projectDatas };
|
return { status: "Success", data: projectDatas };
|
||||||
@@ -197,14 +223,41 @@ export const ViewProjectService = async (
|
|||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, userId } = data;
|
const { organization, projectId, userId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
let query: any = { _id: projectId, isArchive: false };
|
||||||
const RecentUserDoc = await userDataModel(organization).findOne({
|
const RecentUserDoc = await userDataModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
|
||||||
_id: projectId,
|
if (ExistingUser.role === "Editor") {
|
||||||
isArchive: false,
|
query = {
|
||||||
});
|
...query,
|
||||||
|
$or: [{ createdBy: userId }, { members: userId }],
|
||||||
|
};
|
||||||
|
} else if (ExistingUser.role === "Viewer") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
members: userId,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
query;
|
||||||
|
}
|
||||||
|
const projectData = await ProjectType(organization)
|
||||||
|
.findOne(query)
|
||||||
|
.populate({
|
||||||
|
path: "createdBy",
|
||||||
|
model: userModel(organization),
|
||||||
|
select: "userName",
|
||||||
|
})
|
||||||
|
.select("_id projectName createdBy");
|
||||||
|
console.log("projectData: ", projectData);
|
||||||
|
if (projectData === null) {
|
||||||
|
return { status: "Datas not found" };
|
||||||
|
}
|
||||||
const newArr = RecentUserDoc?.recentlyViewed || [];
|
const newArr = RecentUserDoc?.recentlyViewed || [];
|
||||||
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
||||||
newArr.push(projectId);
|
newArr.push(projectId);
|
||||||
@@ -225,18 +278,8 @@ export const ViewProjectService = async (
|
|||||||
{ recentlyViewed: newArr },
|
{ recentlyViewed: newArr },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
const projectData = await ProjectType(organization)
|
|
||||||
.findOne({
|
return { status: "Success", data: projectData || [] };
|
||||||
_id: projectId,
|
|
||||||
isArchive: false,
|
|
||||||
})
|
|
||||||
.populate({
|
|
||||||
path: "createdBy",
|
|
||||||
model: userModel(organization),
|
|
||||||
select: "userName",
|
|
||||||
})
|
|
||||||
.select("_id projectName createdBy");
|
|
||||||
return { status: "Success", data: projectData };
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
return {
|
return {
|
||||||
@@ -250,7 +293,7 @@ export const ViewProjectService = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DeleteProject = async (data: IProjectView) => {
|
export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, organization, userId } = data;
|
const { projectId, organization, userId } = data;
|
||||||
const ExistingUser = await userModel(organization).findOne({
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
@@ -259,82 +302,40 @@ export const DeleteProject = async (data: IProjectView) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!ExistingUser) return { status: "User not found" };
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
let filter = {
|
let query: any = {
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
createdBy: userId,
|
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
};
|
};
|
||||||
const existingProject = await ProjectType(organization).findOne(filter);
|
const existingProject = await ProjectType(organization).findOne(query);
|
||||||
if (!existingProject) return { status: "Project not found" };
|
if (!existingProject) return { status: "Project not found" };
|
||||||
const updateProject = await ProjectType(organization).findOneAndUpdate(
|
|
||||||
filter,
|
if (ExistingUser.role === "Editor") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
$or: [{ createdBy: userId }, { members: userId }],
|
||||||
|
};
|
||||||
|
} else if (ExistingUser.role === "Admin") {
|
||||||
|
query;
|
||||||
|
} else {
|
||||||
|
return { status: "No access granted to delete this project" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteProject = await ProjectType(organization).findOneAndUpdate(
|
||||||
|
query,
|
||||||
{ isArchive: true },
|
{ isArchive: true },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
await shareModel(organization).updateMany(
|
if(!deleteProject) return {status:"Project Delete unsuccessfull"}
|
||||||
{ projectId: projectId, isArchive: false },
|
return { status: "Success" };
|
||||||
{ isArchive: true }
|
|
||||||
);
|
|
||||||
if (updateProject) return { status: "Success" };
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const ViewProjectService = async (
|
|
||||||
// data: IProjectView
|
|
||||||
// ): Promise<Iresponse> => {
|
|
||||||
// const { organization, projectId, userId } = data;
|
|
||||||
// try {
|
|
||||||
// const RecentUserDoc = await userDataModel(organization).findOne({
|
|
||||||
// userId: userId,
|
|
||||||
// isArchive: false,
|
|
||||||
// });
|
|
||||||
// const existingProject = await ProjectType(organization).findOne({
|
|
||||||
// _id: projectId,
|
|
||||||
// isArchive: false,
|
|
||||||
// });
|
|
||||||
// const newArr = RecentUserDoc?.recentlyViewed || [];
|
|
||||||
// if (RecentUserDoc?.recentlyViewed.length === 0) {
|
|
||||||
// newArr.push(projectId);
|
|
||||||
// await RecentUserDoc.save();
|
|
||||||
// } else {
|
|
||||||
// const index = newArr.indexOf(projectId);
|
|
||||||
// if (index !== -1) {
|
|
||||||
// newArr.splice(index, 1);
|
|
||||||
// }
|
|
||||||
// newArr.unshift(projectId);
|
|
||||||
|
|
||||||
// if (newArr.length > maxLength) {
|
|
||||||
// newArr.pop();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// await userDataModel(organization).findOneAndUpdate(
|
|
||||||
// { userId: userId, isArchive: false },
|
|
||||||
// { recentlyViewed: newArr },
|
|
||||||
// { new: true }
|
|
||||||
// );
|
|
||||||
// const projectData = await ProjectType(organization)
|
|
||||||
// .findOne({
|
|
||||||
// _id: projectId,
|
|
||||||
// isArchive: false,
|
|
||||||
// })
|
|
||||||
// .populate({
|
|
||||||
// path: "createdBy",
|
|
||||||
// model: userModel(organization),
|
|
||||||
// select: "userName",
|
|
||||||
// })
|
|
||||||
// .select("_id projectName createdBy");
|
|
||||||
// return { status: "Success", data: projectData };
|
|
||||||
// } catch (error: unknown) {
|
|
||||||
// if (error instanceof Error) {
|
|
||||||
// return {
|
|
||||||
// status: error.message,
|
|
||||||
// };
|
|
||||||
// } else {
|
|
||||||
// return {
|
|
||||||
// status: "An unexpected error occurred",
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user