First commit
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import dotenv from "dotenv";
|
||||
import projectRoutes from "./routes/projectRoutes";
|
||||
import collectionNodeRoutes from "./routes/collectionRoutes";
|
||||
import edgeRoutes from "./routes/edgeRoutes";
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
app.use(
|
||||
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||
);
|
||||
|
||||
app.use("/api/v1", projectRoutes);
|
||||
app.use("/api/v1", collectionNodeRoutes);
|
||||
app.use("/api/v1", edgeRoutes);
|
||||
|
||||
export default app;
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import dotenv from "dotenv";
|
||||
import projectRoutes from "./routes/projectRoutes";
|
||||
import collectionNodeRoutes from "./routes/collectionRoutes";
|
||||
import edgeRoutes from "./routes/edgeRoutes";
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
app.use(
|
||||
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||
);
|
||||
|
||||
app.use("/api/v1", projectRoutes);
|
||||
app.use("/api/v1", collectionNodeRoutes);
|
||||
app.use("/api/v1", edgeRoutes);
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,459 +1,459 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
addAttributes,
|
||||
DelAttributes,
|
||||
delCollection,
|
||||
DuplicateCollection,
|
||||
GetcollectionNode,
|
||||
GetNodesInProject,
|
||||
Nodecreation,
|
||||
SetCollectionName,
|
||||
UpdateAttributes,
|
||||
} from "../../shared/services/collectionService";
|
||||
|
||||
export const NodeCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, position } = req.body;
|
||||
if (!organization || !projectId || !position) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
position,
|
||||
};
|
||||
const result = await Nodecreation(data);
|
||||
|
||||
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 SetCollectionNameController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
collectionName,
|
||||
position,
|
||||
} = req.body;
|
||||
if (!organization || !projectId || !collectionName || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
collectionName,
|
||||
position,
|
||||
};
|
||||
const result = await SetCollectionName(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 name updated",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const CollectionDatas = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization, collectionNodeId } = req.params;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
};
|
||||
const result = await GetcollectionNode(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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, collectionNodeId } = req.params;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { projectId, organization, collectionName, position, attributes } =
|
||||
req.body;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization } = req.params;
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
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 AddAttributesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { organization, projectId, attributes } = req.body;
|
||||
if (!organization || !projectId || !attributes || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
attributes,
|
||||
};
|
||||
const result = await addAttributes(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 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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId, attributeId } = req.params;
|
||||
const {
|
||||
organization,
|
||||
projectId,
|
||||
required,
|
||||
defaultValue,
|
||||
unique,
|
||||
index,
|
||||
key,
|
||||
type,
|
||||
} = req.body;
|
||||
if (!organization || !projectId || !collectionNodeId || !attributeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { organization, projectId, AttributeId } = req.body;
|
||||
if (!organization || !projectId || !collectionNodeId || !AttributeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
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",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
addAttributes,
|
||||
DelAttributes,
|
||||
delCollection,
|
||||
DuplicateCollection,
|
||||
GetcollectionNode,
|
||||
GetNodesInProject,
|
||||
Nodecreation,
|
||||
SetCollectionName,
|
||||
UpdateAttributes,
|
||||
} from "../../shared/services/collectionService";
|
||||
|
||||
export const NodeCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, position } = req.body;
|
||||
if (!organization || !projectId || !position) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
position,
|
||||
};
|
||||
const result = await Nodecreation(data);
|
||||
|
||||
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 SetCollectionNameController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
collectionName,
|
||||
position,
|
||||
} = req.body;
|
||||
if (!organization || !projectId || !collectionName || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
collectionName,
|
||||
position,
|
||||
};
|
||||
const result = await SetCollectionName(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 name updated",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const CollectionDatas = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization, collectionNodeId } = req.params;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
};
|
||||
const result = await GetcollectionNode(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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, collectionNodeId } = req.params;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { projectId, organization, collectionName, position, attributes } =
|
||||
req.body;
|
||||
if (!organization || !projectId || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization } = req.params;
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
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 AddAttributesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { organization, projectId, attributes } = req.body;
|
||||
if (!organization || !projectId || !attributes || !collectionNodeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
collectionNodeId,
|
||||
attributes,
|
||||
};
|
||||
const result = await addAttributes(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 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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId, attributeId } = req.params;
|
||||
const {
|
||||
organization,
|
||||
projectId,
|
||||
required,
|
||||
defaultValue,
|
||||
unique,
|
||||
index,
|
||||
key,
|
||||
type,
|
||||
} = req.body;
|
||||
if (!organization || !projectId || !collectionNodeId || !attributeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
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: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { collectionNodeId } = req.params;
|
||||
const { organization, projectId, AttributeId } = req.body;
|
||||
if (!organization || !projectId || !collectionNodeId || !AttributeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
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,157 +1,157 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService";
|
||||
export const edgeCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, from,to,cardinality } = req.body;
|
||||
if (!organization || !projectId || !from || !to) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
from,
|
||||
to,
|
||||
cardinality
|
||||
};
|
||||
const result = await edgecreation(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "From collection not found":
|
||||
res.status(200).json({
|
||||
message: "From collection not found",
|
||||
});
|
||||
break;
|
||||
case "To collection not found":
|
||||
res.status(200).json({
|
||||
message: "To collection not found",
|
||||
});
|
||||
break;
|
||||
case "Field already exists":
|
||||
res.status(200).json({
|
||||
message: "Field already exists",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"Edge 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 allEdgesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, } = req.body;
|
||||
if (!organization || !projectId ) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
const result = await Alledges(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "edge not found":
|
||||
res.status(200).json({
|
||||
message: "edge not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"fetch all Edge datas 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 deleteEdgesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, edgeId} = req.body;
|
||||
if (!organization || !projectId ||!edgeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
edgeId
|
||||
};
|
||||
const result = await deleteEdge(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "edge not found":
|
||||
res.status(200).json({
|
||||
message: "edge not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"Edge deleted successfully",
|
||||
collectionNodeId: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
import { Request, Response } from "express";
|
||||
import { Alledges, deleteEdge, edgecreation } from "../../shared/services/edgeService";
|
||||
export const edgeCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, from,to,cardinality } = req.body;
|
||||
if (!organization || !projectId || !from || !to) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
from,
|
||||
to,
|
||||
cardinality
|
||||
};
|
||||
const result = await edgecreation(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "From collection not found":
|
||||
res.status(200).json({
|
||||
message: "From collection not found",
|
||||
});
|
||||
break;
|
||||
case "To collection not found":
|
||||
res.status(200).json({
|
||||
message: "To collection not found",
|
||||
});
|
||||
break;
|
||||
case "Field already exists":
|
||||
res.status(200).json({
|
||||
message: "Field already exists",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"Edge 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 allEdgesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, } = req.body;
|
||||
if (!organization || !projectId ) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
const result = await Alledges(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "edge not found":
|
||||
res.status(200).json({
|
||||
message: "edge not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"fetch all Edge datas 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 deleteEdgesController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, projectId, edgeId} = req.body;
|
||||
if (!organization || !projectId ||!edgeId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
edgeId
|
||||
};
|
||||
const result = await deleteEdge(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "project not found":
|
||||
res.status(200).json({
|
||||
message: "project not found",
|
||||
});
|
||||
break;
|
||||
case "edge not found":
|
||||
res.status(200).json({
|
||||
message: "edge not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"Edge deleted successfully",
|
||||
collectionNodeId: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,95 +1,95 @@
|
||||
import fs from "node:fs";
|
||||
import { Request, Response } from "express";
|
||||
import path from "path";
|
||||
import baseType from "../../shared/model/projectmodel";
|
||||
import FileMode from "../../shared/model/collectionModel";
|
||||
export const fileModelCreatecontroller = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<any> => {
|
||||
const { pathName, baseId, modelName, organization, attributes } = req.body;
|
||||
|
||||
try {
|
||||
const findBaseName = await baseType(organization).findById(baseId);
|
||||
|
||||
const attrToSchema = (attr: any) => {
|
||||
const mapType: any = {
|
||||
string: "String",
|
||||
number: "Number",
|
||||
boolean: "Boolean",
|
||||
};
|
||||
const lines = [];
|
||||
for (const [key, config] of Object.entries(attr)) {
|
||||
const line: string[] = [];
|
||||
line.push(`${key}: {`);
|
||||
line.push(` type: ${mapType[(config as any).type] || "String"},`);
|
||||
if ((config as any).required) line.push(` required: true,`);
|
||||
if ((config as any).default !== undefined)
|
||||
line.push(` default: ${(config as any).default},`);
|
||||
if ((config as any).minLength)
|
||||
line.push(` minlength: ${(config as any).minLength},`);
|
||||
if ((config as any).maxLength)
|
||||
line.push(` maxlength: ${(config as any).maxLength},`);
|
||||
if ((config as any).min !== undefined)
|
||||
line.push(` min: ${(config as any).min},`);
|
||||
if ((config as any).max !== undefined)
|
||||
line.push(` max: ${(config as any).max},`);
|
||||
line.push("},");
|
||||
lines.push(line.join("\n"));
|
||||
}
|
||||
return lines.join("\n");
|
||||
};
|
||||
const schemaCode = `
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const ${modelName}Schema = new mongoose.Schema({
|
||||
${attrToSchema(attributes)}
|
||||
});
|
||||
|
||||
export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema);
|
||||
`;
|
||||
|
||||
const basePath = path.join(
|
||||
pathName,
|
||||
findBaseName.BaseName,
|
||||
"src",
|
||||
"Models"
|
||||
);
|
||||
const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`);
|
||||
|
||||
// Read all subfolders inside basePath
|
||||
if (!fs.existsSync(basePath)) {
|
||||
fs.mkdirSync(basePath, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(modelFilePath, schemaCode.trim());
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Model file created successfully." });
|
||||
|
||||
// const folders = ["Controller", "Routes", "Models", "Services"];
|
||||
|
||||
// if (!fs.existsSync(basePath)) {
|
||||
// fs.mkdirSync(basePath, { recursive: true });
|
||||
// console.log(`Created root path: ${basePath}`);
|
||||
// }
|
||||
// folders.forEach(async (folder) => {
|
||||
// const fullPath = path.join(basePath, folder);
|
||||
// if (!fs.existsSync(fullPath)) {
|
||||
// fs.mkdirSync(fullPath, { recursive: true });
|
||||
// const BaseDataSave = await FileMode(organization).create({
|
||||
// baseId,
|
||||
// modelName,
|
||||
// attributes,
|
||||
|
||||
// });
|
||||
// } else {
|
||||
// res.send(`Folder already exists: ${fullPath}`);
|
||||
// console.log(`Folder already exists: ${folder}`);
|
||||
// }
|
||||
// });
|
||||
} catch (error: unknown) {
|
||||
res.send(error);
|
||||
}
|
||||
};
|
||||
import fs from "node:fs";
|
||||
import { Request, Response } from "express";
|
||||
import path from "path";
|
||||
import baseType from "../../shared/model/projectmodel";
|
||||
import FileMode from "../../shared/model/collectionModel";
|
||||
export const fileModelCreatecontroller = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<any> => {
|
||||
const { pathName, baseId, modelName, organization, attributes } = req.body;
|
||||
|
||||
try {
|
||||
const findBaseName = await baseType(organization).findById(baseId);
|
||||
|
||||
const attrToSchema = (attr: any) => {
|
||||
const mapType: any = {
|
||||
string: "String",
|
||||
number: "Number",
|
||||
boolean: "Boolean",
|
||||
};
|
||||
const lines = [];
|
||||
for (const [key, config] of Object.entries(attr)) {
|
||||
const line: string[] = [];
|
||||
line.push(`${key}: {`);
|
||||
line.push(` type: ${mapType[(config as any).type] || "String"},`);
|
||||
if ((config as any).required) line.push(` required: true,`);
|
||||
if ((config as any).default !== undefined)
|
||||
line.push(` default: ${(config as any).default},`);
|
||||
if ((config as any).minLength)
|
||||
line.push(` minlength: ${(config as any).minLength},`);
|
||||
if ((config as any).maxLength)
|
||||
line.push(` maxlength: ${(config as any).maxLength},`);
|
||||
if ((config as any).min !== undefined)
|
||||
line.push(` min: ${(config as any).min},`);
|
||||
if ((config as any).max !== undefined)
|
||||
line.push(` max: ${(config as any).max},`);
|
||||
line.push("},");
|
||||
lines.push(line.join("\n"));
|
||||
}
|
||||
return lines.join("\n");
|
||||
};
|
||||
const schemaCode = `
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const ${modelName}Schema = new mongoose.Schema({
|
||||
${attrToSchema(attributes)}
|
||||
});
|
||||
|
||||
export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema);
|
||||
`;
|
||||
|
||||
const basePath = path.join(
|
||||
pathName,
|
||||
findBaseName.BaseName,
|
||||
"src",
|
||||
"Models"
|
||||
);
|
||||
const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`);
|
||||
|
||||
// Read all subfolders inside basePath
|
||||
if (!fs.existsSync(basePath)) {
|
||||
fs.mkdirSync(basePath, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(modelFilePath, schemaCode.trim());
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Model file created successfully." });
|
||||
|
||||
// const folders = ["Controller", "Routes", "Models", "Services"];
|
||||
|
||||
// if (!fs.existsSync(basePath)) {
|
||||
// fs.mkdirSync(basePath, { recursive: true });
|
||||
// console.log(`Created root path: ${basePath}`);
|
||||
// }
|
||||
// folders.forEach(async (folder) => {
|
||||
// const fullPath = path.join(basePath, folder);
|
||||
// if (!fs.existsSync(fullPath)) {
|
||||
// fs.mkdirSync(fullPath, { recursive: true });
|
||||
// const BaseDataSave = await FileMode(organization).create({
|
||||
// baseId,
|
||||
// modelName,
|
||||
// attributes,
|
||||
|
||||
// });
|
||||
// } else {
|
||||
// res.send(`Folder already exists: ${fullPath}`);
|
||||
// console.log(`Folder already exists: ${folder}`);
|
||||
// }
|
||||
// });
|
||||
} catch (error: unknown) {
|
||||
res.send(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,168 +1,168 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
GetNodesInProject,
|
||||
projectCreationService,
|
||||
projectDatas,
|
||||
} from "../../shared/services/projectService";
|
||||
|
||||
export const projectCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
useableLanguage,
|
||||
projectName,
|
||||
userName,
|
||||
apiType,
|
||||
application,
|
||||
architecture,
|
||||
description,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!useableLanguage ||
|
||||
!projectName ||
|
||||
!userName ||
|
||||
!apiType ||
|
||||
!architecture|| !application
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectName,
|
||||
useableLanguage,
|
||||
description,application,
|
||||
userName,
|
||||
apiType,
|
||||
architecture,
|
||||
};
|
||||
const result = await projectCreationService(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "Project Already Exists":
|
||||
res.status(403).json({
|
||||
message: "Project Already Exists",
|
||||
});
|
||||
break;
|
||||
case "Already MVC architecture assigned to this projectId":
|
||||
res.status(403).json({
|
||||
message: "Already MVC architecture assigned to this projectId",
|
||||
});
|
||||
break;
|
||||
case "Project creation unsuccessfull":
|
||||
res.status(200).json({
|
||||
message: "Project creation unsuccessfull",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Project created successfully",
|
||||
projectId: result.data,
|
||||
});
|
||||
break;
|
||||
case "New architecture":
|
||||
res.status(200).json({
|
||||
message: "New architecture",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getProjects = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization } = req.body;
|
||||
if (!organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await projectDatas(organization);
|
||||
|
||||
switch (result.status) {
|
||||
case "No project found":
|
||||
res.status(200).json({});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Project created successfully",
|
||||
projectDatas: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const NodesCollectionsBasedOnproject = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization } = req.params;
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
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(result.data);
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
GetNodesInProject,
|
||||
projectCreationService,
|
||||
projectDatas,
|
||||
} from "../../shared/services/projectService";
|
||||
|
||||
export const projectCreationController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
useableLanguage,
|
||||
projectName,
|
||||
userName,
|
||||
apiType,
|
||||
application,
|
||||
architecture,
|
||||
description,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!useableLanguage ||
|
||||
!projectName ||
|
||||
!userName ||
|
||||
!apiType ||
|
||||
!architecture|| !application
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectName,
|
||||
useableLanguage,
|
||||
description,application,
|
||||
userName,
|
||||
apiType,
|
||||
architecture,
|
||||
};
|
||||
const result = await projectCreationService(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "Project Already Exists":
|
||||
res.status(403).json({
|
||||
message: "Project Already Exists",
|
||||
});
|
||||
break;
|
||||
case "Already MVC architecture assigned to this projectId":
|
||||
res.status(403).json({
|
||||
message: "Already MVC architecture assigned to this projectId",
|
||||
});
|
||||
break;
|
||||
case "Project creation unsuccessfull":
|
||||
res.status(200).json({
|
||||
message: "Project creation unsuccessfull",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Project created successfully",
|
||||
projectId: result.data,
|
||||
});
|
||||
break;
|
||||
case "New architecture":
|
||||
res.status(200).json({
|
||||
message: "New architecture",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getProjects = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization } = req.body;
|
||||
if (!organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await projectDatas(organization);
|
||||
|
||||
switch (result.status) {
|
||||
case "No project found":
|
||||
res.status(200).json({});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Project created successfully",
|
||||
projectDatas: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const NodesCollectionsBasedOnproject = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId, organization } = req.params;
|
||||
if (!organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
projectId,
|
||||
};
|
||||
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(result.data);
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import app from "./app";
|
||||
const port = process.env.API_PORT;
|
||||
app.listen(port, () => {
|
||||
console.log(`Port is running on the ${port}`);
|
||||
});
|
||||
import app from "./app";
|
||||
const port = process.env.API_PORT;
|
||||
app.listen(port, () => {
|
||||
console.log(`Port is running on the ${port}`);
|
||||
});
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
import express from "express";
|
||||
import {
|
||||
AddAttributesController,
|
||||
CollectionDatas,
|
||||
delAttributesCollections,
|
||||
DeleteCollectionsController,
|
||||
DuplicateNodeCollectionController,
|
||||
NodeCreationController,
|
||||
NodesCollectionsBasedOnproject,
|
||||
SetCollectionNameController,
|
||||
updateAttributesCollections,
|
||||
} from "../controller/collectionNodeController";
|
||||
|
||||
const collectionNodeRoutes = express.Router();
|
||||
//Node creation
|
||||
collectionNodeRoutes.post("/nodes", NodeCreationController);
|
||||
//collection Added
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/collectionName",
|
||||
SetCollectionNameController
|
||||
);
|
||||
//duplicate collection
|
||||
collectionNodeRoutes.post(
|
||||
"/nodes/:collectionNodeId/duplicate",
|
||||
DuplicateNodeCollectionController
|
||||
);
|
||||
//particular collection data
|
||||
collectionNodeRoutes.get(
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
CollectionDatas
|
||||
);
|
||||
//delete collection
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
DeleteCollectionsController
|
||||
);
|
||||
|
||||
//Add fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes",
|
||||
AddAttributesController
|
||||
);
|
||||
//Collections and fiels based on the project
|
||||
collectionNodeRoutes.get(
|
||||
"/nodes/:organization/:projectId",
|
||||
NodesCollectionsBasedOnproject
|
||||
);
|
||||
//update fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/:attributeId",
|
||||
updateAttributesCollections
|
||||
);
|
||||
//delete fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/softDelete",
|
||||
delAttributesCollections
|
||||
);
|
||||
export default collectionNodeRoutes;
|
||||
import express from "express";
|
||||
import {
|
||||
AddAttributesController,
|
||||
CollectionDatas,
|
||||
delAttributesCollections,
|
||||
DeleteCollectionsController,
|
||||
DuplicateNodeCollectionController,
|
||||
NodeCreationController,
|
||||
NodesCollectionsBasedOnproject,
|
||||
SetCollectionNameController,
|
||||
updateAttributesCollections,
|
||||
} from "../controller/collectionNodeController";
|
||||
|
||||
const collectionNodeRoutes = express.Router();
|
||||
//Node creation
|
||||
collectionNodeRoutes.post("/nodes", NodeCreationController);
|
||||
//collection Added
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/collectionName",
|
||||
SetCollectionNameController
|
||||
);
|
||||
//duplicate collection
|
||||
collectionNodeRoutes.post(
|
||||
"/nodes/:collectionNodeId/duplicate",
|
||||
DuplicateNodeCollectionController
|
||||
);
|
||||
//particular collection data
|
||||
collectionNodeRoutes.get(
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
CollectionDatas
|
||||
);
|
||||
//delete collection
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:organization/:projectId/:collectionNodeId",
|
||||
DeleteCollectionsController
|
||||
);
|
||||
|
||||
//Add fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes",
|
||||
AddAttributesController
|
||||
);
|
||||
//Collections and fiels based on the project
|
||||
collectionNodeRoutes.get(
|
||||
"/nodes/:organization/:projectId",
|
||||
NodesCollectionsBasedOnproject
|
||||
);
|
||||
//update fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/:attributeId",
|
||||
updateAttributesCollections
|
||||
);
|
||||
//delete fields
|
||||
collectionNodeRoutes.patch(
|
||||
"/nodes/:collectionNodeId/attributes/softDelete",
|
||||
delAttributesCollections
|
||||
);
|
||||
export default collectionNodeRoutes;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import express from "express";
|
||||
import { allEdgesController, deleteEdgesController, edgeCreationController } from "../controller/edgeController";
|
||||
const edgeRoutes = express.Router();
|
||||
|
||||
edgeRoutes.post("/edgeCreate", edgeCreationController);
|
||||
edgeRoutes.patch("/edgeDelete", deleteEdgesController);
|
||||
edgeRoutes.get("/allEdges", allEdgesController);
|
||||
export default edgeRoutes;
|
||||
import express from "express";
|
||||
import { allEdgesController, deleteEdgesController, edgeCreationController } from "../controller/edgeController";
|
||||
const edgeRoutes = express.Router();
|
||||
|
||||
edgeRoutes.post("/edgeCreate", edgeCreationController);
|
||||
edgeRoutes.patch("/edgeDelete", deleteEdgesController);
|
||||
edgeRoutes.get("/allEdges", allEdgesController);
|
||||
export default edgeRoutes;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import express from "express";
|
||||
import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController";
|
||||
|
||||
const projectRoutes = express.Router();
|
||||
|
||||
projectRoutes.post("/Newproject", projectCreationController);
|
||||
projectRoutes.get(
|
||||
"/nodes/:organization/:projectId",
|
||||
NodesCollectionsBasedOnproject
|
||||
);
|
||||
// appRoutes.post("/createfileModel", fileModelCreatecontroller);
|
||||
export default projectRoutes;
|
||||
import express from "express";
|
||||
import { NodesCollectionsBasedOnproject, projectCreationController } from "../controller/projectController";
|
||||
|
||||
const projectRoutes = express.Router();
|
||||
|
||||
projectRoutes.post("/Newproject", projectCreationController);
|
||||
projectRoutes.get(
|
||||
"/nodes/:organization/:projectId",
|
||||
NodesCollectionsBasedOnproject
|
||||
);
|
||||
// appRoutes.post("/createfileModel", fileModelCreatecontroller);
|
||||
export default projectRoutes;
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
import mongoose, { Schema, Connection, Model } from "mongoose";
|
||||
import dotenv from "dotenv";
|
||||
interface ConnectionCache {
|
||||
[key: string]: Connection;
|
||||
}
|
||||
|
||||
const connections: ConnectionCache = {};
|
||||
dotenv.config({ quiet: true });
|
||||
const MainModel = <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);
|
||||
}
|
||||
|
||||
try {
|
||||
const db1 = mongoose.createConnection(db1_url, authOptions);
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
export default MainModel;
|
||||
import mongoose, { Schema, Connection, Model } from "mongoose";
|
||||
import dotenv from "dotenv";
|
||||
interface ConnectionCache {
|
||||
[key: string]: Connection;
|
||||
}
|
||||
|
||||
const connections: ConnectionCache = {};
|
||||
dotenv.config({ quiet: true });
|
||||
const MainModel = <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);
|
||||
}
|
||||
|
||||
try {
|
||||
const db1 = mongoose.createConnection(db1_url, authOptions);
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
export default MainModel;
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
type IattributeTypes =
|
||||
| "string"
|
||||
| "any"
|
||||
| "Array"
|
||||
| "Date"
|
||||
| "Enum"
|
||||
| "undefined"
|
||||
| "object"
|
||||
| "ObjectId"
|
||||
| "number"
|
||||
| "boolean";
|
||||
|
||||
interface IAttributes {
|
||||
isArchive: boolean;
|
||||
key: string;
|
||||
type: IattributeTypes;
|
||||
refKey?: object;
|
||||
required?: boolean;
|
||||
default?: any;
|
||||
unique?: boolean;
|
||||
index?: boolean;
|
||||
}
|
||||
interface ICollectionNode extends Document {
|
||||
projectId: IProject["_id"];
|
||||
collectionNodeName: string;
|
||||
attributes: IAttributes[];
|
||||
isArchive: boolean;
|
||||
position: [number, number, number];
|
||||
}
|
||||
const attributeSchema = new Schema<IAttributes>({
|
||||
key: { type: String, required: true },
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"Date",
|
||||
"ObjectId",
|
||||
"Array",
|
||||
"Enum",
|
||||
"object",
|
||||
"any",
|
||||
],
|
||||
},
|
||||
required: { type: Boolean },
|
||||
refKey: { type: Object },
|
||||
default: { type: Schema.Types.Mixed },
|
||||
unique: { type: Boolean },
|
||||
index: { type: Boolean },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
});
|
||||
const collectionSchema: Schema<ICollectionNode> = new Schema(
|
||||
{
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
collectionNodeName: { type: String },
|
||||
position: { type: [Number], required: true },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
attributes: [attributeSchema],
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const collectionsModel = (db: any) => {
|
||||
return MainModel(db, "collectionNode", collectionSchema, "collectionNode");
|
||||
};
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
type IattributeTypes =
|
||||
| "string"
|
||||
| "any"
|
||||
| "Array"
|
||||
| "Date"
|
||||
| "Enum"
|
||||
| "undefined"
|
||||
| "object"
|
||||
| "ObjectId"
|
||||
| "number"
|
||||
| "boolean";
|
||||
|
||||
interface IAttributes {
|
||||
isArchive: boolean;
|
||||
key: string;
|
||||
type: IattributeTypes;
|
||||
refKey?: object;
|
||||
required?: boolean;
|
||||
default?: any;
|
||||
unique?: boolean;
|
||||
index?: boolean;
|
||||
}
|
||||
interface ICollectionNode extends Document {
|
||||
projectId: IProject["_id"];
|
||||
collectionNodeName: string;
|
||||
attributes: IAttributes[];
|
||||
isArchive: boolean;
|
||||
position: [number, number, number];
|
||||
}
|
||||
const attributeSchema = new Schema<IAttributes>({
|
||||
key: { type: String, required: true },
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"Date",
|
||||
"ObjectId",
|
||||
"Array",
|
||||
"Enum",
|
||||
"object",
|
||||
"any",
|
||||
],
|
||||
},
|
||||
required: { type: Boolean },
|
||||
refKey: { type: Object },
|
||||
default: { type: Schema.Types.Mixed },
|
||||
unique: { type: Boolean },
|
||||
index: { type: Boolean },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
});
|
||||
const collectionSchema: Schema<ICollectionNode> = new Schema(
|
||||
{
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
collectionNodeName: { type: String },
|
||||
position: { type: [Number], required: true },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
attributes: [attributeSchema],
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const collectionsModel = (db: any) => {
|
||||
return MainModel(db, "collectionNode", collectionSchema, "collectionNode");
|
||||
};
|
||||
export default collectionsModel;
|
||||
@@ -1,29 +1,29 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
interface IEdgeModel extends Document {
|
||||
projectId: IProject["_id"];
|
||||
from: { collection_id: string; field: string };
|
||||
to: { collection_id: string };
|
||||
cardinality: "one-to-one" | "one-to-many"|"many-to-many"
|
||||
isArchive: boolean;
|
||||
createdAt: number;
|
||||
|
||||
}
|
||||
const EdgeSchema = new Schema<IEdgeModel>({
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
|
||||
from: {
|
||||
collection_id: { type: String, required: true },
|
||||
field: { type: String, required: true },
|
||||
},
|
||||
to: {
|
||||
collection_id: { type: String, required: true },
|
||||
},
|
||||
cardinality: { type: String, 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) => {
|
||||
return MainModel(db, "edge", EdgeSchema, "edge");
|
||||
};
|
||||
export default edgeModel;
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
interface IEdgeModel extends Document {
|
||||
projectId: IProject["_id"];
|
||||
from: { collection_id: string; field: string };
|
||||
to: { collection_id: string };
|
||||
cardinality: "one-to-one" | "one-to-many"|"many-to-many"
|
||||
isArchive: boolean;
|
||||
createdAt: number;
|
||||
|
||||
}
|
||||
const EdgeSchema = new Schema<IEdgeModel>({
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true },
|
||||
from: {
|
||||
collection_id: { type: String, required: true },
|
||||
field: { type: String, required: true },
|
||||
},
|
||||
to: {
|
||||
collection_id: { type: String, required: true },
|
||||
},
|
||||
cardinality: { type: String, 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) => {
|
||||
return MainModel(db, "edge", EdgeSchema, "edge");
|
||||
};
|
||||
export default edgeModel;
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
interface Ifolders extends Document {
|
||||
folderName: string;
|
||||
createdAt: number;
|
||||
}
|
||||
const folderSchema: Schema = new Schema({
|
||||
folderName: { type: String, required: true },
|
||||
createdAt: { type: Date, default: Date.now },
|
||||
});
|
||||
export interface IMVCPrject extends Document {
|
||||
projectId: IProject["_id"];
|
||||
controllers: boolean;
|
||||
routes: boolean;
|
||||
models: boolean;
|
||||
services: boolean;
|
||||
middleware: boolean;
|
||||
utils: boolean;
|
||||
config: boolean;
|
||||
folders: Ifolders[];
|
||||
}
|
||||
const mvcSchema: Schema = new Schema({
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
controllers: { type: Boolean },
|
||||
routes: { type: Boolean },
|
||||
models: { type: Boolean },
|
||||
services: { type: Boolean },
|
||||
middleware: { type: Boolean },
|
||||
utils: { type: Boolean },
|
||||
config: { type: Boolean },
|
||||
folders: [folderSchema],
|
||||
});
|
||||
|
||||
const MVCarcModel = (db: any) => {
|
||||
return MainModel(db, "MVC", mvcSchema, "MVC");
|
||||
};
|
||||
export default MVCarcModel;
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
import { IProject } from "./projectmodel";
|
||||
interface Ifolders extends Document {
|
||||
folderName: string;
|
||||
createdAt: number;
|
||||
}
|
||||
const folderSchema: Schema = new Schema({
|
||||
folderName: { type: String, required: true },
|
||||
createdAt: { type: Date, default: Date.now },
|
||||
});
|
||||
export interface IMVCPrject extends Document {
|
||||
projectId: IProject["_id"];
|
||||
controllers: boolean;
|
||||
routes: boolean;
|
||||
models: boolean;
|
||||
services: boolean;
|
||||
middleware: boolean;
|
||||
utils: boolean;
|
||||
config: boolean;
|
||||
folders: Ifolders[];
|
||||
}
|
||||
const mvcSchema: Schema = new Schema({
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
controllers: { type: Boolean },
|
||||
routes: { type: Boolean },
|
||||
models: { type: Boolean },
|
||||
services: { type: Boolean },
|
||||
middleware: { type: Boolean },
|
||||
utils: { type: Boolean },
|
||||
config: { type: Boolean },
|
||||
folders: [folderSchema],
|
||||
});
|
||||
|
||||
const MVCarcModel = (db: any) => {
|
||||
return MainModel(db, "MVC", mvcSchema, "MVC");
|
||||
};
|
||||
export default MVCarcModel;
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
export interface IProject extends Document {
|
||||
projectName: string;
|
||||
appType: string;
|
||||
slug: string;
|
||||
isArchive: boolean;
|
||||
createdBy: string;
|
||||
description: string;
|
||||
members: [string];
|
||||
useableLanguage: string;
|
||||
typeOfDB: string;
|
||||
DBName: string;
|
||||
architecture: string;
|
||||
apiType: string;
|
||||
}
|
||||
const projectSchema: Schema = new Schema(
|
||||
{
|
||||
projectName: { type: String },
|
||||
appType:{type:String,enum:["Backend","Frontend"]},
|
||||
slug: { type: String },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
createdBy: { type: String },
|
||||
description: { type: String },
|
||||
DBName: { type: String },
|
||||
typeOfDB: { type: String },
|
||||
useableLanguage: { type: String },
|
||||
architecture: { type: String },
|
||||
apiType: {
|
||||
type: String,
|
||||
enum: ["RESTful", "SOAP", "GraphQL", "RPC", "WebSocket"],
|
||||
},
|
||||
members: { type: [String] },
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const ProjectType = (db: any) => {
|
||||
return MainModel(db, "Project", projectSchema, "Project");
|
||||
};
|
||||
export default ProjectType;
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../connection/connection";
|
||||
export interface IProject extends Document {
|
||||
projectName: string;
|
||||
appType: string;
|
||||
slug: string;
|
||||
isArchive: boolean;
|
||||
createdBy: string;
|
||||
description: string;
|
||||
members: [string];
|
||||
useableLanguage: string;
|
||||
typeOfDB: string;
|
||||
DBName: string;
|
||||
architecture: string;
|
||||
apiType: string;
|
||||
}
|
||||
const projectSchema: Schema = new Schema(
|
||||
{
|
||||
projectName: { type: String },
|
||||
appType:{type:String,enum:["Backend","Frontend"]},
|
||||
slug: { type: String },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
createdBy: { type: String },
|
||||
description: { type: String },
|
||||
DBName: { type: String },
|
||||
typeOfDB: { type: String },
|
||||
useableLanguage: { type: String },
|
||||
architecture: { type: String },
|
||||
apiType: {
|
||||
type: String,
|
||||
enum: ["RESTful", "SOAP", "GraphQL", "RPC", "WebSocket"],
|
||||
},
|
||||
members: { type: [String] },
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const ProjectType = (db: any) => {
|
||||
return MainModel(db, "Project", projectSchema, "Project");
|
||||
};
|
||||
export default ProjectType;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,293 +1,293 @@
|
||||
import ProjectType from "../../shared/model/projectmodel";
|
||||
import collectionsModel from "../model/collectionModel";
|
||||
import edgeModel from "../model/edgeModel";
|
||||
interface Iresponse {
|
||||
status: string;
|
||||
data?: any;
|
||||
}
|
||||
interface IEdge {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
from: { collection_id: string, field: string };
|
||||
to: { collection_id: string };
|
||||
cardinality: string
|
||||
}
|
||||
interface IAllEdge {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IEdgeDelete {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
edgeId: string;
|
||||
}
|
||||
interface Attribute {
|
||||
key: string;
|
||||
type: string;
|
||||
isArchive: boolean;
|
||||
|
||||
refKey?: {
|
||||
collection_id: any;
|
||||
fieldId: any;
|
||||
};
|
||||
|
||||
}
|
||||
export const edgecreation = async (
|
||||
data: IEdge
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, from, to, cardinality } = data;
|
||||
|
||||
try {
|
||||
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.collectionNodeName;
|
||||
const fieldName = from.field;
|
||||
|
||||
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) {
|
||||
console.log('error: ', error);
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const Alledges = async (
|
||||
data: IAllEdge
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, } = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
// createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
}
|
||||
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 (
|
||||
data: IEdgeDelete
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, edgeId } = data;
|
||||
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
// createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
}
|
||||
|
||||
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 => {
|
||||
if (!type) return "string"; // default
|
||||
if (typeof type === "string") {
|
||||
switch (type.toLowerCase()) {
|
||||
case "boolean":
|
||||
return "boolean";
|
||||
case "number":
|
||||
return "number";
|
||||
case "string":
|
||||
return "string";
|
||||
case "object":
|
||||
return "object";
|
||||
case "array":
|
||||
return "array";
|
||||
case "date":
|
||||
return "date";
|
||||
default:
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
|
||||
// Handle cases like [Number], Boolean, Object
|
||||
if (Array.isArray(type)) return "array";
|
||||
if (type === Boolean) return "boolean";
|
||||
if (type === Number) return "number";
|
||||
if (type === String) return "string";
|
||||
if (type === Object) return "object";
|
||||
|
||||
return "string"; // fallback
|
||||
import ProjectType from "../../shared/model/projectmodel";
|
||||
import collectionsModel from "../model/collectionModel";
|
||||
import edgeModel from "../model/edgeModel";
|
||||
interface Iresponse {
|
||||
status: string;
|
||||
data?: any;
|
||||
}
|
||||
interface IEdge {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
from: { collection_id: string, field: string };
|
||||
to: { collection_id: string };
|
||||
cardinality: string
|
||||
}
|
||||
interface IAllEdge {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IEdgeDelete {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
edgeId: string;
|
||||
}
|
||||
interface Attribute {
|
||||
key: string;
|
||||
type: string;
|
||||
isArchive: boolean;
|
||||
|
||||
refKey?: {
|
||||
collection_id: any;
|
||||
fieldId: any;
|
||||
};
|
||||
|
||||
}
|
||||
export const edgecreation = async (
|
||||
data: IEdge
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, from, to, cardinality } = data;
|
||||
|
||||
try {
|
||||
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.collectionNodeName;
|
||||
const fieldName = from.field;
|
||||
|
||||
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) {
|
||||
console.log('error: ', error);
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const Alledges = async (
|
||||
data: IAllEdge
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, } = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
// createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
}
|
||||
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 (
|
||||
data: IEdgeDelete
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId, edgeId } = data;
|
||||
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
// createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
}
|
||||
|
||||
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 => {
|
||||
if (!type) return "string"; // default
|
||||
if (typeof type === "string") {
|
||||
switch (type.toLowerCase()) {
|
||||
case "boolean":
|
||||
return "boolean";
|
||||
case "number":
|
||||
return "number";
|
||||
case "string":
|
||||
return "string";
|
||||
case "object":
|
||||
return "object";
|
||||
case "array":
|
||||
return "array";
|
||||
case "date":
|
||||
return "date";
|
||||
default:
|
||||
return "string";
|
||||
}
|
||||
}
|
||||
|
||||
// Handle cases like [Number], Boolean, Object
|
||||
if (Array.isArray(type)) return "array";
|
||||
if (type === Boolean) return "boolean";
|
||||
if (type === Number) return "number";
|
||||
if (type === String) return "string";
|
||||
if (type === Object) return "object";
|
||||
|
||||
return "string"; // fallback
|
||||
};
|
||||
@@ -1,185 +1,185 @@
|
||||
import MVCarcModel from "../../shared/model/mvcModel";
|
||||
import ProjectType from "../../shared/model/projectmodel";
|
||||
import collectionsModel from "../model/collectionModel";
|
||||
import edgeModel from "../model/edgeModel";
|
||||
interface Iresponse {
|
||||
status: string;
|
||||
data?: any;
|
||||
}
|
||||
interface IProject {
|
||||
useableLanguage: string;
|
||||
organization: string;
|
||||
projectName: string;
|
||||
userName: string;
|
||||
apiType: string;
|
||||
application: string;
|
||||
architecture: string;
|
||||
description: string;
|
||||
}
|
||||
interface IProjectstructure {
|
||||
projectId: string;
|
||||
organization: string;
|
||||
}
|
||||
export const projectCreationService = async (
|
||||
data: IProject
|
||||
): Promise<Iresponse> => {
|
||||
const {
|
||||
organization,
|
||||
projectName,
|
||||
useableLanguage,
|
||||
description,
|
||||
userName,
|
||||
apiType,
|
||||
application,
|
||||
architecture,
|
||||
} = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
projectName: projectName,
|
||||
createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingProject) {
|
||||
return { status: "Project Already Exists" };
|
||||
} else {
|
||||
if (architecture.toLowerCase() === "mvc") {
|
||||
const newProject = await ProjectType(organization).create({
|
||||
projectName,
|
||||
createdBy: userName,
|
||||
useableLanguage,
|
||||
architecture,
|
||||
apiType: apiType,
|
||||
appType: application,
|
||||
description,
|
||||
});
|
||||
if (!newProject) return { status: "Project creation unsuccessfull" };
|
||||
const existingProjectinMVC = await MVCarcModel(organization).findOne({
|
||||
projectId: newProject._id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProjectinMVC) {
|
||||
const MVCCreation = await MVCarcModel(organization).create({
|
||||
projectId: newProject._id,
|
||||
createdBy: userName,
|
||||
controllers: true,
|
||||
routes: true,
|
||||
models: true,
|
||||
services: true,
|
||||
middleware: true,
|
||||
utils: true,
|
||||
config: true,
|
||||
});
|
||||
const mvcData = MVCCreation.toObject();
|
||||
|
||||
const excludedKeys = [
|
||||
"projectId",
|
||||
"_id",
|
||||
"__v",
|
||||
"createdBy",
|
||||
"isArchive",
|
||||
"folders",
|
||||
];
|
||||
const folders = Object.keys(mvcData).filter(
|
||||
(key) => !excludedKeys.includes(key) && mvcData[key] === true
|
||||
);
|
||||
const createdFolders = folders.map((folderName) => ({
|
||||
folderName,
|
||||
createdAt: new Date(),
|
||||
}));
|
||||
|
||||
MVCCreation.folders.push(...createdFolders);
|
||||
await MVCCreation.save();
|
||||
return { status: "Success", data: newProject._id };
|
||||
} else {
|
||||
return {
|
||||
status: "Already MVC architecture assigned to this projectId",
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return { status: "New architecture" };
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const projectDatas = async (data: IProject): Promise<Iresponse> => {
|
||||
const { organization } = data;
|
||||
try {
|
||||
const projectDatas = await ProjectType(organization)
|
||||
.findOne({
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-__v -isArchive -createdAt -updatedAt");
|
||||
if (!projectDatas) return { status: "No project found" };
|
||||
return { status: "Success", data: projectDatas };
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const GetNodesInProject = async (
|
||||
data: IProjectstructure
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId } = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
} else {
|
||||
const collectionNodesdata = await collectionsModel(organization)
|
||||
.find({ projectId: projectId, isArchive: false })
|
||||
.select("collectionNodeName attributes position -_id ");
|
||||
const edgeNodes = await edgeModel(organization)
|
||||
.find({ projectId: projectId, isArchive: false })
|
||||
.select("cardinality from to");
|
||||
if(!edgeNodes) return {status:'No edge Nodes present',data:[]}
|
||||
if (!collectionNodesdata)
|
||||
return { status: "No collection Nodes present", data: [] };
|
||||
else {
|
||||
const collectionNodes = collectionNodesdata.map((collection) => ({
|
||||
position: collection.position,
|
||||
collectionNodeName: collection.collectionNodeName,
|
||||
attributes: collection.attributes
|
||||
.filter((attr: any) => !attr.isArchive)
|
||||
.map((attr: any) => {
|
||||
const { isArchive, ...rest } = attr.toObject();
|
||||
return { ...rest,edgeNodes };
|
||||
}),
|
||||
|
||||
}));
|
||||
return { status: "Success", data: {collectionNodes,edgeNodes} };
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
import MVCarcModel from "../../shared/model/mvcModel";
|
||||
import ProjectType from "../../shared/model/projectmodel";
|
||||
import collectionsModel from "../model/collectionModel";
|
||||
import edgeModel from "../model/edgeModel";
|
||||
interface Iresponse {
|
||||
status: string;
|
||||
data?: any;
|
||||
}
|
||||
interface IProject {
|
||||
useableLanguage: string;
|
||||
organization: string;
|
||||
projectName: string;
|
||||
userName: string;
|
||||
apiType: string;
|
||||
application: string;
|
||||
architecture: string;
|
||||
description: string;
|
||||
}
|
||||
interface IProjectstructure {
|
||||
projectId: string;
|
||||
organization: string;
|
||||
}
|
||||
export const projectCreationService = async (
|
||||
data: IProject
|
||||
): Promise<Iresponse> => {
|
||||
const {
|
||||
organization,
|
||||
projectName,
|
||||
useableLanguage,
|
||||
description,
|
||||
userName,
|
||||
apiType,
|
||||
application,
|
||||
architecture,
|
||||
} = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
projectName: projectName,
|
||||
createdBy: userName,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingProject) {
|
||||
return { status: "Project Already Exists" };
|
||||
} else {
|
||||
if (architecture.toLowerCase() === "mvc") {
|
||||
const newProject = await ProjectType(organization).create({
|
||||
projectName,
|
||||
createdBy: userName,
|
||||
useableLanguage,
|
||||
architecture,
|
||||
apiType: apiType,
|
||||
appType: application,
|
||||
description,
|
||||
});
|
||||
if (!newProject) return { status: "Project creation unsuccessfull" };
|
||||
const existingProjectinMVC = await MVCarcModel(organization).findOne({
|
||||
projectId: newProject._id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProjectinMVC) {
|
||||
const MVCCreation = await MVCarcModel(organization).create({
|
||||
projectId: newProject._id,
|
||||
createdBy: userName,
|
||||
controllers: true,
|
||||
routes: true,
|
||||
models: true,
|
||||
services: true,
|
||||
middleware: true,
|
||||
utils: true,
|
||||
config: true,
|
||||
});
|
||||
const mvcData = MVCCreation.toObject();
|
||||
|
||||
const excludedKeys = [
|
||||
"projectId",
|
||||
"_id",
|
||||
"__v",
|
||||
"createdBy",
|
||||
"isArchive",
|
||||
"folders",
|
||||
];
|
||||
const folders = Object.keys(mvcData).filter(
|
||||
(key) => !excludedKeys.includes(key) && mvcData[key] === true
|
||||
);
|
||||
const createdFolders = folders.map((folderName) => ({
|
||||
folderName,
|
||||
createdAt: new Date(),
|
||||
}));
|
||||
|
||||
MVCCreation.folders.push(...createdFolders);
|
||||
await MVCCreation.save();
|
||||
return { status: "Success", data: newProject._id };
|
||||
} else {
|
||||
return {
|
||||
status: "Already MVC architecture assigned to this projectId",
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return { status: "New architecture" };
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const projectDatas = async (data: IProject): Promise<Iresponse> => {
|
||||
const { organization } = data;
|
||||
try {
|
||||
const projectDatas = await ProjectType(organization)
|
||||
.findOne({
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-__v -isArchive -createdAt -updatedAt");
|
||||
if (!projectDatas) return { status: "No project found" };
|
||||
return { status: "Success", data: projectDatas };
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const GetNodesInProject = async (
|
||||
data: IProjectstructure
|
||||
): Promise<Iresponse> => {
|
||||
const { organization, projectId } = data;
|
||||
try {
|
||||
const existingProject = await ProjectType(organization).findOne({
|
||||
_id: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProject) {
|
||||
return { status: "project not found" };
|
||||
} else {
|
||||
const collectionNodesdata = await collectionsModel(organization)
|
||||
.find({ projectId: projectId, isArchive: false })
|
||||
.select("collectionNodeName attributes position -_id ");
|
||||
const edgeNodes = await edgeModel(organization)
|
||||
.find({ projectId: projectId, isArchive: false })
|
||||
.select("cardinality from to");
|
||||
if(!edgeNodes) return {status:'No edge Nodes present',data:[]}
|
||||
if (!collectionNodesdata)
|
||||
return { status: "No collection Nodes present", data: [] };
|
||||
else {
|
||||
const collectionNodes = collectionNodesdata.map((collection) => ({
|
||||
position: collection.position,
|
||||
collectionNodeName: collection.collectionNodeName,
|
||||
attributes: collection.attributes
|
||||
.filter((attr: any) => !attr.isArchive)
|
||||
.map((attr: any) => {
|
||||
const { isArchive, ...rest } = attr.toObject();
|
||||
return { ...rest,edgeNodes };
|
||||
}),
|
||||
|
||||
}));
|
||||
return { status: "Success", data: {collectionNodes,edgeNodes} };
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user