API completed

This commit is contained in:
2025-10-25 09:25:25 +05:30
parent dbd0132936
commit e86a6609b0
20 changed files with 2124 additions and 920 deletions

2
.env
View File

@@ -9,7 +9,7 @@ JWT_SECRET="Schema_Studio"
REFRESH_JWT_SECRET="Schema_Studio" REFRESH_JWT_SECRET="Schema_Studio"
REDIS_ENV= false REDIS_ENV= false
REDIS_LOCAL = 192.168.0.203 REDIS_LOCAL = 192.168.0.204
REDIS_PORT=6379 REDIS_PORT=6379
EMAIL_USER=nivetha@hexrfactory.com EMAIL_USER=nivetha@hexrfactory.com

View File

@@ -11,9 +11,26 @@ export const signupController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { userName, email, password } = req.body; const { userName, email, password } = req.body;
if (!userName || !email || !password) { // if (!userName || !email || !password) {
// res.status(400).json({
// message: "All fields are required",
// });
// return;
// }
const missing = Object.entries({
userName,
email,
password,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
@@ -64,9 +81,25 @@ export const signinController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { email, password } = req.body; const { email, password } = req.body;
if (!email || !password) { // if (!email || !password) {
// res.status(400).json({
// message: "All fields are required",
// });
// return;
// }
const missing = Object.entries({
email,
password,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
@@ -112,9 +145,24 @@ export const forgetPasswordController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { email } = req.body; const { email } = req.body;
if (!email) { // if (!email) {
// res.status(400).json({
// message: "All fields are required",
// });
// return;
// }
const missing = Object.entries({
email,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }

View File

@@ -21,28 +21,34 @@ export const NodeCreationController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, position, collectionName, type } = req.body; const { projectId, position, collectionName, type } = req.body;
if ( const missing = Object.entries({
!organization || organization,
!projectId || projectId,
!position || position,
!userId || userId,
!collectionName collectionName,
) { })
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
position, position,
type, type,
collectionName, collectionName,
userId, userId: userId as string,
}; };
const result = await Nodecreation(data); const result = await Nodecreation(data);
console.log("result: ", result); console.log("result:nodecreatge ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
@@ -66,7 +72,8 @@ export const NodeCreationController = async (
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,
data: result.data,
}); });
break; break;
case "Validation Error": case "Validation Error":
@@ -85,15 +92,15 @@ export const NodeCreationController = async (
} }
}; };
//casting error handled and missing fields handling updated for testing
export const updateCollectionController = 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 { collectionNodeId } = req.params const { collectionNodeId, projectId } = req.params;
const { const {
projectId,
collectionName, collectionName,
position, position,
backgroundColor, backgroundColor,
@@ -106,22 +113,27 @@ export const updateCollectionController = async (
borderThickness, borderThickness,
cornerRadius, cornerRadius,
} = req.body; } = req.body;
if ( const missing = Object.entries({
!organization || organization,
!projectId || projectId,
!userId || userId,
!collectionName || collectionNodeId,
!collectionNodeId })
) { .filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
backgroundColor, backgroundColor,
borderColor, borderColor,
fontColor, fontColor,
@@ -136,7 +148,6 @@ export const updateCollectionController = async (
position, position,
}; };
const result = await updatecollection(data); const result = await updatecollection(data);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
res.status(404).json({ message: "User not found" }); res.status(404).json({ message: "User not found" });
@@ -146,6 +157,9 @@ export const updateCollectionController = async (
message: "project not found", message: "project not found",
}); });
break; break;
case "Invalid ID":
res.status(400).json({ message: result.data || "Invalid ID provided" });
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",
@@ -176,16 +190,27 @@ export const CollectionDatas = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, collectionNodeId } = req.params; const { projectId, collectionNodeId } = req.params;
if (!organization || !projectId || !collectionNodeId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
collectionNodeId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
collectionNodeId, collectionNodeId,
}; };
const result = await GetcollectionNode(data); const result = await GetcollectionNode(data);
@@ -227,16 +252,27 @@ export const graphicDatas = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, collectionNodeId } = req.params; const { projectId, collectionNodeId } = req.params;
if (!organization || !projectId || !collectionNodeId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
collectionNodeId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
collectionNodeId, collectionNodeId,
}; };
const result = await GetcollectionGraphicData(data); const result = await GetcollectionGraphicData(data);
@@ -278,16 +314,27 @@ export const DeleteCollectionsController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, collectionNodeId } = req.params; const { projectId, collectionNodeId } = req.params;
if (!organization || !projectId || !collectionNodeId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
collectionNodeId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
collectionNodeId, collectionNodeId,
}; };
const result = await delCollection(data); const result = await delCollection(data);
@@ -329,16 +376,27 @@ export const DuplicateNodeCollectionController = async (
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { collectionNodeId } = req.params; const { collectionNodeId } = req.params;
const { projectId, collectionName, position, attributes } = req.body; const { projectId, collectionName, position, attributes } = req.body;
if (!organization || !projectId || !collectionNodeId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
collectionNodeId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: organization as string,
collectionName, collectionName,
position, position,
attributes, attributes,
@@ -382,19 +440,28 @@ export const NodesCollectionsBasedOnproject = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !projectId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
}; };
const result = await GetNodesInProject(data); const result = await GetNodesInProject(data);
console.log("resultdssa: ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
@@ -435,27 +502,33 @@ export const AddAttributesController = async (
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
// const { collectionNodeId } = req.params; // const { collectionNodeId } = req.params;
const { projectId, attributes, collectionNodeId } = req.body; const { projectId, attributes, collectionNodeId } = req.body;
if ( const missing = Object.entries({
!organization || organization,
!projectId || projectId,
!attributes || userId,
!userId || attributes,
!collectionNodeId collectionNodeId,
) { })
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
collectionNodeId, collectionNodeId,
attributes, attributes,
}; };
const result = await addAttributes(data); const result = await addAttributes(data);
console.log("result: ", result); console.log("result:addattri ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
res.status(404).json({ message: "User not found" }); res.status(404).json({ message: "User not found" });
@@ -470,6 +543,9 @@ export const AddAttributesController = async (
message: "Subcollection already added for the object data", message: "Subcollection already added for the object data",
}); });
break; break;
case "Invalid ObjectId":
res.status(400).json({ message: "Invalid Id" });
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",
@@ -478,6 +554,7 @@ export const AddAttributesController = async (
case "Success": case "Success":
res.status(200).json({ res.status(200).json({
message: "collection Attributes Added", message: "collection Attributes Added",
fieldId: result.data,
}); });
break; break;
default: default:
@@ -499,45 +576,34 @@ export const updateAttributesCollections = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { collectionNodeId, attributeId } = req.params; const { collectionNodeId } = req.params;
const { const { projectId, attributes } = req.body;
const missing = Object.entries({
organization,
projectId, projectId,
required, userId,
primary, collectionNodeId,
defaultValue, })
unique, .filter(([_, v]) => !v)
index, .map(([k]) => k);
key,
type, if (missing.length) {
} = req.body;
if (
!organization ||
!userId ||
!projectId ||
!collectionNodeId ||
!attributeId
) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
primary, userId: userId as string,
userId,
collectionNodeId, collectionNodeId,
attributeId, attributes,
required,
defaultValue,
unique,
index,
key,
type,
}; };
const result = await UpdateAttributes(data); const result = await UpdateAttributes(data);
console.log("result: ", result); console.log("result:d ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
@@ -576,27 +642,34 @@ export const delAttributesCollections = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { collectionNodeId } = req.params; const { collectionNodeId } = req.params;
const { projectId, AttributeId } = req.body; const { projectId, fieldId } = req.body;
if ( const missing = Object.entries({
!organization || organization,
!projectId || projectId,
!collectionNodeId || userId,
!AttributeId || collectionNodeId,
!userId fieldId,
) { })
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
userId, userId: userId as string,
projectId, projectId,
collectionNodeId, collectionNodeId,
AttributeId, fieldId,
}; };
const result = await DelAttributes(data); const result = await DelAttributes(data);
console.log("result:delatt ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
res.status(404).json({ message: "User not found" }); res.status(404).json({ message: "User not found" });
@@ -607,9 +680,13 @@ export const delAttributesCollections = async (
}); });
break; break;
case "Collection not found": case "Collection not found":
res.status(200).json({ res.status(404).json({
message: "Collection not found", message: "Collection not found",
Collections: result.data, });
break;
case "Attribute not found":
res.status(200).json({
message: "field not found",
}); });
break; break;
case "Success": case "Success":
@@ -635,27 +712,45 @@ export const duplicateAttributesCollections = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, attrKey, collectionNodeId } = req.body; const { projectId, attrKey, collectionNodeId } = req.body;
if ( // if (
!organization || // !organization ||
!projectId || // !projectId ||
!collectionNodeId || // !collectionNodeId ||
!attrKey || // !attrKey ||
!userId // !userId
) { // ) {
// res.status(400).json({
// message: "All fields are required",
// });
// return;
// }
const missing = Object.entries({
organization,
projectId,
userId,
collectionNodeId,
attrKey,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
userId, userId: userId as string,
projectId, projectId,
collectionNodeId, collectionNodeId,
attrKey, attrKey,
}; };
const result = await DuplicateAttributes(data); const result = await DuplicateAttributes(data);
console.log("result: ", result); console.log("result:duplicateatt ", result);
switch (result.status) { switch (result.status) {
case "User not found": case "User not found":
res.status(404).json({ message: "User not found" }); res.status(404).json({ message: "User not found" });
@@ -701,16 +796,27 @@ export const collectionListsController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !projectId || !userId) {
const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
}; };
const result = await GetcollectionLists(data); const result = await GetcollectionLists(data);

View File

@@ -445,7 +445,7 @@ export const AddAttributesControllerdummy = async (
// ): Promise<void> => { // ): Promise<void> => {
// try { // try {
// const { organization, userId } = req.user || {}; // const { organization, userId } = req.user || {};
// const { collectionNodeId, attributeId } = req.params; // const { collectionNodeId, fieldId } = req.params;
// const { projectId, required, defaultValue, unique, index, key, type } = // const { projectId, required, defaultValue, unique, index, key, type } =
// req.body; // req.body;
// if ( // if (
@@ -453,7 +453,7 @@ export const AddAttributesControllerdummy = async (
// !userId || // !userId ||
// !projectId || // !projectId ||
// !collectionNodeId || // !collectionNodeId ||
// !attributeId // !fieldId
// ) { // ) {
// res.status(400).json({ // res.status(400).json({
// message: "All fields are required", // message: "All fields are required",
@@ -465,7 +465,7 @@ export const AddAttributesControllerdummy = async (
// projectId, // projectId,
// userId, // userId,
// collectionNodeId, // collectionNodeId,
// attributeId, // fieldId,
// required, // required,
// defaultValue, // defaultValue,
// unique, // unique,
@@ -508,12 +508,12 @@ export const AddAttributesControllerdummy = async (
// try { // try {
// const { organization, userId } = req.user || {}; // const { organization, userId } = req.user || {};
// const { collectionNodeId } = req.params; // const { collectionNodeId } = req.params;
// const { projectId, AttributeId } = req.body; // const { projectId, fieldId } = req.body;
// if ( // if (
// !organization || // !organization ||
// !projectId || // !projectId ||
// !collectionNodeId || // !collectionNodeId ||
// !AttributeId || // !fieldId ||
// !userId // !userId
// ) { // ) {
// res.status(400).json({ // res.status(400).json({
@@ -526,7 +526,7 @@ export const AddAttributesControllerdummy = async (
// userId, // userId,
// projectId, // projectId,
// collectionNodeId, // collectionNodeId,
// AttributeId, // fieldId,
// }; // };
// const result = await DelAttributes(data); // const result = await DelAttributes(data);
// switch (result.status) { // switch (result.status) {

View File

@@ -1,4 +1,4 @@
import { Request, Response } from "express"; import { Response } from "express";
import { import {
Alledges, Alledges,
deleteEdge, deleteEdge,
@@ -12,19 +12,31 @@ export const edgeCreationController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, from, to, cardinality } = req.body; const { projectId, from, to, cardinality } = req.body;
if (!organization || !projectId || !from || !to || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
from,
to,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
from, from,
to, to,
cardinality, cardinality,
userId, userId: userId as string,
}; };
const result = await edgecreation(data); const result = await edgecreation(data);
@@ -52,6 +64,9 @@ export const edgeCreationController = async (
message: "Field already exists", message: "Field already exists",
}); });
break; break;
case "Validation Error":
res.status(400).json({ message: result.data || "Validation Error" });
break;
case "Success": case "Success":
res.status(200).json({ res.status(200).json({
message: "Edge created successfully", message: "Edge created successfully",
@@ -77,16 +92,26 @@ export const allEdgesController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !projectId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
}; };
const result = await Alledges(data); const result = await Alledges(data);
@@ -129,17 +154,28 @@ export const deleteEdgesController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId, edgeId } = req.params; const { projectId, edgeId } = req.params;
if (!organization || !projectId || !edgeId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
edgeId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
edgeId, edgeId,
userId, userId: userId as string,
}; };
const result = await deleteEdge(data); const result = await deleteEdge(data);

View File

@@ -0,0 +1,82 @@
import { Request, Response } from "express";
import { AuthenticatedRequest } from "../../shared/utils/token";
import { groupcreation } from "../../shared/services/groupService";
export const addGroupController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const { projectId, position, groupName, type, collections } = req.body;
const missing = Object.entries({
organization,
projectId,
position,
userId,
groupName,
type,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({
message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
});
return;
}
const data = {
organization: organization as string,
projectId,
position,
type,
groupName,
collections,
userId: userId as string,
};
const result = await groupcreation(data);
console.log("result:groupcretate ", 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 "Collections already exist in this group":
res.status(200).json({
message: "Collections already exist in this group",
});
break;
case "Collections added to existing group":
res.status(200).json({
message: "Collections added to existing group",
});
break;
case "Success":
res.status(200).json({
message: "Group created successfully",
groupId: result.data,
});
break;
case "Validation Error":
res.status(400).json({ message: result.data || "Validation Error" });
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};

View File

@@ -11,15 +11,24 @@ export const homePageRecentlyViewedController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
if (!organization || !userId) { const missing = Object.entries({
organization,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
userId, userId: userId as string,
}; };
const result = await recentlyViewedServices(data); const result = await recentlyViewedServices(data);
@@ -53,15 +62,24 @@ export const homePageUserDataController = async (
): Promise<void> => { ): Promise<void> => {
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
if (!organization || !userId) { const missing = Object.entries({
organization,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
userId, userId: userId as string,
}; };
const result = await homeuserProfileServices(data); const result = await homeuserProfileServices(data);

View File

@@ -2,6 +2,7 @@ import { Request, Response } from "express";
import { import {
DeleteProject, DeleteProject,
GetNodesInProject, GetNodesInProject,
projectClear,
projectCreationService, projectCreationService,
projectDatas, projectDatas,
projectModification, projectModification,
@@ -23,32 +24,37 @@ export const projectCreationController = async (
architecture, architecture,
description, description,
} = req.body; } = req.body;
if ( const missing = Object.entries({
!organization || organization,
!language || language,
!projectName || userId,
!userId || projectName,
!apiProtocol || apiProtocol,
!architecture || architecture,
!application application,
) { })
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectName, projectName,
language, language,
description, description,
application, application,
userId, userId: userId as string,
apiProtocol, 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":
@@ -97,17 +103,26 @@ export const getProjects = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { skip, limit } = req.params; const { skip, limit } = req.params;
if (!organization || !userId) { const missing = Object.entries({
organization,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const skipdata = parseInt(skip); const skipdata = parseInt(skip);
const limitdata = parseInt(limit); const limitdata = parseInt(limit);
const result = await projectDatas({ const result = await projectDatas({
organization, organization: organization as string,
userId, userId: userId as string,
skipdata, skipdata,
limitdata, limitdata,
}); });
@@ -139,16 +154,26 @@ export const NodesCollectionsBasedOnproject = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !projectId || !userId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const data = { const data = {
organization, organization: organization as string,
projectId, projectId,
userId, userId: userId as string,
}; };
const result = await GetNodesInProject(data); const result = await GetNodesInProject(data);
switch (result.status) { switch (result.status) {
@@ -191,15 +216,25 @@ export const accessAproject = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !userId || !projectId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const result = await ViewProjectService({ const result = await ViewProjectService({
organization, organization: organization as string,
userId, userId: userId as string,
projectId, projectId,
}); });
@@ -235,15 +270,25 @@ export const deleteProjectController = async (
try { try {
const { organization, userId } = req.user || {}; const { organization, userId } = req.user || {};
const { projectId } = req.params; const { projectId } = req.params;
if (!organization || !userId || !projectId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const result = await DeleteProject({ const result = await DeleteProject({
organization, organization: organization as string,
userId, userId: userId as string,
projectId, projectId,
}); });
@@ -294,16 +339,26 @@ export const updateProjectController = async (
language, language,
architecture, architecture,
} = req.body; } = req.body;
if (!organization || !userId || !projectId) { const missing = Object.entries({
organization,
projectId,
userId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({ res.status(400).json({
message: "All fields are required", message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
}); });
return; return;
} }
const result = await projectModification({ const result = await projectModification({
projectId, projectId,
organization, organization: organization as string,
userId, userId: userId as string,
projectName, projectName,
application, application,
description, description,
@@ -343,3 +398,64 @@ export const updateProjectController = async (
}); });
} }
}; };
export const projectClearController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const { projectId } = req.params;
const missing = Object.entries({
organization,
userId,
projectId,
})
.filter(([_, v]) => !v)
.map(([k]) => k);
if (missing.length) {
res.status(400).json({
message: `Missing field${missing.length > 1 ? "s" : ""}: ${missing.join(
", "
)}`,
});
return;
}
const data = {
organization: organization as string,
projectId,
userId: userId as string,
};
const result = await projectClear(data);
console.log("result:clear ", 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 "Success":
res.status(200).json({
message: "Datas cleared successfully",
});
break;
case "Validation Error":
res.status(400).json({ message: result.data || "Validation Error" });
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
res.status(500).json({
message: "Unknown error",
});
}
};

View File

@@ -17,6 +17,7 @@ import { tokenValidator } from "../../shared/utils/token";
import authorizedRoles from "../../shared/middleware/rbacMiddleware"; import authorizedRoles from "../../shared/middleware/rbacMiddleware";
const collectionNodeRoutes = express.Router(); const collectionNodeRoutes = express.Router();
//Node creation //Node creation
collectionNodeRoutes.post( collectionNodeRoutes.post(
"/node/save", "/node/save",
@@ -24,13 +25,15 @@ collectionNodeRoutes.post(
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
NodeCreationController NodeCreationController
); );
//collection update //collection update
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:collectionNodeId", "/nodes/update/:projectId/:collectionNodeId",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
updateCollectionController updateCollectionController
); );
//duplicate collection //duplicate collection
collectionNodeRoutes.post( collectionNodeRoutes.post(
"/nodes/:collectionNodeId/duplicate", "/nodes/:collectionNodeId/duplicate",
@@ -46,6 +49,7 @@ collectionNodeRoutes.get(
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
CollectionDatas CollectionDatas
); );
//delete collection //delete collection
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:projectId/:collectionNodeId", "/nodes/:projectId/:collectionNodeId",
@@ -72,7 +76,7 @@ collectionNodeRoutes.get(
//update fields //update fields
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes/:attributeId", "/nodesfield/attribute/:collectionNodeId",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
updateAttributesCollections updateAttributesCollections
@@ -80,7 +84,7 @@ collectionNodeRoutes.patch(
//delete fields //delete fields
collectionNodeRoutes.patch( collectionNodeRoutes.patch(
"/nodes/:collectionNodeId/attributes/softDelete", "/nodes/:collectionNodeId/attributes/softdelete",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
delAttributesCollections delAttributesCollections
@@ -102,11 +106,11 @@ collectionNodeRoutes.get(
); );
//graphic Data //graphic Data
collectionNodeRoutes.get( collectionNodeRoutes.get(
"/collections/:projectId/:collectionNodeId", "/collections/:projectId/:collectionNodeId",
tokenValidator, tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
graphicDatas graphicDatas
); );
export default collectionNodeRoutes; export default collectionNodeRoutes;

View File

@@ -70,7 +70,7 @@ dummyRoutes.patch(
// ); // );
// //update fields // //update fields
// dummyRoutes.patch( // dummyRoutes.patch(
// "/nodes/:collectionNodeId/attributes/:attributeId", // "/nodes/:collectionNodeId/attributes/:fieldId",
// tokenValidator, // tokenValidator,
// authorizedRoles("Admin", "Editor", "Viewer"), // authorizedRoles("Admin", "Editor", "Viewer"),
// updateAttributesCollections // updateAttributesCollections

View File

@@ -5,6 +5,7 @@ import {
deleteProjectController, deleteProjectController,
getProjects, getProjects,
NodesCollectionsBasedOnproject, NodesCollectionsBasedOnproject,
projectClearController,
projectCreationController, projectCreationController,
updateProjectController, updateProjectController,
} from "../controller/projectController"; } from "../controller/projectController";
@@ -59,4 +60,13 @@ projectRoutes.patch(
authorizedRoles("Admin", "Editor", "Viewer"), authorizedRoles("Admin", "Editor", "Viewer"),
updateProjectController updateProjectController
); );
//clear Project
projectRoutes.patch(
"/project/:projectId/clearAll",
tokenValidator,
authorizedRoles("Admin", "Editor", "Viewer"),
projectClearController
);
export default projectRoutes; export default projectRoutes;

View File

@@ -5,7 +5,7 @@ type IattributeTypes =
| "string" | "string"
| "any" | "any"
| "Array" | "Array"
| "Date" | "date"
| "Enum" | "Enum"
| "Undefined" | "Undefined"
| "Object" | "Object"
@@ -19,6 +19,7 @@ type IattributeTypes =
interface IAttributes { interface IAttributes {
isArchive: boolean; isArchive: boolean;
isIdentifier: boolean;
primary?: boolean; primary?: boolean;
key: string; key: string;
type: IattributeTypes; type: IattributeTypes;
@@ -61,7 +62,7 @@ const attributeSchema = new Schema<IAttributes>({
"string", "string",
"Number", "Number",
"Boolean", "Boolean",
"Date", "date",
"ObjectId", "ObjectId",
"Array", "Array",
"Enum", "Enum",
@@ -81,6 +82,7 @@ const attributeSchema = new Schema<IAttributes>({
primary: { type: Boolean }, primary: { type: Boolean },
index: { type: Boolean }, index: { type: Boolean },
isArchive: { type: Boolean, default: false }, isArchive: { type: Boolean, default: false },
isIdentifier: { type: Boolean, default: false },
}); });
interface ColorHex { interface ColorHex {
type: "HEX"; type: "HEX";
@@ -128,6 +130,7 @@ const collectionSchema: Schema<ICollectionNode> = new Schema(
cornerRadius: { type: Number }, cornerRadius: { type: Number },
fontSize: { type: Number }, fontSize: { type: Number },
isArchive: { type: Boolean, default: false }, isArchive: { type: Boolean, default: false },
// isIdentifier: { type: Boolean, default: false },
isSubCollection: { type: Boolean, default: false }, isSubCollection: { type: Boolean, default: false },
attributes: [attributeSchema], attributes: [attributeSchema],
}, },

View File

@@ -21,7 +21,7 @@ const EdgeSchema = new Schema<IEdgeModel>({
cardinality: { cardinality: {
type: String, type: String,
enum: ["one-to-one", "one-to-many", "many-to-many"], enum: ["one-to-one", "one-to-many", "many-to-many"],
required: true, // required: true,
}, },
isArchive: { type: Boolean, default: false }, isArchive: { type: Boolean, default: false },
createdAt: { type: Number, default: Date.now }, createdAt: { type: Number, default: Date.now },

View File

@@ -0,0 +1,36 @@
import { Schema, Document } from "mongoose";
import MainModel from "../connection/connection";
import { IProject } from "./projectmodel";
import { ICollectionNode } from "./collectionModel";
import { IUser } from "./userModel";
export interface IgroupModel extends Document {
type: string;
groupName: string;
position: {
x: number;
y: number;
};
projectId: IProject["_id"];
collections: ICollectionNode["_id"][];
isArchive: boolean;
createdBy: IUser["_id"];
}
const GroupSchema = new Schema<IgroupModel>(
{
type: { type: String },
groupName: { type: String, required: true },
position: {
x: { type: Number },
y: { type: Number },
},
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
collections: [{ type: Schema.Types.ObjectId, ref: "Collection" }],
isArchive: { type: Boolean, default: false },
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
},
{ timestamps: true }
);
const groupModel = (db: any) => {
return MainModel(db, "group", GroupSchema, "group");
};
export default groupModel;

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ interface IAttributesEdit {
userId: string; userId: string;
organization: string; organization: string;
collectionNodeId: string; collectionNodeId: string;
attributeId: string; fieldId: string;
key?: string; key?: string;
type?: string; type?: string;
required?: boolean; required?: boolean;
@@ -69,7 +69,7 @@ interface IAttributesDel {
userId: string; userId: string;
organization: string; organization: string;
collectionNodeId: string; collectionNodeId: string;
AttributeId: string; fieldId: string;
} }
interface ICollectionDelete { interface ICollectionDelete {
projectId: string; projectId: string;
@@ -308,7 +308,7 @@ export const addAttributesdummy = async (
// userId, // userId,
// projectId, // projectId,
// collectionNodeId, // collectionNodeId,
// attributeId, // fieldId,
// required, // required,
// defaultValue, // defaultValue,
// unique, // unique,
@@ -338,7 +338,7 @@ export const addAttributesdummy = async (
// projectId: projectId, // projectId: projectId,
// isArchive: false, // isArchive: false,
// attributes: { // attributes: {
// $elemMatch: { _id: new mongoose.Types.ObjectId(attributeId) }, // $elemMatch: { _id: new mongoose.Types.ObjectId(fieldId) },
// }, // },
// }, // },
// { // {
@@ -371,7 +371,7 @@ export const addAttributesdummy = async (
// export const DelAttributes = async ( // export const DelAttributes = async (
// data: IAttributesDel // data: IAttributesDel
// ): Promise<Iresponse> => { // ): Promise<Iresponse> => {
// const { organization, userId, projectId, collectionNodeId, AttributeId } = // const { organization, userId, projectId, collectionNodeId, fieldId } =
// data; // data;
// try { // try {
// const existingProject = await ProjectType(organization).findOne({ // const existingProject = await ProjectType(organization).findOne({
@@ -396,7 +396,7 @@ export const addAttributesdummy = async (
// isArchive: false, // isArchive: false,
// attributes: { // attributes: {
// $elemMatch: { // $elemMatch: {
// _id: new mongoose.Types.ObjectId(AttributeId), // _id: new mongoose.Types.ObjectId(fieldId),
// isArchive: false, // isArchive: false,
// }, // },
// }, // },

View File

@@ -1,3 +1,4 @@
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 edgeModel from "../model/edgeModel";
@@ -115,9 +116,9 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
await existingToCollection.save(); await existingToCollection.save();
console.log( // console.log(
`Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}` // `Field ${newFieldKey} (type: ${fieldType}) added to TO collection with reference to ${existingFromCollection._id}`
); // );
const newEdge = { const newEdge = {
projectId, projectId,
from: { collection_id: existingFromCollection._id, field: from.field }, from: { collection_id: existingFromCollection._id, field: from.field },
@@ -138,7 +139,9 @@ export const edgecreation = async (data: IEdge): Promise<Iresponse> => {
}; };
} }
} catch (error: unknown) { } catch (error: unknown) {
console.log("error: ", error); if (error instanceof mongoose.Error.ValidationError) {
return { status: "Validation Error", data: error.message };
}
if (error instanceof Error) { if (error instanceof Error) {
return { return {
status: error.message, status: error.message,

View File

@@ -0,0 +1,202 @@
import mongoose from "mongoose";
import ProjectType from "../../shared/model/projectmodel";
import collectionsModel from "../model/collectionModel";
import userModel from "../model/userModel";
import groupModel from "../model/groupModel";
interface Iresponse {
status: string;
data?: any;
}
interface IcollectionsNode {
collectionNodeId: string;
}
interface IgroupNode {
projectId: string;
userId: string;
collections: IcollectionsNode[];
groupName: string;
type: string;
organization: string;
position: {
x: number;
y: number;
};
}
interface IgroupNodeupdate {
projectId: string;
userId: string;
groupName: string;
type: string;
organization: string;
position: {
x: number;
y: number;
};
}
export const groupcreation = async (data: IgroupNode): Promise<Iresponse> => {
const {
organization,
projectId,
position,
userId,
groupName,
type,
collections,
} = 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 existingGroup = await groupModel(organization).findOne({
projectId: projectId,
isArchive: false,
groupName: groupName,
});
// if (existingGroup) return { status: "Group already exists" };
// else {
// if (collections.length > 0) {
// const newcoln = collections;
// const updatedCollectionsMap = new Map<string, null>();
// for (const coln of collections) {
// updatedCollectionsMap.set(coln, 0);
// }
// for (const coln of collections) {
// if (!updatedCollectionsMap.has(coln)) {
// updatedCollectionsMap.set(coln);
// }
// }
// const updatedCollections = Array.from(updatedCollectionsMap.values());
// const newGroup = await groupModel(organization).create({
// groupName,
// projectId,
// position,
// createdBy: userId,
// collections: updatedCollections,
// });
// // }
// if (newGroup)
// return {
// status: "NewGroup Created Successfully",
// data: newGroup._id,
// };
// else {
// return {
// status: "Creation Unsuccessfull",
// };
// }
// }
// }
// }
const collectionIds = collections.map(
(c) => new mongoose.Types.ObjectId(c.collectionNodeId)
);
if (existingGroup) {
const existingIds = existingGroup.collections.map((id) =>
(id as any).toString()
);
const newIds = collectionIds.filter(
(id) => !existingIds.includes(id.toString())
);
if (newIds.length === 0)
return { status: "Collections already exist in this group" };
existingGroup.collections.push(...newIds);
await existingGroup.save();
return {
status: "Collections added to existing group",
data: existingGroup._id,
};
} else {
const newGroup = await groupModel(organization).create({
groupName,
type,
position,
projectId,
createdBy: userId,
collections: [
...new Set(collectionIds.map((id) => id.toString())),
].map((id) => new mongoose.Types.ObjectId(id)),
});
return { status: "Success", data: newGroup._id };
}
}
} catch (error: unknown) {
if (error instanceof mongoose.Error.ValidationError) {
return { status: "Validation Error", data: error.message };
} else if (error instanceof Error) {
return { status: error.message };
} else {
return { status: "An unexpected error occurred" };
}
}
};
// export const addNodesToGroup = async (data: IgroupNode): Promise<Iresponse> => {
// const { organization, projectId, position, userId, groupId, groups } = 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 existingGroup = await groupModel(organization).findOne({
// projectId: projectId,
// isArchive: false,
// groupId: groupId,
// });
// if (existingGroup) {
// const existingGroup = await groupModel(organization).findOneAndUpdate(
// {
// projectId: projectId,
// isArchive: false,
// groupId: groupId,
// },
// {
// groups: groups,
// },
// { new: true }
// );
// if (existingGroup) {
// return { status: "Group updated successfully" };
// } else {
// return { status: "Group update Unsuccessfully" };
// }
// }
// }
// } catch (error: unknown) {
// if (error instanceof mongoose.Error.ValidationError) {
// return { status: "Validation Error", data: error.message };
// } else if (error instanceof Error) {
// return { status: error.message };
// } else {
// return { status: "An unexpected error occurred" };
// }
// }
// };

View File

@@ -7,6 +7,7 @@ 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"; import versionModel from "../model/versionModel";
import groupModel from "../model/groupModel";
interface Iresponse { interface Iresponse {
status: string; status: string;
data?: any; data?: any;
@@ -478,3 +479,41 @@ export const projectModification = async (
} }
} }
}; };
export const projectClear = async (data: IProjectView): Promise<Iresponse> => {
try {
const { projectId, organization, userId } = 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" };
const models = [collectionsModel, edgeModel, groupModel];
for (const model of models) {
await model(organization).updateMany(
{ projectId, isArchive: false },
{ isArchive: true }
);
}
// }
return { status: "Success" };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -1,450 +1,441 @@
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 { deleteEdge, edgecreation } from "../../shared/services/edgeService"; import { deleteEdge, edgecreation } from "../../shared/services/edgeService";
import { addAttributes, DelAttributes, delCollection, DuplicateCollection, Nodecreation, SetCollectionName, UpdateAttributes } from "../../shared/services/collectionService"; import {
addAttributes,
DelAttributes,
delCollection,
DuplicateCollection,
Nodecreation,
SetCollectionName,
UpdateAttributes,
} from "../../shared/services/collectionService";
export const CollectionHandleEvent = async ( export const CollectionHandleEvent = 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.collectionCreate || !data?.organization) return; if (event !== EVENTS.collectionCreate || !data?.organization) return;
const requiredFields = [ const requiredFields = ["position", "projectId", "organization"];
"position", const missingFields = validateFields(data, requiredFields);
"projectId",
"organization",
];
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionCreateResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await Nodecreation(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Node created successfully" },
"Collection node creation unsuccessfull": { message: "Collection node creation unsuccessfull" },
"Project not found": { message: "Project not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionCreateResponse, EVENTS.collectionCreateResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await Nodecreation(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Node created successfully" },
"Collection node creation unsuccessfull": {
message: "Collection node creation unsuccessfull",
},
"Project not found": { message: "Project not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionCreateResponse,
response,
connectedUsersByOrg
);
}; };
export const CollectioNamenHandleEvent = async ( export const CollectioNamenHandleEvent = 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.collectionNameSet || !data?.organization) return; if (event !== EVENTS.collectionNameSet || !data?.organization) return;
const requiredFields = [ const requiredFields = [
"collectionName", "collectionName",
"collectionNodeId", "collectionNodeId",
"projectId", "projectId",
"organization", "organization",
]; ];
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionNameSetResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await SetCollectionName(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "collection name updated" },
"Collection not found": { message: "Collection not found" },
"Project not found": { message: "Project not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionNameSetResponse, EVENTS.collectionNameSetResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await SetCollectionName(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "collection name updated" },
"Collection not found": { message: "Collection not found" },
"Project not found": { message: "Project not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionNameSetResponse,
response,
connectedUsersByOrg
);
}; };
export const CollectioDeleteHandleEvent = async ( export const CollectioDeleteHandleEvent = 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.collectionDelete || !data?.organization) return; if (event !== EVENTS.collectionDelete || !data?.organization) return;
const requiredFields = [ const requiredFields = ["collectionNodeId", "projectId", "organization"];
"collectionNodeId", const missingFields = validateFields(data, requiredFields);
"projectId",
"organization",
];
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionDeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await delCollection(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionDeleteResponse, EVENTS.collectionDeleteResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await delCollection(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionDeleteResponse,
response,
connectedUsersByOrg
);
}; };
export const CollectioDuplicateHandleEvent = async ( export const CollectioDuplicateHandleEvent = 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.collectionDuplicate || !data?.organization) return; if (event !== EVENTS.collectionDuplicate || !data?.organization) return;
const requiredFields = [ const requiredFields = ["collectionNodeId", "projectId", "organization"];
"collectionNodeId", const missingFields = validateFields(data, requiredFields);
"projectId",
"organization",
];
const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionDeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await DuplicateCollection(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
"Duplication unsuccessfull": { message: "Duplication unsuccessfull" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionDuplicateResponse, EVENTS.collectionDeleteResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await DuplicateCollection(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
"Duplication unsuccessfull": { message: "Duplication unsuccessfull" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionDuplicateResponse,
response,
connectedUsersByOrg
);
}; };
export const setAttributesHandleEvent = async ( export const setAttributesHandleEvent = 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.collectionAttributeSet || !data?.organization) return; if (event !== EVENTS.collectionAttributeSet || !data?.organization) return;
const requiredFields = [ const requiredFields = [
"attributes", "attributes",
"collectionNodeId", "collectionNodeId",
"projectId", "projectId",
"organization", "organization",
]; ];
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeSetResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await addAttributes(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection Attributes Added" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionAttributeSetResponse, EVENTS.collectionAttributeSetResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await addAttributes(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Collection Attributes Added" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeSetResponse,
response,
connectedUsersByOrg
);
}; };
export const AttributesDeleteHandleEvent = async ( export const AttributesDeleteHandleEvent = 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.collectionAttributeDelete || !data?.organization) return; if (event !== EVENTS.collectionAttributeDelete || !data?.organization) return;
const requiredFields = [ const requiredFields = [
"attributeId", "fieldId",
"collectionNodeId", "collectionNodeId",
"projectId", "projectId",
"organization", "organization",
]; ];
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeDeleteResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await DelAttributes(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Field deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionAttributeDeleteResponse, EVENTS.collectionAttributeDeleteResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
return;
}
const result = await DelAttributes(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Field deleted successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeDeleteResponse,
response,
connectedUsersByOrg
);
}; };
export const AttributesUpdateHandleEvent = async ( export const AttributesUpdateHandleEvent = 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.collectionAttributeUpdate || !data?.organization) return; if (event !== EVENTS.collectionAttributeUpdate || !data?.organization) return;
const requiredFields = [ const requiredFields = [
"attributeId", "fieldId",
"collectionNodeId", "collectionNodeId",
"projectId", "projectId",
"organization", "organization",
]; ];
const missingFields = validateFields(data, requiredFields); const missingFields = validateFields(data, requiredFields);
if (missingFields.length > 0) {
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeUpdateResponse,
ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg
);
return;
}
const result = await UpdateAttributes(data);
console.log('result: ', result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Field updated successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log('result_Datas: ', result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log('response: ', response);
if (missingFields.length > 0) {
emitToSenderAndAdmins( emitToSenderAndAdmins(
io, io,
socket, socket,
data.organization, data.organization,
EVENTS.collectionAttributeUpdateResponse, EVENTS.collectionAttributeUpdateResponse,
response, ErrorResponse(missingFields, socket, data.organization),
connectedUsersByOrg connectedUsersByOrg
); );
}; return;
}
const result = await UpdateAttributes(data);
console.log("result: ", result);
const status = typeof result?.status === "string" ? result.status : "unknown";
const messages: Record<string, { message: string }> = {
Success: { message: "Field updated successfully" },
"Project not found": { message: "Project not found" },
"Collection not found": { message: "Collection not found" },
};
const msg = messages[status] || { message: "Internal server error" };
const result_Datas =
status === "Success" && result?.data ? result.data : undefined;
console.log("result_Datas: ", result_Datas);
const response = FinalResponse(
status,
socket,
data.organization,
messages,
result_Datas
);
console.log("response: ", response);
emitToSenderAndAdmins(
io,
socket,
data.organization,
EVENTS.collectionAttributeUpdateResponse,
response,
connectedUsersByOrg
);
};