api collaboration
This commit is contained in:
2
.env
2
.env
@@ -1,4 +1,4 @@
|
|||||||
MONGO_URI=mongodb://192.168.0.110/
|
MONGO_URI=mongodb://192.168.0.212/
|
||||||
MONGO_USER=mydata
|
MONGO_USER=mydata
|
||||||
MONGO_PASSWORD=mongodb@hexr2002
|
MONGO_PASSWORD=mongodb@hexr2002
|
||||||
MONGO_AUTH_DB=admin
|
MONGO_AUTH_DB=admin
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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";
|
import homeRoutes from "./routes/homeRoutes";
|
||||||
|
import dummyRoutes from "./routes/dummyRoutes";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -20,5 +21,6 @@ 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);
|
app.use("/api/v1", homeRoutes);
|
||||||
|
app.use("/api/v1", dummyRoutes);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ export const signupController = async (
|
|||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userName, email, password, confirmPassword } = req.body;
|
const { userName, email, password } = req.body;
|
||||||
if (!userName || !email || !password || !confirmPassword) {
|
if (!userName || !email || !password) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -21,9 +21,9 @@ export const signupController = async (
|
|||||||
userName,
|
userName,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
confirmPassword,
|
|
||||||
};
|
};
|
||||||
const result = await signupService(data);
|
const result = await signupService(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User Already exists":
|
case "User Already exists":
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ import {
|
|||||||
addAttributes,
|
addAttributes,
|
||||||
DelAttributes,
|
DelAttributes,
|
||||||
delCollection,
|
delCollection,
|
||||||
|
DuplicateAttributes,
|
||||||
DuplicateCollection,
|
DuplicateCollection,
|
||||||
|
GetcollectionLists,
|
||||||
GetcollectionNode,
|
GetcollectionNode,
|
||||||
GetNodesInProject,
|
GetNodesInProject,
|
||||||
Nodecreation,
|
Nodecreation,
|
||||||
SetCollectionName,
|
updatecollection,
|
||||||
UpdateAttributes,
|
UpdateAttributes,
|
||||||
|
GetcollectionGraphicData,
|
||||||
} from "../../shared/services/collectionService";
|
} from "../../shared/services/collectionService";
|
||||||
import { AuthenticatedRequest } from "../../shared/utils/token";
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
export const NodeCreationController = async (
|
export const NodeCreationController = async (
|
||||||
@@ -17,8 +20,14 @@ export const NodeCreationController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, position } = req.body;
|
const { projectId, position, collectionName, type } = req.body;
|
||||||
if (!organization || !projectId || !position || !userId) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!position ||
|
||||||
|
!userId ||
|
||||||
|
!collectionName
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -28,13 +37,19 @@ export const NodeCreationController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
position,
|
position,
|
||||||
|
type,
|
||||||
|
collectionName,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await Nodecreation(data);
|
const result = await Nodecreation(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -43,12 +58,20 @@ export const NodeCreationController = async (
|
|||||||
message: "Collection node creation unsuccessfull",
|
message: "Collection node creation unsuccessfull",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "CollectionName already exists":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "CollectionName already exists",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Node created successfully",
|
message: "Node created successfully",
|
||||||
collectionNodeId: result.data,
|
collectionNodeId: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Validation Error":
|
||||||
|
res.status(400).json({ message: result.data || "Validation Error" });
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
@@ -62,13 +85,27 @@ export const NodeCreationController = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SetCollectionNameController = async (
|
export const updateCollectionController = async (
|
||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, collectionNodeId, collectionName, position } = req.body;
|
const {
|
||||||
|
projectId,
|
||||||
|
collectionNodeId,
|
||||||
|
collectionName,
|
||||||
|
position,
|
||||||
|
backgroundColor,
|
||||||
|
borderColor,
|
||||||
|
fontColor,
|
||||||
|
lineColor,
|
||||||
|
lineThickness,
|
||||||
|
fontName,
|
||||||
|
lineType,
|
||||||
|
borderThickness,
|
||||||
|
cornerRadius,
|
||||||
|
} = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
@@ -85,15 +122,27 @@ export const SetCollectionNameController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
backgroundColor,
|
||||||
|
borderColor,
|
||||||
|
fontColor,
|
||||||
|
lineColor,
|
||||||
|
lineThickness,
|
||||||
|
fontName,
|
||||||
|
lineType,
|
||||||
|
borderThickness,
|
||||||
|
cornerRadius,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
collectionName,
|
collectionName,
|
||||||
position,
|
position,
|
||||||
};
|
};
|
||||||
const result = await SetCollectionName(data);
|
const result = await updatecollection(data);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -141,8 +190,62 @@ export const CollectionDatas = async (
|
|||||||
};
|
};
|
||||||
const result = await GetcollectionNode(data);
|
const result = await GetcollectionNode(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No collection Nodes present":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
message: "No collection Nodes present",
|
||||||
|
Collections: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const graphicDatas = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, collectionNodeId } = req.params;
|
||||||
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
collectionNodeId,
|
||||||
|
};
|
||||||
|
const result = await GetcollectionGraphicData(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
|
case "project not found":
|
||||||
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -189,8 +292,11 @@ export const DeleteCollectionsController = async (
|
|||||||
};
|
};
|
||||||
const result = await delCollection(data);
|
const result = await delCollection(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -240,8 +346,11 @@ export const DuplicateNodeCollectionController = async (
|
|||||||
};
|
};
|
||||||
const result = await DuplicateCollection(data);
|
const result = await DuplicateCollection(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -285,9 +394,14 @@ export const NodesCollectionsBasedOnproject = async (
|
|||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await GetNodesInProject(data);
|
const result = await GetNodesInProject(data);
|
||||||
|
console.log("resultdssa: ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -319,8 +433,8 @@ export const AddAttributesController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId } = req.params;
|
// const { collectionNodeId } = req.params;
|
||||||
const { projectId, attributes } = req.body;
|
const { projectId, attributes, collectionNodeId } = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
@@ -341,12 +455,21 @@ export const AddAttributesController = async (
|
|||||||
attributes,
|
attributes,
|
||||||
};
|
};
|
||||||
const result = await addAttributes(data);
|
const result = await addAttributes(data);
|
||||||
|
console.log("result: ", result);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Subcollection already added for the object data":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Subcollection already added for the object data",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Collection not found":
|
case "Collection not found":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Collection not found",
|
message: "Collection not found",
|
||||||
@@ -377,8 +500,16 @@ export const updateAttributesCollections = async (
|
|||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { collectionNodeId, attributeId } = req.params;
|
const { collectionNodeId, attributeId } = req.params;
|
||||||
const { projectId, required, defaultValue, unique, index, key, type } =
|
const {
|
||||||
req.body;
|
projectId,
|
||||||
|
required,
|
||||||
|
primary,
|
||||||
|
defaultValue,
|
||||||
|
unique,
|
||||||
|
index,
|
||||||
|
key,
|
||||||
|
type,
|
||||||
|
} = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!userId ||
|
!userId ||
|
||||||
@@ -394,6 +525,7 @@ export const updateAttributesCollections = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
primary,
|
||||||
userId,
|
userId,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
attributeId,
|
attributeId,
|
||||||
@@ -405,9 +537,14 @@ export const updateAttributesCollections = async (
|
|||||||
type,
|
type,
|
||||||
};
|
};
|
||||||
const result = await UpdateAttributes(data);
|
const result = await UpdateAttributes(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -461,8 +598,11 @@ export const delAttributesCollections = async (
|
|||||||
};
|
};
|
||||||
const result = await DelAttributes(data);
|
const result = await DelAttributes(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -487,3 +627,120 @@ export const delAttributesCollections = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const duplicateAttributesCollections = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, attrKey, collectionNodeId } = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!collectionNodeId ||
|
||||||
|
!attrKey ||
|
||||||
|
!userId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
collectionNodeId,
|
||||||
|
attrKey,
|
||||||
|
};
|
||||||
|
const result = await DuplicateAttributes(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
|
case "project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CollectionId not found for duplication":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "CollectionId not found for duplication",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Attribute doesnot match":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Attribute doesnot match",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Attributes duplicated successfully",
|
||||||
|
data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const collectionListsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !projectId || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await GetcollectionLists(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
|
case "project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Collection not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Collection not found",
|
||||||
|
Collections: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ Collections: result.data });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
558
src/api-server/controller/dummyController.ts
Normal file
558
src/api-server/controller/dummyController.ts
Normal file
@@ -0,0 +1,558 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
import {
|
||||||
|
addAttributesdummy,
|
||||||
|
collectionKeyRenamedummy,
|
||||||
|
GetcollectionNodedummy,
|
||||||
|
Nodecreationdummy,
|
||||||
|
SetCollectionNamedummy,
|
||||||
|
} from "../../shared/services/dummyService";
|
||||||
|
export const NodeCreationControllerdummy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, position, organization, userId, collectionName } =
|
||||||
|
req.body;
|
||||||
|
console.log("req.body: ", req.body);
|
||||||
|
if (!organization || !projectId || !position || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
position,
|
||||||
|
userId,
|
||||||
|
collectionName,
|
||||||
|
};
|
||||||
|
const result = await Nodecreationdummy(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Collection node creation unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Collection node creation unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Node created successfully",
|
||||||
|
collectionNodeId: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SetCollectionNameControllerdummy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
projectId,
|
||||||
|
collectionNodeId,
|
||||||
|
collectionName,
|
||||||
|
position,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!userId ||
|
||||||
|
!collectionName ||
|
||||||
|
!collectionNodeId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
collectionNodeId,
|
||||||
|
collectionName,
|
||||||
|
position,
|
||||||
|
};
|
||||||
|
const result = await SetCollectionNamedummy(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Collection not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Collection not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "collection name updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CollectionDatasdummy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.query as {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
};
|
||||||
|
const { projectId, collectionNodeId } = req.params;
|
||||||
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
collectionNodeId,
|
||||||
|
};
|
||||||
|
const result = await GetcollectionNodedummy(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No collection Nodes present":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "No collection Nodes present",
|
||||||
|
Collections: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CollectionkeyRenamesdummy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
projectId,
|
||||||
|
collectionNodeId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
newKeyName,
|
||||||
|
oldKeyName,
|
||||||
|
} = req.body;
|
||||||
|
if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
collectionNodeId,
|
||||||
|
newKeyName,
|
||||||
|
oldKeyName,
|
||||||
|
};
|
||||||
|
const result = await collectionKeyRenamedummy(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No collection Nodes present":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "No collection Nodes present",
|
||||||
|
Collections: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// export const DeleteCollectionsController = async (
|
||||||
|
// req: AuthenticatedRequest,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
// const { projectId, collectionNodeId } = req.params;
|
||||||
|
// if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const data = {
|
||||||
|
// organization,
|
||||||
|
// projectId,
|
||||||
|
// userId,
|
||||||
|
// collectionNodeId,
|
||||||
|
// };
|
||||||
|
// const result = await delCollection(data);
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "project not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "project not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Collection not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "Collection not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({ message: "Collection deleted successfully" });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Unknown error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const DuplicateNodeCollectionController = async (
|
||||||
|
// req: AuthenticatedRequest,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
// const { collectionNodeId } = req.params;
|
||||||
|
// const { projectId, collectionName, position, attributes } = req.body;
|
||||||
|
// if (!organization || !projectId || !collectionNodeId || !userId) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const data = {
|
||||||
|
// organization,
|
||||||
|
// projectId,
|
||||||
|
// userId,
|
||||||
|
// collectionName,
|
||||||
|
// position,
|
||||||
|
// attributes,
|
||||||
|
// collectionNodeId,
|
||||||
|
// };
|
||||||
|
// const result = await DuplicateCollection(data);
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "project not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "project not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Duplication unsuccessfull":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "Duplication unsuccessfull",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({ message: "Duplicated successfully" });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Unknown error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const NodesCollectionsBasedOnproject = async (
|
||||||
|
// req: AuthenticatedRequest,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
// const { projectId } = req.params;
|
||||||
|
// if (!organization || !projectId || !userId) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const data = {
|
||||||
|
// organization,
|
||||||
|
// projectId,
|
||||||
|
// userId,
|
||||||
|
// };
|
||||||
|
// const result = await GetNodesInProject(data);
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "project not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "project not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "No collection Nodes present":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "No collection Nodes present",
|
||||||
|
// Collections: result.data,
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({ Collections: result.data });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Unknown error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
export const AddAttributesControllerdummy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
const { collectionNodeId } = req.params;
|
||||||
|
const { projectId, attributes, organization, userId } = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!attributes ||
|
||||||
|
!userId ||
|
||||||
|
!collectionNodeId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
collectionNodeId,
|
||||||
|
attributes,
|
||||||
|
};
|
||||||
|
const result = await addAttributesdummy(data);
|
||||||
|
console.log("result: ", result);
|
||||||
|
switch (result.status) {
|
||||||
|
case "project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Collection not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Collection not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "collection Attributes Added",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// export const updateAttributesCollections = async (
|
||||||
|
// req: AuthenticatedRequest,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
// const { collectionNodeId, attributeId } = req.params;
|
||||||
|
// const { projectId, required, defaultValue, unique, index, key, type } =
|
||||||
|
// req.body;
|
||||||
|
// if (
|
||||||
|
// !organization ||
|
||||||
|
// !userId ||
|
||||||
|
// !projectId ||
|
||||||
|
// !collectionNodeId ||
|
||||||
|
// !attributeId
|
||||||
|
// ) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const data = {
|
||||||
|
// organization,
|
||||||
|
// projectId,
|
||||||
|
// userId,
|
||||||
|
// collectionNodeId,
|
||||||
|
// attributeId,
|
||||||
|
// required,
|
||||||
|
// defaultValue,
|
||||||
|
// unique,
|
||||||
|
// index,
|
||||||
|
// key,
|
||||||
|
// type,
|
||||||
|
// };
|
||||||
|
// const result = await UpdateAttributes(data);
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "project not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "project not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Collection not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "Collection not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({ message: "Field updated successfully" });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Unknown error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const delAttributesCollections = async (
|
||||||
|
// req: AuthenticatedRequest,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { organization, userId } = req.user || {};
|
||||||
|
// const { collectionNodeId } = req.params;
|
||||||
|
// const { projectId, AttributeId } = req.body;
|
||||||
|
// if (
|
||||||
|
// !organization ||
|
||||||
|
// !projectId ||
|
||||||
|
// !collectionNodeId ||
|
||||||
|
// !AttributeId ||
|
||||||
|
// !userId
|
||||||
|
// ) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const data = {
|
||||||
|
// organization,
|
||||||
|
// userId,
|
||||||
|
// projectId,
|
||||||
|
// collectionNodeId,
|
||||||
|
// AttributeId,
|
||||||
|
// };
|
||||||
|
// const result = await DelAttributes(data);
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "project not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "project not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Collection not found":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: "Collection not found",
|
||||||
|
// Collections: result.data,
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({ message: "Field deleted successfully" });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Unknown error",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService";
|
import {
|
||||||
|
Alledges,
|
||||||
|
deleteEdge,
|
||||||
|
edgecreation,
|
||||||
|
} from "../../shared/services/edgeService";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
export const edgeCreationController = async (
|
export const edgeCreationController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, from,to,cardinality } = req.body;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId || !from || !to) {
|
const { projectId, from, to, cardinality } = req.body;
|
||||||
|
if (!organization || !projectId || !from || !to || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -15,36 +21,40 @@ export const edgeCreationController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
cardinality
|
cardinality,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
const result = await edgecreation(data);
|
const result = await edgecreation(data);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "From collection not found":
|
case "From collection not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "From collection not found",
|
message: "From collection not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "To collection not found":
|
case "To collection not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "To collection not found",
|
message: "To collection not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Field already exists":
|
case "Field already exists":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Field already exists",
|
message: "Field already exists",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message:"Edge created successfully",
|
message: "Edge created successfully",
|
||||||
collectionNodeId: result.data,
|
collectionNodeId: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -61,12 +71,13 @@ cardinality
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const allEdgesController = async (
|
export const allEdgesController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, } = req.body;
|
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",
|
||||||
});
|
});
|
||||||
@@ -75,23 +86,27 @@ export const allEdgesController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
const result = await Alledges(data);
|
const result = await Alledges(data);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "edge not found":
|
case "edge not found":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "edge not found",
|
message: "edge not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message:"fetch all Edge datas successfully",
|
message: "fetch all Edge datas successfully",
|
||||||
collectionNodeId: result.data,
|
collectionNodeId: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -108,12 +123,13 @@ export const allEdgesController = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const deleteEdgesController = async (
|
export const deleteEdgesController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, edgeId} = req.body;
|
const { organization, userId } = req.user || {};
|
||||||
if (!organization || !projectId ||!edgeId) {
|
const { projectId, edgeId } = req.params;
|
||||||
|
if (!organization || !projectId || !edgeId || !userId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -122,24 +138,28 @@ export const deleteEdgesController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
edgeId
|
edgeId,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
const result = await deleteEdge(data);
|
const result = await deleteEdge(data);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "edge not found":
|
case "edge not found":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "edge not found",
|
message: "edge not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message:"Edge deleted successfully",
|
message: "Edge deleted successfully",
|
||||||
collectionNodeId: result.data,
|
collectionNodeId: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -154,4 +174,4 @@ export const deleteEdgesController = async (
|
|||||||
message: "Unknown error",
|
message: "Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { AuthenticatedRequest } from "../../shared/utils/token";
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
import { recentlyViewedServices } from "../../shared/services/homePageService";
|
import {
|
||||||
|
homeuserProfileServices,
|
||||||
|
recentlyViewedServices,
|
||||||
|
} from "../../shared/services/homePageService";
|
||||||
|
|
||||||
export const homePageRecentlyViewedController = async (
|
export const homePageRecentlyViewedController = async (
|
||||||
req: AuthenticatedRequest,
|
req: AuthenticatedRequest,
|
||||||
@@ -22,7 +25,49 @@ export const homePageRecentlyViewedController = async (
|
|||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
res.status(403).json({
|
res.status(404).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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const homePageUserDataController = 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 homeuserProfileServices(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
message: "User not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -4,31 +4,31 @@ import {
|
|||||||
GetNodesInProject,
|
GetNodesInProject,
|
||||||
projectCreationService,
|
projectCreationService,
|
||||||
projectDatas,
|
projectDatas,
|
||||||
|
projectModification,
|
||||||
ViewProjectService,
|
ViewProjectService,
|
||||||
} from "../../shared/services/projectService";
|
} from "../../shared/services/projectService";
|
||||||
import { AuthenticatedRequest } from "../../shared/utils/token";
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
|
|
||||||
export const projectCreationController = async (
|
export const projectCreationController = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
const {
|
const {
|
||||||
organization,
|
language,
|
||||||
useableLanguage,
|
|
||||||
projectName,
|
projectName,
|
||||||
userId,
|
apiProtocol,
|
||||||
apiType,
|
|
||||||
application,
|
application,
|
||||||
architecture,
|
architecture,
|
||||||
description,
|
description,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!useableLanguage ||
|
!language ||
|
||||||
!projectName ||
|
!projectName ||
|
||||||
!userId ||
|
!userId ||
|
||||||
!apiType ||
|
!apiProtocol ||
|
||||||
!architecture ||
|
!architecture ||
|
||||||
!application
|
!application
|
||||||
) {
|
) {
|
||||||
@@ -40,14 +40,15 @@ export const projectCreationController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
organization,
|
organization,
|
||||||
projectName,
|
projectName,
|
||||||
useableLanguage,
|
language,
|
||||||
description,
|
description,
|
||||||
application,
|
application,
|
||||||
userId,
|
userId,
|
||||||
apiType,
|
apiProtocol,
|
||||||
architecture,
|
architecture,
|
||||||
};
|
};
|
||||||
const result = await projectCreationService(data);
|
const result = await projectCreationService(data);
|
||||||
|
console.log("result:projectcreate ", result);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "Project Already Exists":
|
case "Project Already Exists":
|
||||||
@@ -95,24 +96,28 @@ export const getProjects = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
|
const { skip, limit } = req.params;
|
||||||
if (!organization || !userId) {
|
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, userId });
|
const skipdata = parseInt(skip);
|
||||||
console.log("result: ", result);
|
const limitdata = parseInt(limit);
|
||||||
|
const result = await projectDatas({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
skipdata,
|
||||||
|
limitdata,
|
||||||
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "No project found":
|
case "No project found":
|
||||||
res.status(200).json({});
|
res.status(404).json({});
|
||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({ data: result.data });
|
||||||
// message: "Projec",
|
|
||||||
projectDatas: result.data,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
@@ -128,12 +133,13 @@ export const getProjects = 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",
|
||||||
});
|
});
|
||||||
@@ -142,14 +148,20 @@ 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) {
|
||||||
case "project not found":
|
case "project not found":
|
||||||
res.status(200).json({
|
res.status(404).json({
|
||||||
message: "project not found",
|
message: "project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "No collection Nodes present":
|
case "No collection Nodes present":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "No collection Nodes present",
|
message: "No collection Nodes present",
|
||||||
@@ -237,10 +249,10 @@ export const deleteProjectController = async (
|
|||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
res.status(200).json({ message: "User not found" });
|
res.status(404).json({ message: "User not found" });
|
||||||
break;
|
break;
|
||||||
case "Project not found":
|
case "Project not found":
|
||||||
res.status(200).json({ message: "Project not found" });
|
res.status(404).json({ message: "Project not found" });
|
||||||
break;
|
break;
|
||||||
case "No access granted to delete this project":
|
case "No access granted to delete this project":
|
||||||
res
|
res
|
||||||
@@ -267,3 +279,67 @@ export const deleteProjectController = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
projectId,
|
||||||
|
projectName,
|
||||||
|
application,
|
||||||
|
description,
|
||||||
|
language,
|
||||||
|
architecture,
|
||||||
|
} = req.body;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await projectModification({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectName,
|
||||||
|
application,
|
||||||
|
description,
|
||||||
|
language,
|
||||||
|
architecture,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({ message: "Project not found" });
|
||||||
|
break;
|
||||||
|
case "No access granted to delete this project":
|
||||||
|
res
|
||||||
|
.status(200)
|
||||||
|
.json({ message: "No access granted to update this project" });
|
||||||
|
break;
|
||||||
|
case "Project update unsuccessfull":
|
||||||
|
res.status(200).json({ message: "Project update unsuccessfull" });
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import express from "express";
|
|||||||
import {
|
import {
|
||||||
AddAttributesController,
|
AddAttributesController,
|
||||||
CollectionDatas,
|
CollectionDatas,
|
||||||
|
collectionListsController,
|
||||||
delAttributesCollections,
|
delAttributesCollections,
|
||||||
DeleteCollectionsController,
|
DeleteCollectionsController,
|
||||||
|
duplicateAttributesCollections,
|
||||||
DuplicateNodeCollectionController,
|
DuplicateNodeCollectionController,
|
||||||
NodeCreationController,
|
NodeCreationController,
|
||||||
NodesCollectionsBasedOnproject,
|
NodesCollectionsBasedOnproject,
|
||||||
SetCollectionNameController,
|
updateCollectionController,
|
||||||
updateAttributesCollections,
|
updateAttributesCollections,
|
||||||
|
graphicDatas,
|
||||||
} from "../controller/collectionNodeController";
|
} from "../controller/collectionNodeController";
|
||||||
import { tokenValidator } from "../../shared/utils/token";
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
@@ -16,7 +19,7 @@ import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
|||||||
const collectionNodeRoutes = express.Router();
|
const collectionNodeRoutes = express.Router();
|
||||||
//Node creation
|
//Node creation
|
||||||
collectionNodeRoutes.post(
|
collectionNodeRoutes.post(
|
||||||
"/nodes",
|
"/node/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
NodeCreationController
|
NodeCreationController
|
||||||
@@ -26,7 +29,7 @@ collectionNodeRoutes.patch(
|
|||||||
"/nodes/collectionName",
|
"/nodes/collectionName",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
SetCollectionNameController
|
updateCollectionController
|
||||||
);
|
);
|
||||||
//duplicate collection
|
//duplicate collection
|
||||||
collectionNodeRoutes.post(
|
collectionNodeRoutes.post(
|
||||||
@@ -35,6 +38,7 @@ collectionNodeRoutes.post(
|
|||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
DuplicateNodeCollectionController
|
DuplicateNodeCollectionController
|
||||||
);
|
);
|
||||||
|
|
||||||
//particular collection data
|
//particular collection data
|
||||||
collectionNodeRoutes.get(
|
collectionNodeRoutes.get(
|
||||||
"/nodes/:projectId/:collectionNodeId",
|
"/nodes/:projectId/:collectionNodeId",
|
||||||
@@ -50,20 +54,22 @@ collectionNodeRoutes.patch(
|
|||||||
DeleteCollectionsController
|
DeleteCollectionsController
|
||||||
);
|
);
|
||||||
|
|
||||||
//Add fields
|
//Add fields to the collection node
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes",
|
"/node/attributes",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
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//:projectId",
|
"/nodes/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
NodesCollectionsBasedOnproject
|
NodesCollectionsBasedOnproject
|
||||||
);
|
);
|
||||||
|
|
||||||
//update fields
|
//update fields
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes/:attributeId",
|
"/nodes/:collectionNodeId/attributes/:attributeId",
|
||||||
@@ -71,6 +77,7 @@ collectionNodeRoutes.patch(
|
|||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
updateAttributesCollections
|
updateAttributesCollections
|
||||||
);
|
);
|
||||||
|
|
||||||
//delete fields
|
//delete fields
|
||||||
collectionNodeRoutes.patch(
|
collectionNodeRoutes.patch(
|
||||||
"/nodes/:collectionNodeId/attributes/softDelete",
|
"/nodes/:collectionNodeId/attributes/softDelete",
|
||||||
@@ -78,4 +85,28 @@ collectionNodeRoutes.patch(
|
|||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
delAttributesCollections
|
delAttributesCollections
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collectionNodeRoutes.patch(
|
||||||
|
"/duplicate/attribute",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
duplicateAttributesCollections
|
||||||
|
);
|
||||||
|
|
||||||
|
//collectionName lists on the right panel
|
||||||
|
collectionNodeRoutes.get(
|
||||||
|
"/collections/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
collectionListsController
|
||||||
|
);
|
||||||
|
|
||||||
|
//graphic Data
|
||||||
|
|
||||||
|
collectionNodeRoutes.get(
|
||||||
|
"/collections/:projectId/:collectionNodeId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
graphicDatas
|
||||||
|
);
|
||||||
export default collectionNodeRoutes;
|
export default collectionNodeRoutes;
|
||||||
|
|||||||
85
src/api-server/routes/dummyRoutes.ts
Normal file
85
src/api-server/routes/dummyRoutes.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
|
import {
|
||||||
|
AddAttributesControllerdummy,
|
||||||
|
CollectionDatasdummy,
|
||||||
|
CollectionkeyRenamesdummy,
|
||||||
|
NodeCreationControllerdummy,
|
||||||
|
SetCollectionNameControllerdummy,
|
||||||
|
} from "../controller/dummyController";
|
||||||
|
|
||||||
|
const dummyRoutes = express.Router();
|
||||||
|
//Node creation
|
||||||
|
dummyRoutes.post(
|
||||||
|
"/nodesCreate",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
NodeCreationControllerdummy
|
||||||
|
);
|
||||||
|
//collection Added
|
||||||
|
dummyRoutes.patch(
|
||||||
|
"/nodes/collectionNamedummy",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
SetCollectionNameControllerdummy
|
||||||
|
);
|
||||||
|
// //duplicate collection
|
||||||
|
// dummyRoutes.post(
|
||||||
|
// "/nodes/:collectionNodeId/duplicate",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
// DuplicateNodeCollectionController
|
||||||
|
// );
|
||||||
|
// //particular collection data
|
||||||
|
dummyRoutes.get(
|
||||||
|
"/nodesdummyget/:projectId/:collectionNodeId",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
CollectionDatasdummy
|
||||||
|
);
|
||||||
|
//renameKeyvalue
|
||||||
|
dummyRoutes.patch(
|
||||||
|
"/nodesdummyKeyrename",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
CollectionkeyRenamesdummy
|
||||||
|
);
|
||||||
|
// //delete collection
|
||||||
|
// dummyRoutes.patch(
|
||||||
|
// "/nodes/:projectId/:collectionNodeId",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
// DeleteCollectionsController
|
||||||
|
// );
|
||||||
|
|
||||||
|
// //Add fields
|
||||||
|
dummyRoutes.patch(
|
||||||
|
"/nodesdummy/:collectionNodeId/dummyattributes",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
AddAttributesControllerdummy
|
||||||
|
);
|
||||||
|
// //Collections and fiels based on the project
|
||||||
|
// dummyRoutes.get(
|
||||||
|
// "/nodes//:projectId",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
// NodesCollectionsBasedOnproject
|
||||||
|
// );
|
||||||
|
// //update fields
|
||||||
|
// dummyRoutes.patch(
|
||||||
|
// "/nodes/:collectionNodeId/attributes/:attributeId",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
// updateAttributesCollections
|
||||||
|
// );
|
||||||
|
// //delete fields
|
||||||
|
// dummyRoutes.patch(
|
||||||
|
// "/nodes/:collectionNodeId/attributes/softDelete",
|
||||||
|
// tokenValidator,
|
||||||
|
// authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
// delAttributesCollections
|
||||||
|
// );
|
||||||
|
export default dummyRoutes;
|
||||||
@@ -1,8 +1,29 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { allEdgesController, deleteEdgesController, edgeCreationController } from "../controller/edgeController";
|
import {
|
||||||
|
allEdgesController,
|
||||||
|
deleteEdgesController,
|
||||||
|
edgeCreationController,
|
||||||
|
} from "../controller/edgeController";
|
||||||
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
const edgeRoutes = express.Router();
|
const edgeRoutes = express.Router();
|
||||||
|
|
||||||
edgeRoutes.post("/edgeCreate", edgeCreationController);
|
edgeRoutes.post(
|
||||||
edgeRoutes.patch("/edgeDelete", deleteEdgesController);
|
"/edge/save",
|
||||||
edgeRoutes.get("/allEdges", allEdgesController);
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
edgeCreationController
|
||||||
|
);
|
||||||
|
edgeRoutes.patch(
|
||||||
|
"/edge/:projectId/:edgeId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
deleteEdgesController
|
||||||
|
);
|
||||||
|
edgeRoutes.get(
|
||||||
|
"/edges/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
allEdgesController
|
||||||
|
);
|
||||||
export default edgeRoutes;
|
export default edgeRoutes;
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { homePageRecentlyViewedController } from "../controller/homePageController";
|
import {
|
||||||
|
homePageRecentlyViewedController,
|
||||||
|
homePageUserDataController,
|
||||||
|
} from "../controller/homePageController";
|
||||||
import { tokenValidator } from "../../shared/utils/token";
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
const homeRoutes = express.Router();
|
const homeRoutes = express.Router();
|
||||||
|
|
||||||
homeRoutes.get("/home",tokenValidator,authorizedRoles("Admin","Editor","Viewer"), homePageRecentlyViewedController);
|
homeRoutes.get(
|
||||||
|
"/home/recentlyviewed",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
homePageRecentlyViewedController
|
||||||
|
);
|
||||||
|
homeRoutes.get("/home", tokenValidator, homePageUserDataController);
|
||||||
export default homeRoutes;
|
export default homeRoutes;
|
||||||
|
|||||||
@@ -2,46 +2,61 @@ import express, { Response, NextFunction } from "express";
|
|||||||
import { AuthenticatedRequest } from "../../shared/utils/token";
|
import { AuthenticatedRequest } from "../../shared/utils/token";
|
||||||
import {
|
import {
|
||||||
accessAproject,
|
accessAproject,
|
||||||
|
deleteProjectController,
|
||||||
getProjects,
|
getProjects,
|
||||||
NodesCollectionsBasedOnproject,
|
NodesCollectionsBasedOnproject,
|
||||||
projectCreationController,
|
projectCreationController,
|
||||||
|
updateProjectController,
|
||||||
} from "../controller/projectController";
|
} from "../controller/projectController";
|
||||||
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
import authorizedRoles from "../../shared/middleware/rbacMiddleware";
|
||||||
import { tokenValidator } from "../../shared/utils/token";
|
import { tokenValidator } from "../../shared/utils/token";
|
||||||
|
|
||||||
const projectRoutes = express.Router();
|
const projectRoutes = express.Router();
|
||||||
|
|
||||||
|
//project save
|
||||||
projectRoutes.post(
|
projectRoutes.post(
|
||||||
"/Newproject",
|
"/project/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor"),
|
authorizedRoles("Admin", "Editor"),
|
||||||
projectCreationController
|
projectCreationController
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//all nodes based on the project
|
||||||
projectRoutes.get(
|
projectRoutes.get(
|
||||||
"/nodes/:organization/:projectId",
|
"/project/:organization/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Viewer", "Admin", "Editor"),
|
authorizedRoles("Viewer", "Admin", "Editor"),
|
||||||
NodesCollectionsBasedOnproject
|
NodesCollectionsBasedOnproject
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//listing of all projects
|
||||||
projectRoutes.get(
|
projectRoutes.get(
|
||||||
"/Allprojects/:organization",
|
"/projects/:skip/:limit",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
getProjects
|
getProjects
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//view a project
|
||||||
projectRoutes.get(
|
projectRoutes.get(
|
||||||
"/Aproject/:projectId",
|
"/project/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor", "Viewer"),
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
accessAproject
|
accessAproject
|
||||||
);
|
);
|
||||||
|
|
||||||
projectRoutes.put(
|
//delete Project
|
||||||
"/node/deleteproject/:projectId",
|
projectRoutes.patch(
|
||||||
|
"/project/deleteproject/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
authorizedRoles("Admin", "Editor"),
|
authorizedRoles("Admin", "Editor"),
|
||||||
accessAproject
|
deleteProjectController
|
||||||
|
);
|
||||||
|
|
||||||
|
projectRoutes.patch(
|
||||||
|
"/project/updateproject",
|
||||||
|
tokenValidator,
|
||||||
|
authorizedRoles("Admin", "Editor", "Viewer"),
|
||||||
|
updateProjectController
|
||||||
);
|
);
|
||||||
export default projectRoutes;
|
export default projectRoutes;
|
||||||
|
|||||||
@@ -6,6 +6,54 @@ interface ConnectionCache {
|
|||||||
|
|
||||||
const connections: ConnectionCache = {};
|
const connections: ConnectionCache = {};
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
// const MainModel = async<T>(
|
||||||
|
// db: string,
|
||||||
|
// modelName: string,
|
||||||
|
// schema: Schema<T>,
|
||||||
|
// collectionName: string
|
||||||
|
// ): Model<T> => {
|
||||||
|
// const db1_url = `${process.env.MONGO_URI}${db}`;
|
||||||
|
// const authOptions = {
|
||||||
|
// user: process.env.MONGO_USER,
|
||||||
|
// pass: process.env.MONGO_PASSWORD,
|
||||||
|
// authSource: process.env.MONGO_AUTH_DB || "admin",
|
||||||
|
// maxPoolSize: 50,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// if (connections[db]) {
|
||||||
|
// return connections[db].model<T>(modelName, schema, collectionName);
|
||||||
|
// }
|
||||||
|
// // if (connections[db]) {
|
||||||
|
// // if (connections[db].readyState === 1) {
|
||||||
|
// // return connections[db].model<T>(modelName, schema, collectionName);
|
||||||
|
// // }
|
||||||
|
// // console.warn(`Reconnecting to MongoDB database: ${db}`);
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const db1 = mongoose.createConnection(db1_url, authOptions);
|
||||||
|
// // await db1.asPromise();
|
||||||
|
|
||||||
|
// connections[db] = db1;
|
||||||
|
// // connections[db] = db1;
|
||||||
|
|
||||||
|
// db1.on("connected", () => {
|
||||||
|
// console.log(`Connected to MongoDB database: ${db}`);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// db1.on("error", (err) => {
|
||||||
|
// console.error(
|
||||||
|
// `MongoDB connection error for database ${db}:`,
|
||||||
|
// err.message
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
|
// return db1.model<T>(modelName, schema, collectionName);
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Database connection error:", (error as Error).message);
|
||||||
|
// throw error;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
const MainModel = <T>(
|
const MainModel = <T>(
|
||||||
db: string,
|
db: string,
|
||||||
modelName: string,
|
modelName: string,
|
||||||
@@ -34,10 +82,7 @@ const MainModel = <T>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
db1.on("error", (err) => {
|
db1.on("error", (err) => {
|
||||||
console.error(
|
console.error(`MongoDB connection error for database ${db}`, err.message);
|
||||||
`MongoDB connection error for database ${db}:`,
|
|
||||||
err.message
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return db1.model<T>(modelName, schema, collectionName);
|
return db1.model<T>(modelName, schema, collectionName);
|
||||||
@@ -46,5 +91,4 @@ const MainModel = <T>(
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MainModel;
|
export default MainModel;
|
||||||
|
|||||||
@@ -7,14 +7,19 @@ type IattributeTypes =
|
|||||||
| "Array"
|
| "Array"
|
||||||
| "Date"
|
| "Date"
|
||||||
| "Enum"
|
| "Enum"
|
||||||
| "undefined"
|
| "Undefined"
|
||||||
| "object"
|
| "Object"
|
||||||
| "ObjectId"
|
| "ObjectId"
|
||||||
| "number"
|
| "Number"
|
||||||
| "boolean";
|
| "Boolean"
|
||||||
|
| "Null"
|
||||||
|
| "Map"
|
||||||
|
| "Buffer"
|
||||||
|
| "Mixed";
|
||||||
|
|
||||||
interface IAttributes {
|
interface IAttributes {
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
primary?: boolean;
|
||||||
key: string;
|
key: string;
|
||||||
type: IattributeTypes;
|
type: IattributeTypes;
|
||||||
refKey?: object;
|
refKey?: object;
|
||||||
@@ -23,12 +28,29 @@ interface IAttributes {
|
|||||||
unique?: boolean;
|
unique?: boolean;
|
||||||
index?: boolean;
|
index?: boolean;
|
||||||
}
|
}
|
||||||
interface ICollectionNode extends Document {
|
export interface ICollectionNode extends Document {
|
||||||
|
type: string;
|
||||||
projectId: IProject["_id"];
|
projectId: IProject["_id"];
|
||||||
collectionNodeName: string;
|
parentCollectionNodeId: ICollectionNode["_id"];
|
||||||
|
isSubCollection: boolean;
|
||||||
|
attributeparentId: ICollectionNode["_id"];
|
||||||
|
collectionName: string;
|
||||||
attributes: IAttributes[];
|
attributes: IAttributes[];
|
||||||
|
backgroundColor: BackgroundColor;
|
||||||
|
borderColor: BackgroundColor;
|
||||||
|
lineColor: BackgroundColor;
|
||||||
|
fontColor: BackgroundColor;
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
position: [number, number, number];
|
lineThickness: number;
|
||||||
|
fontName: string;
|
||||||
|
lineType: string;
|
||||||
|
borderThickness: number;
|
||||||
|
cornerRadius: number;
|
||||||
|
fontSize: number;
|
||||||
|
position: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const attributeSchema = new Schema<IAttributes>({
|
const attributeSchema = new Schema<IAttributes>({
|
||||||
key: { type: String, required: true },
|
key: { type: String, required: true },
|
||||||
@@ -37,29 +59,76 @@ const attributeSchema = new Schema<IAttributes>({
|
|||||||
required: true,
|
required: true,
|
||||||
enum: [
|
enum: [
|
||||||
"string",
|
"string",
|
||||||
"number",
|
"Number",
|
||||||
"boolean",
|
"Boolean",
|
||||||
"Date",
|
"Date",
|
||||||
"ObjectId",
|
"ObjectId",
|
||||||
"Array",
|
"Array",
|
||||||
"Enum",
|
"Enum",
|
||||||
"object",
|
"Object",
|
||||||
"any",
|
"any",
|
||||||
|
"Undefined",
|
||||||
|
"Mixed",
|
||||||
|
"Buffer",
|
||||||
|
"Map",
|
||||||
|
"Null",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
required: { type: Boolean },
|
required: { type: Boolean },
|
||||||
refKey: { type: Object },
|
refKey: { type: Object },
|
||||||
default: { type: Schema.Types.Mixed },
|
default: { type: Schema.Types.Mixed },
|
||||||
unique: { type: Boolean },
|
unique: { type: Boolean },
|
||||||
|
primary: { type: Boolean },
|
||||||
index: { type: Boolean },
|
index: { type: Boolean },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
interface ColorHex {
|
||||||
|
type: "HEX";
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
interface ColorRGB {
|
||||||
|
type: "RGB";
|
||||||
|
value: { r: number; g: number; b: number };
|
||||||
|
}
|
||||||
|
interface ColorHSL {
|
||||||
|
type: "HSL";
|
||||||
|
value: { h: number; s: number; l: number };
|
||||||
|
}
|
||||||
|
type BackgroundColor = ColorHex | ColorRGB | ColorHSL;
|
||||||
|
const backgroundColorSchema = new Schema({
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
enum: ["HEX", "RGB", "HSL"],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
const collectionSchema: Schema<ICollectionNode> = new Schema(
|
const collectionSchema: Schema<ICollectionNode> = new Schema(
|
||||||
{
|
{
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
collectionNodeName: { type: String },
|
parentCollectionNodeId: { type: Schema.Types.ObjectId, ref: "Collection" },
|
||||||
position: { type: [Number], required: true },
|
attributeparentId: { type: Schema.Types.ObjectId, ref: "Collection" },
|
||||||
|
collectionName: { type: String },
|
||||||
|
type: { type: String, enum: ["collectionNode", "objectNode"] },
|
||||||
|
backgroundColor: { type: backgroundColorSchema },
|
||||||
|
borderColor: { type: backgroundColorSchema },
|
||||||
|
fontColor: { type: backgroundColorSchema },
|
||||||
|
lineColor: { type: backgroundColorSchema },
|
||||||
|
position: {
|
||||||
|
x: { type: Number },
|
||||||
|
y: { type: Number },
|
||||||
|
},
|
||||||
|
lineThickness: { type: Number },
|
||||||
|
fontName: { type: String },
|
||||||
|
lineType: { type: String },
|
||||||
|
borderThickness: { type: Number },
|
||||||
|
cornerRadius: { type: Number },
|
||||||
|
fontSize: { type: Number },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
|
isSubCollection: { type: Boolean, default: false },
|
||||||
attributes: [attributeSchema],
|
attributes: [attributeSchema],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -70,4 +139,4 @@ const collectionSchema: Schema<ICollectionNode> = new Schema(
|
|||||||
const collectionsModel = (db: any) => {
|
const collectionsModel = (db: any) => {
|
||||||
return MainModel(db, "collectionNode", collectionSchema, "collectionNode");
|
return MainModel(db, "collectionNode", collectionSchema, "collectionNode");
|
||||||
};
|
};
|
||||||
export default collectionsModel;
|
export default collectionsModel;
|
||||||
|
|||||||
110
src/shared/model/dummycollectionmodel.ts
Normal file
110
src/shared/model/dummycollectionmodel.ts
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../connection/connection";
|
||||||
|
import { IProject } from "./projectmodel";
|
||||||
|
|
||||||
|
export const attributeTypes = [
|
||||||
|
"string",
|
||||||
|
"any",
|
||||||
|
"Array",
|
||||||
|
"Date",
|
||||||
|
"Enum",
|
||||||
|
"undefined",
|
||||||
|
"object",
|
||||||
|
"ObjectId",
|
||||||
|
"number",
|
||||||
|
"boolean",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type IattributeTypes = (typeof attributeTypes)[number];
|
||||||
|
|
||||||
|
interface IField {
|
||||||
|
type: IattributeTypes;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IcollectionData {
|
||||||
|
isArchive: boolean;
|
||||||
|
fields: Map<string, IField>;
|
||||||
|
}
|
||||||
|
interface ColorHex {
|
||||||
|
type: "HEX";
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
interface ColorRGB {
|
||||||
|
type: "RGB";
|
||||||
|
value: { r: number; g: number; b: number };
|
||||||
|
}
|
||||||
|
interface ColorHSL {
|
||||||
|
type: "HSL";
|
||||||
|
value: { h: number; s: number; l: number };
|
||||||
|
}
|
||||||
|
type BackgroundColor = ColorHex | ColorRGB | ColorHSL;
|
||||||
|
const backgroundColorSchema = new Schema({
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
enum: ["HEX", "RGB", "HSL"],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
export interface ICollectionNode extends Document {
|
||||||
|
projectId: IProject["_id"];
|
||||||
|
parentCollectionNodeId: ICollectionNode["_id"];
|
||||||
|
isSubCollection: boolean;
|
||||||
|
attributeparentId: ICollectionNode["_id"];
|
||||||
|
collectionName: string;
|
||||||
|
collections: IcollectionData[];
|
||||||
|
position: [number, number, number];
|
||||||
|
backgroundColor: BackgroundColor;
|
||||||
|
borderColor: BackgroundColor;
|
||||||
|
lineColor: BackgroundColor;
|
||||||
|
fontColor: BackgroundColor;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldSchema = new Schema<IField>({
|
||||||
|
type: { type: String, enum: attributeTypes, required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const collectionSchema = new Schema<IcollectionData>({
|
||||||
|
fields: {
|
||||||
|
type: Map,
|
||||||
|
of: fieldSchema,
|
||||||
|
default: () => new Map<string, IField>(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodeSchema: Schema<ICollectionNode> = new Schema(
|
||||||
|
{
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
collectionName: { type: String },
|
||||||
|
parentCollectionNodeId: { type: Schema.Types.ObjectId, ref: "Collection" },
|
||||||
|
attributeparentId: { type: Schema.Types.ObjectId, ref: "Collection" },
|
||||||
|
position: { type: [Number], required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
collections: [collectionSchema],
|
||||||
|
isSubCollection: { type: Boolean, default: false },
|
||||||
|
backgroundColor: { type: backgroundColorSchema },
|
||||||
|
borderColor: { type: backgroundColorSchema },
|
||||||
|
fontColor: { type: backgroundColorSchema },
|
||||||
|
lineColor: { type: backgroundColorSchema },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timestamps: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const dummyModel = (db: any) => {
|
||||||
|
return MainModel(
|
||||||
|
db,
|
||||||
|
"collectionNodeDummy",
|
||||||
|
nodeSchema,
|
||||||
|
"collectionNodeDummy"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default dummyModel;
|
||||||
@@ -1,29 +1,32 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
import { IProject } from "./projectmodel";
|
import { IProject } from "./projectmodel";
|
||||||
interface IEdgeModel extends Document {
|
export interface IEdgeModel extends Document {
|
||||||
projectId: IProject["_id"];
|
projectId: IProject["_id"];
|
||||||
from: { collection_id: string; field: string };
|
from: { collection_id: string; field: string };
|
||||||
to: { collection_id: string };
|
to: { collection_id: string };
|
||||||
cardinality: "one-to-one" | "one-to-many"|"many-to-many"
|
cardinality: "one-to-one" | "one-to-many" | "many-to-many";
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
const EdgeSchema = new Schema<IEdgeModel>({
|
const EdgeSchema = new Schema<IEdgeModel>({
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
|
||||||
from: {
|
from: {
|
||||||
collection_id: { type: String, required: true },
|
collection_id: { type: String, required: true },
|
||||||
field: { type: String, required: true },
|
field: { type: String, required: true },
|
||||||
},
|
},
|
||||||
to: {
|
to: {
|
||||||
collection_id: { type: String, required: true },
|
collection_id: { type: String, required: true },
|
||||||
},
|
},
|
||||||
cardinality: { type: String, enum: ["one-to-one", "one-to-many", "many-to-many"], required: true },
|
cardinality: {
|
||||||
isArchive: { type: Boolean, default: false },
|
type: String,
|
||||||
createdAt: { type: Number, default: Date.now },
|
enum: ["one-to-one", "one-to-many", "many-to-many"],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
createdAt: { type: Number, default: Date.now },
|
||||||
});
|
});
|
||||||
const edgeModel = (db: any) => {
|
const edgeModel = (db: any) => {
|
||||||
return MainModel(db, "edge", EdgeSchema, "edge");
|
return MainModel(db, "edge", EdgeSchema, "edge");
|
||||||
};
|
};
|
||||||
export default edgeModel;
|
export default edgeModel;
|
||||||
|
|||||||
@@ -1,34 +1,40 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
|
import { IUser } from "./userModel";
|
||||||
export interface IProject extends Document {
|
export interface IProject extends Document {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
appType: string;
|
thumbnail: string;
|
||||||
|
application: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
createdBy: string;
|
createdBy: IUser["_id"];
|
||||||
description: string;
|
description: string;
|
||||||
members: [string];
|
members: [string];
|
||||||
useableLanguage: string;
|
language: string;
|
||||||
typeOfDB: string;
|
typeOfDB: string;
|
||||||
DBName: string;
|
DBName: string;
|
||||||
architecture: string;
|
architecture: string;
|
||||||
apiType: string;
|
apiProtocol: string;
|
||||||
}
|
}
|
||||||
const projectSchema: Schema = new Schema(
|
const projectSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
projectName: { type: String },
|
projectName: { type: String },
|
||||||
appType:{type:String,enum:["Backend","Frontend"]},
|
thumbnail: { type: String },
|
||||||
|
application: {
|
||||||
|
type: String,
|
||||||
|
enum: ["Web App", "Mobile App", "Desktop App", "IoT", "Microservices"],
|
||||||
|
},
|
||||||
slug: { type: String },
|
slug: { type: String },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
createdBy: { type: String },
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
description: { type: String },
|
description: { type: String },
|
||||||
DBName: { type: String },
|
DBName: { type: String },
|
||||||
typeOfDB: { type: String },
|
typeOfDB: { type: String },
|
||||||
useableLanguage: { type: String },
|
language: { type: String },
|
||||||
architecture: { type: String },
|
architecture: { type: String, enum: ["MVVM", "MVP", "MVC", "CQRS"] },
|
||||||
apiType: {
|
apiProtocol: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ["RESTful", "SOAP", "GraphQL", "RPC", "WebSocket"],
|
enum: ["REST", "SOAP", "GraphQL", "gRPC", "WebSockets"],
|
||||||
},
|
},
|
||||||
members: { type: [String] },
|
members: { type: [String] },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import mongoose, { Document, Schema } from "mongoose";
|
import mongoose, { Document, Schema } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
import { IProject } from "./projectmodel";
|
import { IProject } from "./projectmodel";
|
||||||
import { User } from "./userModel";
|
import { IUser } from "./userModel";
|
||||||
|
|
||||||
export interface ISharedUser {
|
export interface ISharedUser {
|
||||||
userId: User["_id"];
|
userId: IUser["_id"];
|
||||||
accessLevel: "Viewer" | "Editor" | "Admin";
|
accessLevel: "Viewer" | "Editor" | "Admin";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
import { User } from "./userModel";
|
import { IUser } from "./userModel";
|
||||||
export interface IUserToken extends Document {
|
export interface IUserToken extends Document {
|
||||||
userId: User["_id"];
|
userId: IUser["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
resetTokenExpiry?: Date;
|
resetTokenExpiry?: Date;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
import { User } from "./userModel";
|
import { IUser } from "./userModel";
|
||||||
export interface IUserData extends Document {
|
export interface IUserData extends Document {
|
||||||
userId: User["_id"];
|
userId: IUser["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
profilePicture: string;
|
profilePicture: string;
|
||||||
recentlyViewed: string[];
|
recentlyViewed: string[];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
export interface User extends Document {
|
export interface IUser extends Document {
|
||||||
userName: string;
|
userName: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
|||||||
35
src/shared/model/versionModel.ts
Normal file
35
src/shared/model/versionModel.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../connection/connection";
|
||||||
|
import { IProject } from "./projectmodel";
|
||||||
|
import { IUser } from "./userModel";
|
||||||
|
export interface Version extends Document {
|
||||||
|
versionName: string;
|
||||||
|
previous_Version: string;
|
||||||
|
projectId: IProject["_id"];
|
||||||
|
createdBy: IUser["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
version: number;
|
||||||
|
rollBackComment: string;
|
||||||
|
description: string;
|
||||||
|
parentVersionID: Version["_id"];
|
||||||
|
}
|
||||||
|
const versionSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
versionName: { type: String, default: "" },
|
||||||
|
rollBackComment: { type: String },
|
||||||
|
description: { type: String, default: "" },
|
||||||
|
version: { type: Number },
|
||||||
|
parentVersionID: { type: Schema.Types.ObjectId, ref: "version" },
|
||||||
|
previous_Version: { type: String },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const versionModel = (db: string) => {
|
||||||
|
return MainModel(db, "Versions", versionSchema, "Versions");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default versionModel;
|
||||||
@@ -13,13 +13,18 @@ interface Iresponse {
|
|||||||
interface Isignup {
|
interface Isignup {
|
||||||
userName: string;
|
userName: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string
|
||||||
confirmPassword: string;
|
|
||||||
}
|
}
|
||||||
interface Isignin {
|
interface Isignin {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface signout {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface IforGotPassword {
|
interface IforGotPassword {
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
@@ -32,15 +37,15 @@ export async function existingUserData(email: string, organization: string) {
|
|||||||
return existingData;
|
return existingData;
|
||||||
}
|
}
|
||||||
export const signupService = async (data: Isignup): Promise<Iresponse> => {
|
export const signupService = async (data: Isignup): Promise<Iresponse> => {
|
||||||
const { userName, email, password, confirmPassword } = data;
|
const { userName, email, password } = data;
|
||||||
try {
|
try {
|
||||||
const mailCaseChange = email.toLocaleLowerCase();
|
const mailCaseChange = email.toLocaleLowerCase();
|
||||||
const organization = email.split("@")[1].split(".")[0];
|
const organization = email.split("@")[1].split(".")[0];
|
||||||
const mailExistance = await existingUserData(mailCaseChange, organization);
|
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||||
if (mailExistance !== null) return { status: "User Already exists" };
|
if (mailExistance !== null) return { status: "User Already exists" };
|
||||||
if (password !== confirmPassword) {
|
// if (password !== confirmPassword) {
|
||||||
return { status: "Passwords do not match" };
|
// return { status: "Passwords do not match" };
|
||||||
}
|
// }
|
||||||
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({});
|
||||||
@@ -72,8 +77,7 @@ export const signinService = async (data: Isignin): Promise<Iresponse> => {
|
|||||||
const mailCaseChange = email.toLocaleLowerCase();
|
const mailCaseChange = email.toLocaleLowerCase();
|
||||||
const organization = email.split("@")[1].split(".")[0];
|
const organization = email.split("@")[1].split(".")[0];
|
||||||
const mailExistance = await existingUserData(mailCaseChange, organization);
|
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||||
if (mailExistance == null)
|
if (!mailExistance) return { status: "User not found!!! Kindly Signup" };
|
||||||
return { status: "User not found!!! Kindly Signup" };
|
|
||||||
const comparePassword = await hashValidator(
|
const comparePassword = await hashValidator(
|
||||||
password,
|
password,
|
||||||
mailExistance.password
|
mailExistance.password
|
||||||
@@ -230,3 +234,39 @@ export const forgetPassword = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const signOutService = async (data: signout): Promise<Iresponse> => {
|
||||||
|
const { email } = data;
|
||||||
|
try {
|
||||||
|
const mailCaseChange = email.toLocaleLowerCase();
|
||||||
|
const organization = email.split("@")[1].split(".")[0];
|
||||||
|
const mailExistance = await existingUserData(mailCaseChange, organization);
|
||||||
|
if (!mailExistance) return { status: "User not found!!! Kindly Signup" };
|
||||||
|
|
||||||
|
const tokenData = await tokenModel(organization).findOne({
|
||||||
|
userId: mailExistance._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!tokenData) return { status: "Token not found" };
|
||||||
|
await Promise.all([
|
||||||
|
redis.del(`token:${mailCaseChange}`),
|
||||||
|
redis.del(`user:${mailCaseChange}`),
|
||||||
|
]);
|
||||||
|
tokenData.refreshToken = "";
|
||||||
|
await tokenData.save();
|
||||||
|
mailExistance.visitorBrowserID = "";
|
||||||
|
await mailExistance.save();
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import ProjectType from "../../shared/model/projectmodel";
|
import ProjectType from "../../shared/model/projectmodel";
|
||||||
import collectionsModel from "../model/collectionModel";
|
import collectionsModel from "../model/collectionModel";
|
||||||
|
import edgeModel from "../model/edgeModel";
|
||||||
|
import userModel from "../model/userModel";
|
||||||
interface Iresponse {
|
interface Iresponse {
|
||||||
status: string;
|
status: string;
|
||||||
data?: any;
|
data?: any;
|
||||||
@@ -8,6 +10,8 @@ interface Iresponse {
|
|||||||
interface IcollectionNode {
|
interface IcollectionNode {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
collectionName: string;
|
||||||
|
type: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
position: [number];
|
position: [number];
|
||||||
}
|
}
|
||||||
@@ -21,6 +25,15 @@ interface IcollectionNodeName {
|
|||||||
organization: string;
|
organization: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
|
backgroundColor: string;
|
||||||
|
borderColor: string;
|
||||||
|
lineColor: string;
|
||||||
|
fontColor: string;
|
||||||
|
lineThickness: number;
|
||||||
|
fontName: string;
|
||||||
|
lineType: string;
|
||||||
|
borderThickness: number;
|
||||||
|
cornerRadius: number;
|
||||||
position: [number];
|
position: [number];
|
||||||
}
|
}
|
||||||
interface IcollectionAttributes {
|
interface IcollectionAttributes {
|
||||||
@@ -41,6 +54,11 @@ interface IcollectionNodeById {
|
|||||||
userId: string;
|
userId: string;
|
||||||
collectionNodeId: string;
|
collectionNodeId: string;
|
||||||
}
|
}
|
||||||
|
interface IcollectionLists {
|
||||||
|
projectId: string;
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
interface IAttributesEdit {
|
interface IAttributesEdit {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -49,6 +67,7 @@ interface IAttributesEdit {
|
|||||||
attributeId: string;
|
attributeId: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
|
primary:boolean
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
defaultValue?: any;
|
defaultValue?: any;
|
||||||
unique?: boolean;
|
unique?: boolean;
|
||||||
@@ -76,12 +95,25 @@ interface IDuplicateCollectionNode {
|
|||||||
position: [number];
|
position: [number];
|
||||||
attributes: [];
|
attributes: [];
|
||||||
}
|
}
|
||||||
|
interface IDuplicateattributes {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
organization: string;
|
||||||
|
attrKey: string;
|
||||||
|
}
|
||||||
export const Nodecreation = async (
|
export const Nodecreation = async (
|
||||||
data: IcollectionNode
|
data: IcollectionNode
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId, position, userId } = data;
|
const { organization, projectId, position, userId, collectionName, type } =
|
||||||
|
data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -89,29 +121,52 @@ export const Nodecreation = async (
|
|||||||
if (!existingProject) {
|
if (!existingProject) {
|
||||||
return { status: "project not found" };
|
return { status: "project not found" };
|
||||||
} else {
|
} else {
|
||||||
|
const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
collectionName: collectionName,
|
||||||
|
});
|
||||||
|
if (existingCollection)
|
||||||
|
return { status: "CollectionName already exists" };
|
||||||
|
let attributes = [{ key: "auto_id", type: "string" }];
|
||||||
|
const newAttributes = attributes;
|
||||||
|
const updatedAttributesMap = new Map<string, any>();
|
||||||
|
|
||||||
|
// for (const attr of existingAttributes) {
|
||||||
|
// updatedAttributesMap.set(attr.key, attr);
|
||||||
|
// }
|
||||||
|
|
||||||
|
for (const attr of newAttributes) {
|
||||||
|
if (!updatedAttributesMap.has(attr.key)) {
|
||||||
|
updatedAttributesMap.set(attr.key, attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedAttributes = Array.from(updatedAttributesMap.values());
|
||||||
const newCollectionnode = await collectionsModel(organization).create({
|
const newCollectionnode = await collectionsModel(organization).create({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
position: position,
|
position: position,
|
||||||
|
type,
|
||||||
|
collectionName: collectionName,
|
||||||
|
attributes: updatedAttributes,
|
||||||
});
|
});
|
||||||
if (!newCollectionnode)
|
if (!newCollectionnode)
|
||||||
return { status: "Collection node creation unsuccessfull" };
|
return { status: "Collection node creation unsuccessfull" };
|
||||||
else return { status: "Success", data: newCollectionnode._id };
|
else return { status: "Success", data: newCollectionnode._id };
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof mongoose.Error.ValidationError) {
|
||||||
return {
|
return { status: "Validation Error", data: error.message };
|
||||||
status: error.message,
|
} else if (error instanceof Error) {
|
||||||
};
|
return { status: error.message };
|
||||||
} else {
|
} else {
|
||||||
return {
|
return { status: "An unexpected error occurred" };
|
||||||
status: "An unexpected error occurred",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SetCollectionName = async (
|
export const updatecollection = async (
|
||||||
data: IcollectionNodeName
|
data: IcollectionNodeName
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const {
|
const {
|
||||||
@@ -119,10 +174,25 @@ export const SetCollectionName = async (
|
|||||||
projectId,
|
projectId,
|
||||||
position,
|
position,
|
||||||
collectionNodeId,
|
collectionNodeId,
|
||||||
|
backgroundColor,
|
||||||
|
borderColor,
|
||||||
|
fontColor,
|
||||||
|
lineColor,
|
||||||
|
lineThickness,
|
||||||
|
fontName,
|
||||||
|
lineType,
|
||||||
|
borderThickness,
|
||||||
|
cornerRadius,
|
||||||
collectionName,
|
collectionName,
|
||||||
userId,
|
userId,
|
||||||
} = data;
|
} = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -146,7 +216,19 @@ export const SetCollectionName = async (
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
_id: collectionNodeId,
|
_id: collectionNodeId,
|
||||||
},
|
},
|
||||||
{ collectionNodeName: collectionName },
|
{
|
||||||
|
collectionName: collectionName,
|
||||||
|
backgroundColor,
|
||||||
|
borderColor,
|
||||||
|
fontColor,
|
||||||
|
lineColor,
|
||||||
|
position,
|
||||||
|
lineThickness,
|
||||||
|
fontName,
|
||||||
|
lineType,
|
||||||
|
borderThickness,
|
||||||
|
cornerRadius,
|
||||||
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
return { status: "Success" };
|
return { status: "Success" };
|
||||||
@@ -170,6 +252,12 @@ export const addAttributes = async (
|
|||||||
const { organization, projectId, userId, collectionNodeId, attributes } =
|
const { organization, projectId, userId, collectionNodeId, attributes } =
|
||||||
data;
|
data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -211,6 +299,41 @@ export const addAttributes = async (
|
|||||||
{ attributes: updatedAttributes },
|
{ attributes: updatedAttributes },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
if (AttributesAdded) {
|
||||||
|
for (const attr of AttributesAdded.attributes) {
|
||||||
|
if (attr.type === "Object") {
|
||||||
|
const existingsubcollection = await collectionsModel(
|
||||||
|
organization
|
||||||
|
).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
parentCollectionNodeId: collectionNodeId,
|
||||||
|
attributeparentId: (attr as any)._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingsubcollection) {
|
||||||
|
const newCollection = await collectionsModel(organization).create(
|
||||||
|
{
|
||||||
|
type: "objectNode",
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
collectionName: attr.key,
|
||||||
|
parentCollectionNodeId: collectionNodeId,
|
||||||
|
attributeparentId: (attr as any)._id,
|
||||||
|
attributes: [],
|
||||||
|
// position: [0, 0, 0],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
AttributesAdded.isSubCollection = true;
|
||||||
|
await AttributesAdded.save();
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "Subcollection already added for the object data",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await AttributesAdded.save();
|
||||||
|
}
|
||||||
return { status: "Success" };
|
return { status: "Success" };
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -226,11 +349,18 @@ export const addAttributes = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//both collections and edges in projects
|
||||||
export const GetNodesInProject = async (
|
export const GetNodesInProject = async (
|
||||||
data: IcollectionNodes
|
data: IcollectionNodes
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, userId, projectId } = data;
|
const { organization, userId, projectId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -238,23 +368,83 @@ export const GetNodesInProject = async (
|
|||||||
if (!existingProject) {
|
if (!existingProject) {
|
||||||
return { status: "project not found" };
|
return { status: "project not found" };
|
||||||
} else {
|
} else {
|
||||||
const collectionNodes = await collectionsModel(organization)
|
let collectionNodes = await collectionsModel(organization)
|
||||||
.find({ projectId: projectId, isArchive: false })
|
.find({ projectId: projectId, isArchive: false })
|
||||||
.select("collectionNodeName attributes position -_id ");
|
.select(
|
||||||
|
"collectionName attributes position _id type parentCollectionNodeId attributeparentId"
|
||||||
|
);
|
||||||
if (!collectionNodes)
|
if (!collectionNodes)
|
||||||
return { status: "No collection Nodes present", data: [] };
|
return { status: "No collection Nodes present", data: [] };
|
||||||
else {
|
else {
|
||||||
const formattedCollections = collectionNodes.map((collection) => ({
|
const edgeDatas = await edgeModel(organization).find({
|
||||||
position: collection.position,
|
isArchive: false,
|
||||||
collectionNodeName: collection.collectionNodeName,
|
});
|
||||||
attributes: collection.attributes
|
|
||||||
.filter((attr: any) => !attr.isArchive)
|
const filteredEdges = await Promise.all(
|
||||||
.map((attr: any) => {
|
edgeDatas.map(async (e: any) => {
|
||||||
const { isArchive, ...rest } = attr.toObject();
|
const targetCollection = await collectionsModel(organization)
|
||||||
return { ...rest };
|
.findOne({ _id: e.to.collection_id, isArchive: false })
|
||||||
}),
|
.lean();
|
||||||
}));
|
|
||||||
return { status: "Success", data: formattedCollections };
|
let targetFieldKey = null;
|
||||||
|
|
||||||
|
if (targetCollection && targetCollection.attributes?.length > 0) {
|
||||||
|
const refAttribute = targetCollection.attributes.find(
|
||||||
|
(attr: any) =>
|
||||||
|
attr.refKey &&
|
||||||
|
attr.refKey.collection_id?.toString() ===
|
||||||
|
e.from.collection_id.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (refAttribute) {
|
||||||
|
targetFieldKey = refAttribute.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
edgeId: e._id,
|
||||||
|
source: e.from.collection_id,
|
||||||
|
sourceHandle: e.from.field,
|
||||||
|
target: e.to.collection_id,
|
||||||
|
targetHandle: targetFieldKey || e.to.collection_id,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const formattedCollections = collectionNodes.map((collection: any) => {
|
||||||
|
const baseData = {
|
||||||
|
collectionId: collection._id,
|
||||||
|
position: collection.position,
|
||||||
|
type: collection.type,
|
||||||
|
data: {
|
||||||
|
collectionName: collection.collectionName,
|
||||||
|
collectionData: collection.attributes
|
||||||
|
.filter((attr: any) => !attr.isArchive)
|
||||||
|
.map((attr: any) => {
|
||||||
|
if (attr.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const { isArchive, refKey, ...rest } = attr.toObject
|
||||||
|
? attr.toObject()
|
||||||
|
: attr;
|
||||||
|
return { ...rest };
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (collection.type === "objectNode") {
|
||||||
|
return {
|
||||||
|
...baseData,
|
||||||
|
parentId: collection.parentCollectionNodeId,
|
||||||
|
parentFieldId: collection.attributeparentId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return baseData;
|
||||||
|
});
|
||||||
|
const finalResult = {
|
||||||
|
nodes: formattedCollections,
|
||||||
|
edges: filteredEdges,
|
||||||
|
};
|
||||||
|
return { status: "Success", data: finalResult };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -270,6 +460,105 @@ export const GetNodesInProject = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// export const GetNodesInProject = async (
|
||||||
|
// data: IcollectionNodes
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const { organization, userId, projectId } = data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const collectionNodes = await collectionsModel(organization)
|
||||||
|
// .find({ projectId: projectId, isArchive: false })
|
||||||
|
// .select("collectionName attributes position -_id isSubCollection");
|
||||||
|
// if (!collectionNodes)
|
||||||
|
// return { status: "No collection Nodes present", data: [] };
|
||||||
|
// else {
|
||||||
|
// const fetchNestedAttributes = async (
|
||||||
|
// parentCollectionNodeId: string,
|
||||||
|
// attributeId: string
|
||||||
|
// ): Promise<any> => {
|
||||||
|
// const subCollection = await collectionsModel(organization)
|
||||||
|
// .findOne({
|
||||||
|
// parentCollectionNodeId,
|
||||||
|
// attributeparentId: attributeId,
|
||||||
|
// isArchive: false,
|
||||||
|
// })
|
||||||
|
// .select("collectionName attributes");
|
||||||
|
|
||||||
|
// if (!subCollection) {
|
||||||
|
// return {}; // If no sub-collection exists, return empty object
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const nestedAttributes: Record<string, any> = {};
|
||||||
|
// for (const attr of subCollection.attributes) {
|
||||||
|
// if (attr.type === "object") {
|
||||||
|
// nestedAttributes[attr.key] = {
|
||||||
|
// type: "object",
|
||||||
|
// attributes: await fetchNestedAttributes(
|
||||||
|
// subCollection._id as string,
|
||||||
|
// (attr as any)._id
|
||||||
|
// ),
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// nestedAttributes[attr.key] = attr.type;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return nestedAttributes;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // Format the main collections
|
||||||
|
// const formattedCollections = await Promise.all(
|
||||||
|
// collectionNodes.map(async (collection) => {
|
||||||
|
// const formattedAttributes: Record<string, any> = {};
|
||||||
|
|
||||||
|
// for (const attr of collection.attributes) {
|
||||||
|
// if (attr.type === "object") {
|
||||||
|
// formattedAttributes[attr.key] = {
|
||||||
|
// type: "object",
|
||||||
|
// attributes: await fetchNestedAttributes(
|
||||||
|
// collection._id as string,
|
||||||
|
// (attr as any)._id
|
||||||
|
// ),
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// formattedAttributes[attr.key] = attr.type;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// position: collection.position,
|
||||||
|
// collectionName: collection.collectionName,
|
||||||
|
// attributes: formattedAttributes,
|
||||||
|
// };
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// status: "Success",
|
||||||
|
// data: formattedCollections,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
export const UpdateAttributes = async (
|
export const UpdateAttributes = async (
|
||||||
data: IAttributesEdit
|
data: IAttributesEdit
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
@@ -287,6 +576,12 @@ export const UpdateAttributes = async (
|
|||||||
type,
|
type,
|
||||||
} = data;
|
} = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -344,6 +639,12 @@ export const DelAttributes = async (
|
|||||||
const { organization, userId, projectId, collectionNodeId, AttributeId } =
|
const { organization, userId, projectId, collectionNodeId, AttributeId } =
|
||||||
data;
|
data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -398,6 +699,12 @@ export const delCollection = async (
|
|||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, userId, projectId, collectionNodeId } = data;
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -444,6 +751,12 @@ export const GetcollectionNode = async (
|
|||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, userId, projectId, collectionNodeId } = data;
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -461,13 +774,64 @@ export const GetcollectionNode = async (
|
|||||||
}
|
}
|
||||||
const formattedCollection = {
|
const formattedCollection = {
|
||||||
position: existingCollection.position,
|
position: existingCollection.position,
|
||||||
collectionNodeName: existingCollection.collectionNodeName,
|
data: {
|
||||||
attributes: existingCollection.attributes
|
collectionName: existingCollection.collectionName,
|
||||||
.filter((attr: any) => !attr.isArchive)
|
attributes: existingCollection.attributes
|
||||||
.map((attr: any) => {
|
.filter((attr: any) => !attr.isArchive)
|
||||||
const { isArchive, ...rest } = attr.toObject();
|
.map((attr: any) => {
|
||||||
return rest;
|
const { isArchive, ...rest } = attr.toObject();
|
||||||
}),
|
return rest;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return { status: "Success", data: formattedCollection };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetcollectionGraphicData = async (
|
||||||
|
data: IcollectionNodeById
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await collectionsModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
})
|
||||||
|
.select(
|
||||||
|
"backgroundColor borderColor fontColor lineColor position lineThickness fontName lineType borderThickness cornerRadius fontSize"
|
||||||
|
);
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
const formattedCollection = {
|
||||||
|
position: existingCollection.position,
|
||||||
|
collectionName: existingCollection.collectionName,
|
||||||
};
|
};
|
||||||
return { status: "Success", data: formattedCollection };
|
return { status: "Success", data: formattedCollection };
|
||||||
}
|
}
|
||||||
@@ -496,7 +860,7 @@ const generateUniqueCollectionName = async (
|
|||||||
const existingCollection = await collectionsModel(organization).findOne({
|
const existingCollection = await collectionsModel(organization).findOne({
|
||||||
projectId,
|
projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
collectionNodeName: nameToTry,
|
collectionName: nameToTry,
|
||||||
});
|
});
|
||||||
if (!existingCollection) {
|
if (!existingCollection) {
|
||||||
return nameToTry;
|
return nameToTry;
|
||||||
@@ -509,11 +873,18 @@ const generateUniqueCollectionName = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DuplicateCollection = async (
|
export const DuplicateCollection = async (
|
||||||
data: IDuplicateCollectionNode
|
data: IDuplicateCollectionNode
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, userId, projectId, position, collectionNodeId } = data;
|
const { organization, userId, projectId, position, collectionNodeId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -530,7 +901,7 @@ export const DuplicateCollection = async (
|
|||||||
return { status: "CollectionId not found for duplication" };
|
return { status: "CollectionId not found for duplication" };
|
||||||
else {
|
else {
|
||||||
const NewduplicateName = await generateUniqueCollectionName(
|
const NewduplicateName = await generateUniqueCollectionName(
|
||||||
existingCollection.collectionNodeName,
|
existingCollection.collectionName,
|
||||||
organization,
|
organization,
|
||||||
projectId
|
projectId
|
||||||
);
|
);
|
||||||
@@ -541,7 +912,7 @@ export const DuplicateCollection = async (
|
|||||||
projectId,
|
projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
position,
|
position,
|
||||||
collectionNodeName: NewduplicateName,
|
collectionName: NewduplicateName,
|
||||||
});
|
});
|
||||||
if (!NewCollectionDuplicate)
|
if (!NewCollectionDuplicate)
|
||||||
return { status: "Duplication unsuccessfull" };
|
return { status: "Duplication unsuccessfull" };
|
||||||
@@ -570,3 +941,131 @@ export const DuplicateCollection = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const DuplicateAttributes = async (
|
||||||
|
data: IDuplicateattributes
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
attrKey,
|
||||||
|
// position,
|
||||||
|
collectionNodeId,
|
||||||
|
} = data;
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
});
|
||||||
|
if (!existingCollection)
|
||||||
|
return { status: "CollectionId not found for duplication" };
|
||||||
|
else {
|
||||||
|
const existingAttr = existingCollection.attributes.find(
|
||||||
|
(attr: any) => attr.key.toLowerCase() === attrKey.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("existingAttr: ", existingAttr);
|
||||||
|
if (existingAttr) {
|
||||||
|
let counter = 1;
|
||||||
|
let newKey = `${attrKey}(${counter})`;
|
||||||
|
console.log("attrKey: ", attrKey);
|
||||||
|
console.log("newKey: ", newKey);
|
||||||
|
|
||||||
|
while (
|
||||||
|
existingCollection.attributes.some(
|
||||||
|
(attr: any) => attr.key === newKey
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
console.log("hi");
|
||||||
|
counter++;
|
||||||
|
newKey = `${attrKey}(${counter})`;
|
||||||
|
console.log("newKey: ", newKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("existingAttr.type: ", existingAttr.type);
|
||||||
|
existingCollection.attributes.push({
|
||||||
|
key: newKey,
|
||||||
|
type: existingAttr.type,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return { status: "Attribute doesnot match" };
|
||||||
|
}
|
||||||
|
await existingCollection.save();
|
||||||
|
}
|
||||||
|
return { status: "Success", data: existingCollection };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetcollectionLists = async (
|
||||||
|
data: IcollectionLists
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, userId, projectId } = data;
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await collectionsModel(organization)
|
||||||
|
.find({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("collectionName -_id");
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
const formattedCollection = {
|
||||||
|
projectName: existingProject.projectName,
|
||||||
|
application: existingProject.application,
|
||||||
|
collectionsName: existingCollection || [],
|
||||||
|
};
|
||||||
|
return { status: "Success", data: formattedCollection };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
680
src/shared/services/dummyService.ts
Normal file
680
src/shared/services/dummyService.ts
Normal file
@@ -0,0 +1,680 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
import ProjectType from "../../shared/model/projectmodel";
|
||||||
|
import collectionsModel from "../model/collectionModel";
|
||||||
|
import dummyModel from "../model/dummycollectionmodel";
|
||||||
|
interface Iresponse {
|
||||||
|
status: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
||||||
|
interface IcollectionNode {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionName: string;
|
||||||
|
position: [number];
|
||||||
|
}
|
||||||
|
interface IAttribute {
|
||||||
|
key: string;
|
||||||
|
type: any;
|
||||||
|
}
|
||||||
|
interface IcollectionNodeName {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
collectionName: string;
|
||||||
|
position: [number];
|
||||||
|
}
|
||||||
|
interface IcollectionAttributes {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
attributes: IAttribute[];
|
||||||
|
}
|
||||||
|
interface IcollectionNodes {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
interface IcollectionNodeById {
|
||||||
|
projectId: string;
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
}
|
||||||
|
interface IcollectionNodeRenameKey {
|
||||||
|
projectId: string;
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
newKeyName: string;
|
||||||
|
oldKeyName: string;
|
||||||
|
}
|
||||||
|
interface IAttributesEdit {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
attributeId: string;
|
||||||
|
key?: string;
|
||||||
|
type?: string;
|
||||||
|
required?: boolean;
|
||||||
|
defaultValue?: any;
|
||||||
|
unique?: boolean;
|
||||||
|
index?: boolean;
|
||||||
|
}
|
||||||
|
interface IAttributesDel {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
AttributeId: string;
|
||||||
|
}
|
||||||
|
interface ICollectionDelete {
|
||||||
|
projectId: string;
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
}
|
||||||
|
interface IDuplicateCollectionNode {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
collectionNodeId: string;
|
||||||
|
organization: string;
|
||||||
|
collectionName: string;
|
||||||
|
position: [number];
|
||||||
|
attributes: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Nodecreationdummy = async (
|
||||||
|
data: IcollectionNode
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, projectId, position, userId, collectionName } = data;
|
||||||
|
try {
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const newCollectionnode = await dummyModel(organization).create({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
position: position,
|
||||||
|
collectionName: collectionName,
|
||||||
|
});
|
||||||
|
if (!newCollectionnode)
|
||||||
|
return { status: "Collection node creation unsuccessfull" };
|
||||||
|
else return { status: "Success", data: newCollectionnode._id };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SetCollectionNamedummy = async (
|
||||||
|
data: IcollectionNodeName
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
position,
|
||||||
|
collectionNodeId,
|
||||||
|
collectionName,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
|
try {
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await dummyModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
});
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
const collectionNameupdate = await dummyModel(
|
||||||
|
organization
|
||||||
|
).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
},
|
||||||
|
{ collectionName: collectionName },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
return { status: "Success" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const addAttributesdummy = async (
|
||||||
|
data: IcollectionAttributes
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, projectId, userId, collectionNodeId, attributes } =
|
||||||
|
data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingCollection = await dummyModel(organization).findOne({
|
||||||
|
_id: collectionNodeId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
let collections = existingCollection.collections || [];
|
||||||
|
|
||||||
|
if (collections.length === 0) {
|
||||||
|
collections.push({ fields: new Map<string, any>(), isArchive: false });
|
||||||
|
// collections.push({ fields: {}, isArchive: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetCollection = collections[0];
|
||||||
|
|
||||||
|
for (const attr of attributes) {
|
||||||
|
const key = attr.key.trim();
|
||||||
|
|
||||||
|
if (!targetCollection.fields.has(key)) {
|
||||||
|
(targetCollection.fields as Map<string, any>).set(key, {
|
||||||
|
type: attr.type,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
existingCollection.collections = collections;
|
||||||
|
await existingCollection.save();
|
||||||
|
for (const [key, field] of targetCollection.fields.entries()) {
|
||||||
|
if (field.type === "object") {
|
||||||
|
const existingsubcollection = await dummyModel(organization).findOne({
|
||||||
|
projectId,
|
||||||
|
parentCollectionNodeId: collectionNodeId,
|
||||||
|
attributeparentId: (field as any)._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingsubcollection) {
|
||||||
|
const newCollection = await dummyModel(organization).create({
|
||||||
|
isArchive: false,
|
||||||
|
projectId,
|
||||||
|
collectionName: key,
|
||||||
|
parentCollectionNodeId: collectionNodeId,
|
||||||
|
attributeparentId: (field as any)._id,
|
||||||
|
attributes: [],
|
||||||
|
position: [0, 0, 0],
|
||||||
|
});
|
||||||
|
|
||||||
|
existingCollection.isSubCollection = true;
|
||||||
|
await existingCollection.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return { status: error.message };
|
||||||
|
}
|
||||||
|
return { status: "An unexpected error occurred" };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// export const GetNodesInProject = async (
|
||||||
|
// data: IcollectionNodes
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const { organization, userId, projectId } = data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const collectionNodes = await collectionsModel(organization)
|
||||||
|
// .find({ projectId: projectId, isArchive: false })
|
||||||
|
// .select("collectionName attributes position -_id ");
|
||||||
|
// if (!collectionNodes)
|
||||||
|
// return { status: "No collection Nodes present", data: [] };
|
||||||
|
// else {
|
||||||
|
// const formattedCollections = collectionNodes.map((collection) => ({
|
||||||
|
// position: collection.position,
|
||||||
|
// collectionName: collection.collectionName,
|
||||||
|
// attributes: collection.attributes
|
||||||
|
// .filter((attr: any) => !attr.isArchive)
|
||||||
|
// .map((attr: any) => {
|
||||||
|
// const { isArchive, ...rest } = attr.toObject();
|
||||||
|
// return { ...rest };
|
||||||
|
// }),
|
||||||
|
// }));
|
||||||
|
// return { status: "Success", data: formattedCollections };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const UpdateAttributes = async (
|
||||||
|
// data: IAttributesEdit
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const {
|
||||||
|
// organization,
|
||||||
|
// userId,
|
||||||
|
// projectId,
|
||||||
|
// collectionNodeId,
|
||||||
|
// attributeId,
|
||||||
|
// required,
|
||||||
|
// defaultValue,
|
||||||
|
// unique,
|
||||||
|
// index,
|
||||||
|
// key,
|
||||||
|
// type,
|
||||||
|
// } = data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
// projectId: projectId,
|
||||||
|
// _id: collectionNodeId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingCollection) return { status: "Collection not found" };
|
||||||
|
|
||||||
|
// const editCollection = await collectionsModel(
|
||||||
|
// organization
|
||||||
|
// ).findOneAndUpdate(
|
||||||
|
// {
|
||||||
|
// projectId: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// attributes: {
|
||||||
|
// $elemMatch: { _id: new mongoose.Types.ObjectId(attributeId) },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// $set: {
|
||||||
|
// "attributes.$.required": required,
|
||||||
|
// "attributes.$.default": defaultValue,
|
||||||
|
// "attributes.$.index": index,
|
||||||
|
// "attributes.$.unique": unique,
|
||||||
|
// "attributes.$.key": key,
|
||||||
|
// "attributes.$.type": type,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// { new: true }
|
||||||
|
// );
|
||||||
|
// return { status: "Success" };
|
||||||
|
// }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const DelAttributes = async (
|
||||||
|
// data: IAttributesDel
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const { organization, userId, projectId, collectionNodeId, AttributeId } =
|
||||||
|
// data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
// projectId: projectId,
|
||||||
|
// _id: collectionNodeId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingCollection) return { status: "Collection not found" };
|
||||||
|
|
||||||
|
// const softDeleteAttribute = await collectionsModel(
|
||||||
|
// organization
|
||||||
|
// ).findOneAndUpdate(
|
||||||
|
// {
|
||||||
|
// projectId: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// attributes: {
|
||||||
|
// $elemMatch: {
|
||||||
|
// _id: new mongoose.Types.ObjectId(AttributeId),
|
||||||
|
// isArchive: false,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// $set: {
|
||||||
|
// "attributes.$.isArchive": true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// { new: true }
|
||||||
|
// );
|
||||||
|
// return { status: "Success" };
|
||||||
|
// }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export const delCollection = async (
|
||||||
|
// data: ICollectionDelete
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
// projectId: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// _id: collectionNodeId,
|
||||||
|
// });
|
||||||
|
// if (!existingCollection) {
|
||||||
|
// return { status: "Collection not found" };
|
||||||
|
// }
|
||||||
|
// const collectionSoftDelete = await collectionsModel(
|
||||||
|
// organization
|
||||||
|
// ).findOneAndUpdate(
|
||||||
|
// {
|
||||||
|
// projectId: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// _id: collectionNodeId,
|
||||||
|
// },
|
||||||
|
// { isArchive: true },
|
||||||
|
// { new: true }
|
||||||
|
// );
|
||||||
|
// return { status: "Success" };
|
||||||
|
// }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
export const GetcollectionNodedummy = async (
|
||||||
|
data: IcollectionNodeById
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, userId, projectId, collectionNodeId } = data;
|
||||||
|
try {
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await dummyModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
});
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldsMap = existingCollection.collections[0]?.fields || new Map();
|
||||||
|
console.log("fieldsMap: ", fieldsMap);
|
||||||
|
|
||||||
|
const formattedAttributes: Record<string, any> = {};
|
||||||
|
for (const [key, value] of fieldsMap.entries()) {
|
||||||
|
formattedAttributes[key] = value.type;
|
||||||
|
if (value.type === "object") {
|
||||||
|
const childrenData = await dummyModel(organization).findOne({
|
||||||
|
attributeparentId: (value as any)._id,
|
||||||
|
parentCollectionNodeId: collectionNodeId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!childrenData) {
|
||||||
|
return { status: "subCollection not found" };
|
||||||
|
}
|
||||||
|
const fieldsChildrenMap =
|
||||||
|
childrenData.collections[0]?.fields || new Map();
|
||||||
|
const formattedChildrenAttributes: Record<string, any> = {};
|
||||||
|
for (const [childkey, childvalue] of fieldsChildrenMap.entries()) {
|
||||||
|
formattedChildrenAttributes[childkey] = childvalue.type;
|
||||||
|
}
|
||||||
|
formattedAttributes[key] = formattedChildrenAttributes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const formattedCollection = {
|
||||||
|
position: existingCollection.position,
|
||||||
|
collectionName: existingCollection.collectionName,
|
||||||
|
collections: formattedAttributes,
|
||||||
|
};
|
||||||
|
return { status: "Success", data: formattedCollection };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const collectionKeyRenamedummy = async (
|
||||||
|
data: IcollectionNodeRenameKey
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
collectionNodeId,
|
||||||
|
oldKeyName,
|
||||||
|
newKeyName,
|
||||||
|
} = data;
|
||||||
|
try {
|
||||||
|
const existingProject = await await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
} else {
|
||||||
|
const existingCollection = await dummyModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
_id: collectionNodeId,
|
||||||
|
});
|
||||||
|
if (!existingCollection) {
|
||||||
|
return { status: "Collection not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldsMap = existingCollection.collections[0]?.fields || new Map();
|
||||||
|
console.log("fieldsMap: ", fieldsMap);
|
||||||
|
|
||||||
|
if (!fieldsMap.has(oldKeyName)) {
|
||||||
|
return { status: `Key "${oldKeyName}" not found` };
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldValue = fieldsMap.get(oldKeyName);
|
||||||
|
|
||||||
|
if (fieldValue) {
|
||||||
|
fieldsMap.delete(oldKeyName);
|
||||||
|
fieldsMap.set(newKeyName, fieldValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
existingCollection.collections[0].fields = fieldsMap;
|
||||||
|
await existingCollection.save();
|
||||||
|
}
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// const generateUniqueCollectionName = async (
|
||||||
|
// baseName: string,
|
||||||
|
// organization: string,
|
||||||
|
// projectId: string
|
||||||
|
// ): Promise<string> => {
|
||||||
|
// let nameToTry = baseName;
|
||||||
|
// let attempt = 0;
|
||||||
|
|
||||||
|
// while (true) {
|
||||||
|
// const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
// projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// collectionName: nameToTry,
|
||||||
|
// });
|
||||||
|
// if (!existingCollection) {
|
||||||
|
// return nameToTry;
|
||||||
|
// }
|
||||||
|
// attempt++;
|
||||||
|
// nameToTry = `${baseName} (duplicate${attempt > 1 ? ` ${attempt}` : ""})`;
|
||||||
|
|
||||||
|
// if (attempt > 10) {
|
||||||
|
// throw new Error("Too many duplicate project name attempts");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// export const DuplicateCollection = async (
|
||||||
|
// data: IDuplicateCollectionNode
|
||||||
|
// ): Promise<Iresponse> => {
|
||||||
|
// const { organization, userId, projectId, position, collectionNodeId } = data;
|
||||||
|
// try {
|
||||||
|
// const existingProject = await ProjectType(organization).findOne({
|
||||||
|
// _id: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
// if (!existingProject) {
|
||||||
|
// return { status: "project not found" };
|
||||||
|
// } else {
|
||||||
|
// const existingCollection = await collectionsModel(organization).findOne({
|
||||||
|
// projectId: projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// _id: collectionNodeId,
|
||||||
|
// });
|
||||||
|
// if (!existingCollection)
|
||||||
|
// return { status: "CollectionId not found for duplication" };
|
||||||
|
// else {
|
||||||
|
// const NewduplicateName = await generateUniqueCollectionName(
|
||||||
|
// existingCollection.collectionName,
|
||||||
|
// organization,
|
||||||
|
// projectId
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const NewCollectionDuplicate = await collectionsModel(
|
||||||
|
// organization
|
||||||
|
// ).create({
|
||||||
|
// projectId,
|
||||||
|
// isArchive: false,
|
||||||
|
// position,
|
||||||
|
// collectionName: NewduplicateName,
|
||||||
|
// });
|
||||||
|
// if (!NewCollectionDuplicate)
|
||||||
|
// return { status: "Duplication unsuccessfull" };
|
||||||
|
// else {
|
||||||
|
// const data = existingCollection.attributes
|
||||||
|
// .filter((attr: any) => !attr.isArchive)
|
||||||
|
// .map((attr: any) => {
|
||||||
|
// const { isArchive, _id, ...rest } = attr.toObject();
|
||||||
|
// return rest;
|
||||||
|
// });
|
||||||
|
// NewCollectionDuplicate.attributes = data;
|
||||||
|
// NewCollectionDuplicate.save();
|
||||||
|
// return { status: "Success" };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (error: unknown) {
|
||||||
|
// if (error instanceof Error) {
|
||||||
|
// return {
|
||||||
|
// status: error.message,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// return {
|
||||||
|
// status: "An unexpected error occurred",
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// };
|
||||||
@@ -1,293 +1,299 @@
|
|||||||
import ProjectType from "../../shared/model/projectmodel";
|
import ProjectType from "../../shared/model/projectmodel";
|
||||||
import collectionsModel from "../model/collectionModel";
|
import collectionsModel from "../model/collectionModel";
|
||||||
import edgeModel from "../model/edgeModel";
|
import edgeModel from "../model/edgeModel";
|
||||||
|
import userModel from "../model/userModel";
|
||||||
interface Iresponse {
|
interface Iresponse {
|
||||||
status: string;
|
status: string;
|
||||||
data?: any;
|
data?: any;
|
||||||
}
|
}
|
||||||
interface IEdge {
|
interface IEdge {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
userId: string;
|
||||||
from: { collection_id: string, field: string };
|
projectId: string;
|
||||||
to: { collection_id: string };
|
from: { collection_id: string; field: string };
|
||||||
cardinality: string
|
to: { collection_id: string };
|
||||||
|
cardinality: string;
|
||||||
}
|
}
|
||||||
interface IAllEdge {
|
interface IAllEdge {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IEdgeDelete {
|
interface IEdgeDelete {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
edgeId: string;
|
userId: string;
|
||||||
|
edgeId: string;
|
||||||
}
|
}
|
||||||
interface Attribute {
|
interface Attribute {
|
||||||
key: string;
|
key: string;
|
||||||
type: string;
|
type: string;
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
|
||||||
refKey?: {
|
refKey?: {
|
||||||
collection_id: any;
|
collection_id: any;
|
||||||
fieldId: any;
|
fieldId: any;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
|
||||||
|
const { organization, projectId, from, to, cardinality, userId } = data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
// createdBy: userName,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingFromCollection = await collectionsModel(organization).findOne(
|
||||||
|
{
|
||||||
|
_id: from.collection_id,
|
||||||
|
isArchive: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!existingFromCollection) {
|
||||||
|
return { status: "From collection not found" };
|
||||||
|
}
|
||||||
|
const existingToCollection = await collectionsModel(organization).findOne({
|
||||||
|
_id: to.collection_id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingToCollection) {
|
||||||
|
return { status: "To collection not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const capitalizeFirst = (str: string) => {
|
||||||
|
if (!str) return str;
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
const collectionName = existingFromCollection.collectionName;
|
||||||
export const edgecreation = async (
|
const fieldName = from.field;
|
||||||
data: IEdge
|
|
||||||
): Promise<Iresponse> => {
|
|
||||||
const { organization, projectId, from, to, cardinality } = data;
|
|
||||||
|
|
||||||
try {
|
const newFieldKey = `${collectionName}_${capitalizeFirst(fieldName)}`;
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
|
||||||
_id: projectId,
|
|
||||||
// createdBy: userName,
|
|
||||||
isArchive: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!existingProject) {
|
const fromField = existingFromCollection.attributes.find(
|
||||||
return { status: "project not found" };
|
(attr: any) => attr.key === from.field
|
||||||
}
|
);
|
||||||
|
const fromFieldId = [fromField].map((attr: any) => attr?._id)[0];
|
||||||
|
|
||||||
const existingFromCollection = await collectionsModel(organization).findOne({
|
const fieldType = normalizeType(fromField?.type);
|
||||||
_id: from.collection_id,isArchive: false,
|
|
||||||
|
const fieldExists = existingToCollection.attributes.some(
|
||||||
|
(attr: any) => attr.key === newFieldKey
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!fieldExists) {
|
||||||
|
const newAttribute: any = {
|
||||||
|
key: newFieldKey,
|
||||||
|
type: fieldType,
|
||||||
|
refKey: {
|
||||||
|
collection_id: existingFromCollection._id,
|
||||||
|
fieldId: fromFieldId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
existingToCollection.attributes.push(newAttribute);
|
||||||
|
|
||||||
|
existingToCollection.attributes = existingToCollection.attributes.map(
|
||||||
|
(attr: any) => ({
|
||||||
|
...attr,
|
||||||
|
type: normalizeType(attr.type),
|
||||||
})
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (!existingFromCollection) {
|
await existingToCollection.save();
|
||||||
return { status: "From collection not found" };
|
|
||||||
}
|
|
||||||
const existingToCollection = await collectionsModel(organization).findOne({
|
|
||||||
_id: to.collection_id,isArchive: false
|
|
||||||
})
|
|
||||||
if (!existingToCollection) {
|
|
||||||
return { status: "To collection not found" };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
|
||||||
|
);
|
||||||
|
const newEdge = {
|
||||||
|
projectId,
|
||||||
|
from: { collection_id: existingFromCollection._id, field: from.field },
|
||||||
|
to: { collection_id: existingToCollection._id },
|
||||||
|
cardinality,
|
||||||
|
createdAt: new Date(),
|
||||||
|
};
|
||||||
|
const savedEdge = await edgeModel(organization).create(newEdge);
|
||||||
|
|
||||||
const capitalizeFirst = (str: string) => {
|
return {
|
||||||
if (!str) return str;
|
status: "Success",
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
data: savedEdge,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
const collectionName = existingFromCollection.collectionNodeName;
|
console.log("Field already exists");
|
||||||
const fieldName = from.field;
|
return {
|
||||||
|
status: "Field already exists",
|
||||||
const newFieldKey = `${collectionName}${capitalizeFirst(fieldName)}`;
|
};
|
||||||
|
|
||||||
const fromField = existingFromCollection.attributes.find(
|
|
||||||
(attr: any) => attr.key === from.field
|
|
||||||
);
|
|
||||||
const fromFieldId = [fromField].map((attr: any) => attr?._id)[0];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const fieldType = normalizeType(fromField?.type);
|
|
||||||
|
|
||||||
|
|
||||||
const fieldExists = existingToCollection.attributes.some(
|
|
||||||
(attr: any) => attr.key === newFieldKey
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!fieldExists) {
|
|
||||||
const newAttribute: any = {
|
|
||||||
key: newFieldKey,
|
|
||||||
type: fieldType,
|
|
||||||
refKey: {
|
|
||||||
collection_id: existingFromCollection._id,
|
|
||||||
fieldId: fromFieldId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
existingToCollection.attributes.push(newAttribute);
|
|
||||||
|
|
||||||
existingToCollection.attributes = existingToCollection.attributes.map((attr: any) => ({
|
|
||||||
...attr,
|
|
||||||
type: normalizeType(attr.type),
|
|
||||||
}));
|
|
||||||
|
|
||||||
await existingToCollection.save();
|
|
||||||
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
|
|
||||||
);
|
|
||||||
const newEdge = {
|
|
||||||
projectId,
|
|
||||||
from: { collection_id: existingFromCollection._id, field: from.field },
|
|
||||||
to: { collection_id: existingToCollection._id },
|
|
||||||
cardinality,
|
|
||||||
createdAt: new Date(),
|
|
||||||
};
|
|
||||||
const savedEdge = await edgeModel(organization).create(newEdge);
|
|
||||||
|
|
||||||
//
|
|
||||||
return {
|
|
||||||
status: "Success",
|
|
||||||
data: savedEdge, // replace with savedEdge after model integration
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log("Field already exists");
|
|
||||||
return {
|
|
||||||
status: "Field already exists"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.log('error: ', error);
|
console.log("error: ", error);
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
return {
|
return {
|
||||||
status: error.message,
|
status: error.message,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
status: "An unexpected error occurred",
|
status: "An unexpected error occurred",
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Alledges = async (
|
export const Alledges = async (data: IAllEdge): Promise<Iresponse> => {
|
||||||
data: IAllEdge
|
const { organization, projectId, userId } = data;
|
||||||
): Promise<Iresponse> => {
|
try {
|
||||||
const { organization, projectId, } = data;
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
try {
|
_id: userId,
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
isArchive: false,
|
||||||
_id: projectId,
|
});
|
||||||
// createdBy: userName,
|
|
||||||
isArchive: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!existingProject) {
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
return { status: "project not found" };
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
}
|
_id: projectId,
|
||||||
const edgeDatas = await edgeModel(organization).find({isArchive: false})
|
// createdBy: userName,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingProject) {
|
||||||
if (!edgeDatas || edgeDatas.length === 0) {
|
return { status: "project not found" };
|
||||||
return { status: "edge not found" };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: "Success",
|
|
||||||
data: edgeDatas, // replace with savedEdge after model integration
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error: unknown) {
|
|
||||||
console.log('error: ', error);
|
|
||||||
if (error instanceof Error) {
|
|
||||||
return {
|
|
||||||
status: error.message,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: "An unexpected error occurred",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const edgeDatas = await edgeModel(organization).find({ isArchive: false });
|
||||||
|
|
||||||
|
if (!edgeDatas || edgeDatas.length === 0) {
|
||||||
|
return { status: "edge not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: edgeDatas, // replace with savedEdge after model integration
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
export const deleteEdge = async (
|
export const deleteEdge = async (data: IEdgeDelete): Promise<Iresponse> => {
|
||||||
data: IEdgeDelete
|
const { organization, projectId, edgeId, userId } = data;
|
||||||
): Promise<Iresponse> => {
|
|
||||||
const { organization, projectId, edgeId } = data;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
_id: projectId,
|
_id: userId,
|
||||||
// createdBy: userName,
|
isArchive: false,
|
||||||
isArchive: false,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!existingProject) {
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
return { status: "project not found" };
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
}
|
_id: projectId,
|
||||||
|
// createdBy: userName,
|
||||||
const deleteEdge = await edgeModel(organization).findOneAndUpdate
|
isArchive: false,
|
||||||
({ _id: edgeId, isArchive: false }, {
|
});
|
||||||
isArchive: true
|
|
||||||
}, { new: true })
|
|
||||||
if (!deleteEdge) return { status: "Edge not found" }
|
|
||||||
const collectionDoc = await collectionsModel(organization).findOne({
|
|
||||||
_id: deleteEdge?.to?.collection_id, isArchive: false
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!collectionDoc ) {
|
if (!existingProject) {
|
||||||
return { status: "collection not found" };
|
return { status: "project not found" };
|
||||||
}
|
|
||||||
else {
|
|
||||||
const attributes = collectionDoc.attributes || [];
|
|
||||||
const matchedAttr = attributes.find((attr, index) => {
|
|
||||||
const refKey: any = (attr as any).refKey;
|
|
||||||
if (refKey) {
|
|
||||||
return String(refKey.collection_id) === String(deleteEdge?.from?.collection_id);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
if (matchedAttr) {
|
|
||||||
const index = attributes.indexOf(matchedAttr);
|
|
||||||
if (index > -1) {
|
|
||||||
attributes.splice(index, 1);
|
|
||||||
await collectionDoc.save();
|
|
||||||
console.log(`Attribute at index ${index} deleted successfully.`)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('Matched attribute not found in array');
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// console.log('No attribute matches the given collection_id');
|
|
||||||
return { status: "No deleted in matched Document" }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return {status:"Success"}
|
|
||||||
|
|
||||||
} catch (error: unknown) {
|
|
||||||
console.log('error: ', error);
|
|
||||||
if (error instanceof Error) {
|
|
||||||
return {
|
|
||||||
status: error.message,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
status: "An unexpected error occurred",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteEdge = await edgeModel(organization).findOneAndUpdate(
|
||||||
|
{ _id: edgeId, isArchive: false },
|
||||||
|
{
|
||||||
|
isArchive: true,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!deleteEdge) return { status: "Edge not found" };
|
||||||
|
const collectionDoc = await collectionsModel(organization).findOne({
|
||||||
|
_id: deleteEdge?.to?.collection_id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!collectionDoc) {
|
||||||
|
return { status: "collection not found" };
|
||||||
|
} else {
|
||||||
|
const attributes = collectionDoc.attributes || [];
|
||||||
|
const matchedAttr = attributes.find((attr, index) => {
|
||||||
|
const refKey: any = (attr as any).refKey;
|
||||||
|
if (refKey) {
|
||||||
|
return (
|
||||||
|
String(refKey.collection_id) ===
|
||||||
|
String(deleteEdge?.from?.collection_id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (matchedAttr) {
|
||||||
|
const index = attributes.indexOf(matchedAttr);
|
||||||
|
if (index > -1) {
|
||||||
|
attributes.splice(index, 1);
|
||||||
|
await collectionDoc.save();
|
||||||
|
console.log(`Attribute at index ${index} deleted successfully.`);
|
||||||
|
} else {
|
||||||
|
console.log("Matched attribute not found in array");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// console.log('No attribute matches the given collection_id');
|
||||||
|
return { status: "No deleted in matched Document" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const normalizeType = (type: any): string => {
|
const normalizeType = (type: any): string => {
|
||||||
if (!type) return "string"; // default
|
if (!type) return "string"; // default
|
||||||
if (typeof type === "string") {
|
if (typeof type === "string") {
|
||||||
switch (type.toLowerCase()) {
|
switch (type.toLowerCase()) {
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return "boolean";
|
return "boolean";
|
||||||
case "number":
|
case "number":
|
||||||
return "number";
|
return "number";
|
||||||
case "string":
|
case "string":
|
||||||
return "string";
|
return "string";
|
||||||
case "object":
|
case "object":
|
||||||
return "object";
|
return "object";
|
||||||
case "array":
|
case "array":
|
||||||
return "array";
|
return "array";
|
||||||
case "date":
|
case "date":
|
||||||
return "date";
|
return "date";
|
||||||
default:
|
default:
|
||||||
return "string";
|
return "string";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle cases like [Number], Boolean, Object
|
// Handle cases like [Number], Boolean, Object
|
||||||
if (Array.isArray(type)) return "array";
|
if (Array.isArray(type)) return "array";
|
||||||
if (type === Boolean) return "boolean";
|
if (type === Boolean) return "boolean";
|
||||||
if (type === Number) return "number";
|
if (type === Number) return "number";
|
||||||
if (type === String) return "string";
|
if (type === String) return "string";
|
||||||
if (type === Object) return "object";
|
if (type === Object) return "object";
|
||||||
|
|
||||||
return "string"; // fallback
|
return "string"; // fallback
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ interface IrecentlyViewed {
|
|||||||
organization: string;
|
organization: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
interface IuserDetails {
|
||||||
|
organization: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
interface Iresponse {
|
interface Iresponse {
|
||||||
status: string;
|
status: string;
|
||||||
data?: any;
|
data?: any;
|
||||||
@@ -49,3 +53,36 @@ export const recentlyViewedServices = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const homeuserProfileServices = async (
|
||||||
|
data: IuserDetails
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
const { organization, userId } = data;
|
||||||
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const profileData = await userDataModel(organization)
|
||||||
|
.findOne({ userId: userId, isArchive: false })
|
||||||
|
.select("-_id");
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
else {
|
||||||
|
const DestructureData = {
|
||||||
|
Email: ExistingUser.email,
|
||||||
|
userName: ExistingUser.userName,
|
||||||
|
profile: profileData || ExistingUser.userName.charAt(0),
|
||||||
|
};
|
||||||
|
return { status: "Success", data: DestructureData };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { skip } from "node:test";
|
||||||
import MVCarcModel from "../../shared/model/mvcModel";
|
import MVCarcModel from "../../shared/model/mvcModel";
|
||||||
import ProjectType from "../../shared/model/projectmodel";
|
import ProjectType from "../../shared/model/projectmodel";
|
||||||
import collectionsModel from "../model/collectionModel";
|
import collectionsModel from "../model/collectionModel";
|
||||||
@@ -5,16 +6,17 @@ import edgeModel from "../model/edgeModel";
|
|||||||
import shareModel from "../model/shareModel";
|
import shareModel from "../model/shareModel";
|
||||||
import userDataModel from "../model/userDataModel";
|
import userDataModel from "../model/userDataModel";
|
||||||
import userModel from "../model/userModel";
|
import userModel from "../model/userModel";
|
||||||
|
import versionModel from "../model/versionModel";
|
||||||
interface Iresponse {
|
interface Iresponse {
|
||||||
status: string;
|
status: string;
|
||||||
data?: any;
|
data?: any;
|
||||||
}
|
}
|
||||||
interface IProject {
|
interface IProject {
|
||||||
useableLanguage: string;
|
language: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
apiType: string;
|
apiProtocol: string;
|
||||||
application: string;
|
application: string;
|
||||||
architecture: string;
|
architecture: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -26,24 +28,50 @@ interface IProjectView {
|
|||||||
}
|
}
|
||||||
interface IProjectstructure {
|
interface IProjectstructure {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IgetProject {
|
interface IgetProject {
|
||||||
organization: string;
|
organization: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
skipdata: number;
|
||||||
|
limitdata: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ProjectUpdate {
|
||||||
|
language: string;
|
||||||
|
organization: string;
|
||||||
|
projectName: string;
|
||||||
|
userId: string;
|
||||||
|
projectId: string;
|
||||||
|
application: string;
|
||||||
|
architecture: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const previousVersion = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string
|
||||||
|
) => {
|
||||||
|
const result = await versionModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const projectCreationService = async (
|
export const projectCreationService = async (
|
||||||
data: IProject
|
data: IProject
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const {
|
const {
|
||||||
organization,
|
organization,
|
||||||
projectName,
|
projectName,
|
||||||
useableLanguage,
|
language,
|
||||||
description,
|
description,
|
||||||
userId,
|
userId,
|
||||||
apiType,
|
apiProtocol,
|
||||||
application,
|
application,
|
||||||
architecture,
|
architecture,
|
||||||
} = data;
|
} = data;
|
||||||
@@ -60,14 +88,14 @@ export const projectCreationService = async (
|
|||||||
if (existingProject) {
|
if (existingProject) {
|
||||||
return { status: "Project Already Exists" };
|
return { status: "Project Already Exists" };
|
||||||
} else {
|
} else {
|
||||||
if (architecture.toLowerCase() === "mvc") {
|
if (architecture.toUpperCase() === "MVC") {
|
||||||
const newProject = await ProjectType(organization).create({
|
const newProject = await ProjectType(organization).create({
|
||||||
projectName,
|
projectName,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
useableLanguage,
|
language,
|
||||||
architecture,
|
architecture,
|
||||||
apiType: apiType,
|
apiProtocol: apiProtocol,
|
||||||
appType: application,
|
application: application,
|
||||||
description,
|
description,
|
||||||
});
|
});
|
||||||
if (!newProject) return { status: "Project creation unsuccessfull" };
|
if (!newProject) return { status: "Project creation unsuccessfull" };
|
||||||
@@ -107,6 +135,34 @@ export const projectCreationService = async (
|
|||||||
|
|
||||||
MVCCreation.folders.push(...createdFolders);
|
MVCCreation.folders.push(...createdFolders);
|
||||||
await MVCCreation.save();
|
await MVCCreation.save();
|
||||||
|
const versionData = await previousVersion(
|
||||||
|
newProject._id,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
|
||||||
|
const versionNameDesc = new Date().toLocaleString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
|
if (!versionData || versionData.length === 0) {
|
||||||
|
const newVersion = await versionModel(organization).create({
|
||||||
|
projectId: newProject._id,
|
||||||
|
createdBy: userId,
|
||||||
|
version: 0.1,
|
||||||
|
versionName: versionNameDesc,
|
||||||
|
description: versionNameDesc,
|
||||||
|
});
|
||||||
|
await ProjectType(organization).findByIdAndUpdate(
|
||||||
|
{ _id: newProject._id, isArchive: false },
|
||||||
|
{
|
||||||
|
total_versions: `v-${newVersion.version.toFixed(1)}`,
|
||||||
|
Present_version: newVersion._id,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
return { status: "Success", data: newProject._id };
|
return { status: "Success", data: newProject._id };
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -114,7 +170,17 @@ export const projectCreationService = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return { status: "New architecture" };
|
const newProject = await ProjectType(organization).create({
|
||||||
|
projectName,
|
||||||
|
createdBy: userId,
|
||||||
|
language,
|
||||||
|
architecture,
|
||||||
|
apiProtocol: apiProtocol,
|
||||||
|
application: application,
|
||||||
|
description,
|
||||||
|
});
|
||||||
|
if (!newProject) return { status: "Project creation unsuccessfull" };
|
||||||
|
return { status: "Success", data: newProject._id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -131,7 +197,7 @@ export const projectCreationService = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
|
export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
|
||||||
const { organization, userId } = data;
|
const { organization, userId, limitdata, skipdata } = data;
|
||||||
try {
|
try {
|
||||||
const ExistingUser = await userModel(organization).findOne({
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
_id: userId,
|
_id: userId,
|
||||||
@@ -151,10 +217,16 @@ export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
|
|||||||
} else {
|
} else {
|
||||||
query;
|
query;
|
||||||
}
|
}
|
||||||
console.log("query: ", query);
|
|
||||||
const projectDatas = await ProjectType(organization)
|
const projectDatas = await ProjectType(organization)
|
||||||
.find(query)
|
.find(query)
|
||||||
.select("-__v -isArchive -createdAt -updatedAt");
|
.select("projectName createdBy thumbnail")
|
||||||
|
.populate({
|
||||||
|
path: "createdBy",
|
||||||
|
model: userModel(organization),
|
||||||
|
select: "userName",
|
||||||
|
})
|
||||||
|
.skip(skipdata)
|
||||||
|
.limit(limitdata);
|
||||||
if (!projectDatas) return { status: "No project found" };
|
if (!projectDatas) return { status: "No project found" };
|
||||||
return { status: "Success", data: projectDatas };
|
return { status: "Success", data: projectDatas };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -173,8 +245,15 @@ export const projectDatas = async (data: IgetProject): Promise<Iresponse> => {
|
|||||||
export const GetNodesInProject = async (
|
export const GetNodesInProject = async (
|
||||||
data: IProjectstructure
|
data: IProjectstructure
|
||||||
): Promise<Iresponse> => {
|
): Promise<Iresponse> => {
|
||||||
const { organization, projectId } = data;
|
const { organization, projectId, userId } = data;
|
||||||
try {
|
try {
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!ExistingUser) {
|
||||||
|
return { status: "User not found" };
|
||||||
|
}
|
||||||
const existingProject = await ProjectType(organization).findOne({
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
_id: projectId,
|
_id: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -184,7 +263,7 @@ export const GetNodesInProject = async (
|
|||||||
} else {
|
} else {
|
||||||
const collectionNodesdata = await collectionsModel(organization)
|
const collectionNodesdata = await collectionsModel(organization)
|
||||||
.find({ projectId: projectId, isArchive: false })
|
.find({ projectId: projectId, isArchive: false })
|
||||||
.select("collectionNodeName attributes position -_id ");
|
.select("collectionName attributes position -_id ");
|
||||||
const edgeNodes = await edgeModel(organization)
|
const edgeNodes = await edgeModel(organization)
|
||||||
.find({ projectId: projectId, isArchive: false })
|
.find({ projectId: projectId, isArchive: false })
|
||||||
.select("cardinality from to");
|
.select("cardinality from to");
|
||||||
@@ -194,7 +273,7 @@ export const GetNodesInProject = async (
|
|||||||
else {
|
else {
|
||||||
const collectionNodes = collectionNodesdata.map((collection) => ({
|
const collectionNodes = collectionNodesdata.map((collection) => ({
|
||||||
position: collection.position,
|
position: collection.position,
|
||||||
collectionNodeName: collection.collectionNodeName,
|
collectionName: collection.collectionName,
|
||||||
attributes: collection.attributes
|
attributes: collection.attributes
|
||||||
.filter((attr: any) => !attr.isArchive)
|
.filter((attr: any) => !attr.isArchive)
|
||||||
.map((attr: any) => {
|
.map((attr: any) => {
|
||||||
@@ -254,7 +333,6 @@ export const ViewProjectService = async (
|
|||||||
select: "userName",
|
select: "userName",
|
||||||
})
|
})
|
||||||
.select("_id projectName createdBy");
|
.select("_id projectName createdBy");
|
||||||
console.log("projectData: ", projectData);
|
|
||||||
if (projectData === null) {
|
if (projectData === null) {
|
||||||
return { status: "Datas not found" };
|
return { status: "Datas not found" };
|
||||||
}
|
}
|
||||||
@@ -325,7 +403,68 @@ export const DeleteProject = async (data: IProjectView): Promise<Iresponse> => {
|
|||||||
{ isArchive: true },
|
{ isArchive: true },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
if(!deleteProject) return {status:"Project Delete unsuccessfull"}
|
if (!deleteProject) return { status: "Project Delete unsuccessfull" };
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const projectModification = async (
|
||||||
|
data: ProjectUpdate
|
||||||
|
): Promise<Iresponse> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectName,
|
||||||
|
application,
|
||||||
|
description,
|
||||||
|
language,
|
||||||
|
architecture,
|
||||||
|
} = data;
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
let query: any = {
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
};
|
||||||
|
const existingProject = await ProjectType(organization).findOne(query);
|
||||||
|
if (!existingProject) return { status: "Project not found" };
|
||||||
|
|
||||||
|
if (ExistingUser.role === "Editor") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
$or: [{ createdBy: userId }, { members: userId }],
|
||||||
|
};
|
||||||
|
} else if (ExistingUser.role === "Viewer") {
|
||||||
|
query = {
|
||||||
|
...query,
|
||||||
|
members: userId,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
query;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateProject = await ProjectType(organization).findOneAndUpdate(
|
||||||
|
query,
|
||||||
|
{ projectName, application, description, language, architecture },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!updateProject) return { status: "Project updated unsuccessfull" };
|
||||||
return { status: "Success" };
|
return { status: "Success" };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
|||||||
428
src/shared/services/versionService.ts
Normal file
428
src/shared/services/versionService.ts
Normal file
@@ -0,0 +1,428 @@
|
|||||||
|
|
||||||
|
import collectionsModel ,{ICollectionNode} from "../model/collectionModel";
|
||||||
|
import edgeModel ,{IEdgeModel}from "../model/edgeModel";
|
||||||
|
import ProjectType from "../model/projectmodel";
|
||||||
|
import userDataModel from "../model/userDataModel";
|
||||||
|
import userModel from "../model/userModel";
|
||||||
|
import versionModel from "../model/versionModel";
|
||||||
|
import { existingProjectById, existingUser } from "../utils/functionality";
|
||||||
|
type VersionData = {
|
||||||
|
Project: {
|
||||||
|
edges: IEdgeModel[];
|
||||||
|
collectionNode: ICollectionNode[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
interface IVersionSave {
|
||||||
|
organization: string;
|
||||||
|
hierarchyVersion: string;
|
||||||
|
versionName: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
createdBy: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
interface IVersionRollback {
|
||||||
|
organization: string;
|
||||||
|
versionId: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IVersionHistory {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
page: number;
|
||||||
|
limit: number;
|
||||||
|
sortBy?: string;
|
||||||
|
sortOrder?: string;
|
||||||
|
}
|
||||||
|
interface IVersionUpdate {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
page: number;
|
||||||
|
versionId: string;
|
||||||
|
versionName?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
interface IVersionById {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
export const CreateVersion = async (data: IVersionSave): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
hierarchyVersion,
|
||||||
|
projectId,
|
||||||
|
versionName,
|
||||||
|
description,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
createdBy,
|
||||||
|
} = data;
|
||||||
|
const ExistingUser = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
|
const existingProject = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!existingProject) {
|
||||||
|
return { status: "project not found" };
|
||||||
|
}
|
||||||
|
const versionData = await versionModel(organization).findOne({
|
||||||
|
_id: hierarchyVersion,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!versionData) return { status: "Parent Version not found" };
|
||||||
|
const versionDataprevious = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.sort({ version: -1 });
|
||||||
|
const currentVersion = versionDataprevious?.version ?? 0;
|
||||||
|
const newVersion = parseFloat((currentVersion + 0.1).toFixed(2));
|
||||||
|
const saveVersion = await versionModel(organization).create({
|
||||||
|
versionName: versionName,
|
||||||
|
parentVersionID: versionData._id,
|
||||||
|
projectId: projectId,
|
||||||
|
description: description,
|
||||||
|
createdBy: createdBy,
|
||||||
|
previous_Version: currentVersion,
|
||||||
|
version: newVersion,
|
||||||
|
createdAt: new Date(),
|
||||||
|
});
|
||||||
|
const find_User = await userDataModel(organization).findById({
|
||||||
|
_id: saveVersion.createdBy,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const responseVersionData = {
|
||||||
|
versionId: saveVersion._id,
|
||||||
|
version: saveVersion.version,
|
||||||
|
description: saveVersion.description,
|
||||||
|
versionName: saveVersion.versionName,
|
||||||
|
createdAt: saveVersion.createdAt,
|
||||||
|
createdBy: {
|
||||||
|
userId: find_User._id,
|
||||||
|
userName: find_User.userName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await existingProject.updateOne({
|
||||||
|
Present_version: saveVersion._id,
|
||||||
|
total_versions: `v-${saveVersion.version.toFixed(1)}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
await AllCloneFornewVersions(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
saveVersion._id,
|
||||||
|
hierarchyVersion
|
||||||
|
);
|
||||||
|
return { status: "Success", data: responseVersionData };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetVersionById = async (data: IVersionById): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, organization, versionId } = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "User not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingVersion = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
_id: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("version previous_Version");
|
||||||
|
if (!existingVersion) {
|
||||||
|
return { status: "Version not found for the project" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const [collectionNode, edges] =
|
||||||
|
await Promise.all([
|
||||||
|
collectionsModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
edgeModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
const versionData: VersionData = {
|
||||||
|
Project: {
|
||||||
|
collectionNode,
|
||||||
|
edges
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
version: existingVersion,
|
||||||
|
entities: versionData,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RollBackversion = async (
|
||||||
|
data: IVersionRollback
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { versionId, projectId, userId, organization } = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "User not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const rollbackversion = await versionModel(organization).findOne({
|
||||||
|
_id: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!rollbackversion)
|
||||||
|
return { status: "Mentioned Version not found for the Rollback" };
|
||||||
|
const versionDataprevious = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.sort({ version: -1 });
|
||||||
|
const currentVersion = versionDataprevious?.version ?? 0;
|
||||||
|
const newVersion = parseFloat((currentVersion + 0.01).toFixed(2));
|
||||||
|
const saveVersion = await versionModel(organization).create({
|
||||||
|
parentVersionID: rollbackversion._id,
|
||||||
|
projectId: projectId,
|
||||||
|
createdBy: userId,
|
||||||
|
previous_Version: currentVersion,
|
||||||
|
version: newVersion,
|
||||||
|
createdAt: new Date(),
|
||||||
|
rollBackComment: `RollBack from the version ${rollbackversion.version}`,
|
||||||
|
});
|
||||||
|
LivingProject.Present_version = saveVersion._id;
|
||||||
|
LivingProject.total_versions = `v-${saveVersion.version.toFixed(2)}`;
|
||||||
|
await LivingProject.save();
|
||||||
|
|
||||||
|
await AllCloneFornewVersions(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
saveVersion._id,
|
||||||
|
rollbackversion._id
|
||||||
|
);
|
||||||
|
return { status: "Success", data: saveVersion._id };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const VersionHistory = async (
|
||||||
|
data: IVersionHistory
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId, page, limit, sortOrder } = data;
|
||||||
|
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) return { status: "User not found" };
|
||||||
|
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
|
||||||
|
const filter: object = { projectId, isArchive: false };
|
||||||
|
const total = await versionModel(organization).countDocuments(filter);
|
||||||
|
const versiondatas = await versionModel(organization)
|
||||||
|
.find(filter)
|
||||||
|
.sort({ ["version"]: sortOrder === "asc" ? 1 : -1 })
|
||||||
|
.skip((page - 1) * limit)
|
||||||
|
.limit(limit)
|
||||||
|
.select("version createdBy createdAt description versionName")
|
||||||
|
.populate({
|
||||||
|
path: "createdBy",
|
||||||
|
model: userDataModel(organization),
|
||||||
|
select: "userName",
|
||||||
|
});
|
||||||
|
// .populate({
|
||||||
|
// path: "createdBy",
|
||||||
|
// model: UsersDataModel(organization),
|
||||||
|
// select: "profilePicture",
|
||||||
|
// });
|
||||||
|
// console.log('versiondatas: ', versiondatas);
|
||||||
|
if (!versiondatas)
|
||||||
|
return {
|
||||||
|
status: "Versions not found",
|
||||||
|
};
|
||||||
|
const versions = versiondatas.map((version) => {
|
||||||
|
return {
|
||||||
|
versionId: version._id,
|
||||||
|
version: version.version,
|
||||||
|
createdAt: version.createdAt,
|
||||||
|
description: version.description,
|
||||||
|
versionName: version.versionName,
|
||||||
|
createdBy: {
|
||||||
|
userId: version.createdBy._id,
|
||||||
|
userName: version.createdBy.userName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
versions,
|
||||||
|
Metadatas: {
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
hasNextPage: page * limit < total,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const updateVersion = async (data: IVersionUpdate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
versionName,
|
||||||
|
description,
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) return { status: "User not found" };
|
||||||
|
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingVersionId = await versionModel(organization).findOne({
|
||||||
|
_id: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingVersionId) {
|
||||||
|
return { status: "VersionId not match" };
|
||||||
|
} else {
|
||||||
|
existingVersionId.versionName = versionName;
|
||||||
|
existingVersionId.description = description;
|
||||||
|
await existingVersionId.save();
|
||||||
|
return { status: "Version Updated successfully" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AllCloneFornewVersions = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string,
|
||||||
|
versionId: string,
|
||||||
|
oldeVersionId: string
|
||||||
|
) => {
|
||||||
|
const cloneDocuments = async (model: any, modelName: string) => {
|
||||||
|
const docs = await model(organization).find({
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: oldeVersionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!docs.length) return;
|
||||||
|
|
||||||
|
const clonedDocs = docs.map((doc: any) => {
|
||||||
|
const { _id, __v, ...rest } = doc.toObject();
|
||||||
|
return { ...rest, versionId };
|
||||||
|
});
|
||||||
|
|
||||||
|
const created = await model(organization).create(clonedDocs);
|
||||||
|
};
|
||||||
|
await Promise.all([
|
||||||
|
cloneDocuments(collectionsModel, "collections"),
|
||||||
|
cloneDocuments(edgeModel, "edges"),
|
||||||
|
]);
|
||||||
|
};
|
||||||
27
src/shared/utils/functionality.ts
Normal file
27
src/shared/utils/functionality.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Types } from "mongoose";
|
||||||
|
import ProjectType from "../model/projectmodel";
|
||||||
|
import userModel from "../model/userModel";
|
||||||
|
|
||||||
|
export const existingUser = async (userId: string, organization: string) => {
|
||||||
|
if (!Types.ObjectId.isValid(userId)) {
|
||||||
|
console.log("Invalid ObjectId format");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const userData = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
return userData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const existingProjectById = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string,
|
||||||
|
userId: string
|
||||||
|
) => {
|
||||||
|
const projectData = await ProjectType(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
return projectData;
|
||||||
|
};
|
||||||
@@ -1,70 +1,74 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import { EVENTS } from "../events/events";
|
import { EVENTS } from "../events/events";
|
||||||
import { ErrorResponse, FinalResponse, validateFields } from "../utils/socketfunctionHelpers";
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../utils/socketfunctionHelpers";
|
||||||
import { emitToSenderAndAdmins } from "../utils/emitEventResponse";
|
import { emitToSenderAndAdmins } from "../utils/emitEventResponse";
|
||||||
import { projectCreationService } from "../../shared/services/projectService";
|
import { projectCreationService } from "../../shared/services/projectService";
|
||||||
|
|
||||||
export const projectHandleEvent = async (
|
export const projectHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: {
|
connectedUsersByOrg: {
|
||||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.projectCreate || !data?.organization) return;
|
if (event !== EVENTS.projectCreate || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"application",
|
"application",
|
||||||
"architecture",
|
"architecture",
|
||||||
"apiType",
|
"apiProtocol",
|
||||||
"projectName",
|
"projectName",
|
||||||
"useableLanguage",
|
"language",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
emitToSenderAndAdmins(
|
|
||||||
io,
|
|
||||||
socket,
|
|
||||||
data.organization,
|
|
||||||
EVENTS.projectCreateResponse,
|
|
||||||
ErrorResponse(missingFields, socket, data.organization),
|
|
||||||
connectedUsersByOrg
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await projectCreationService(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "Project Created Successfully" },
|
|
||||||
"Project Already Exists": { message: "Project Already Exists" },
|
|
||||||
"Already MVC architecture assigned to this projectId": { message: "Already MVC architecture assigned to this projectId" },
|
|
||||||
"Project creation unsuccessfull": {
|
|
||||||
message: "Project creation unsuccessfull",
|
|
||||||
},
|
|
||||||
"New architecture": { message: "New architecture" },
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const result_Datas =
|
|
||||||
status === "Success" && result?.data ? result.data : undefined;
|
|
||||||
const response = FinalResponse(
|
|
||||||
status,
|
|
||||||
socket,
|
|
||||||
data.organization,
|
|
||||||
messages,
|
|
||||||
result_Datas
|
|
||||||
);
|
|
||||||
emitToSenderAndAdmins(
|
emitToSenderAndAdmins(
|
||||||
io,
|
io,
|
||||||
socket,
|
socket,
|
||||||
data.organization,
|
data.organization,
|
||||||
EVENTS.projectCreateResponse,
|
EVENTS.projectCreateResponse,
|
||||||
response,
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
connectedUsersByOrg
|
connectedUsersByOrg
|
||||||
);
|
);
|
||||||
};
|
return;
|
||||||
|
}
|
||||||
|
const result = await projectCreationService(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Project Created Successfully" },
|
||||||
|
"Project Already Exists": { message: "Project Already Exists" },
|
||||||
|
"Already MVC architecture assigned to this projectId": {
|
||||||
|
message: "Already MVC architecture assigned to this projectId",
|
||||||
|
},
|
||||||
|
"Project creation unsuccessfull": {
|
||||||
|
message: "Project creation unsuccessfull",
|
||||||
|
},
|
||||||
|
"New architecture": { message: "New architecture" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result_Datas =
|
||||||
|
status === "Success" && result?.data ? result.data : undefined;
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
result_Datas
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.projectCreateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user