From 3c93c1b3b4ea6516c30bfa3e1db10d632b6d8129 Mon Sep 17 00:00:00 2001 From: Nivetharamesh Date: Tue, 26 Aug 2025 12:17:29 +0530 Subject: [PATCH] api and socket folder created models updated --- BaseFE/home.html | 132 -------- package.json | 2 +- src/BaseModel/controller/controller.ts | 50 --- .../controller/fileModelController.ts | 101 ------ src/BaseModel/model/basemodel.ts | 27 -- src/BaseModel/model/fileModel.ts | 20 -- src/api-server/controller/controller.ts | 302 ++++++++++++++++++ .../controller/fileModelController.ts | 98 ++++++ src/{ => api-server}/main.ts | 24 +- .../routes/routes.ts | 14 +- .../connection/connection.ts | 100 +++--- src/shared/fsafdsa | 0 src/shared/model/collectionModel.ts | 24 ++ src/shared/model/mvcModel.ts | 41 +++ src/shared/model/projectmodel.ts | 36 +++ 15 files changed, 571 insertions(+), 400 deletions(-) delete mode 100644 BaseFE/home.html delete mode 100644 src/BaseModel/controller/controller.ts delete mode 100644 src/BaseModel/controller/fileModelController.ts delete mode 100644 src/BaseModel/model/basemodel.ts delete mode 100644 src/BaseModel/model/fileModel.ts create mode 100644 src/api-server/controller/controller.ts create mode 100644 src/api-server/controller/fileModelController.ts rename src/{ => api-server}/main.ts (81%) rename src/{BaseModel => api-server}/routes/routes.ts (55%) rename src/{BaseModel => shared}/connection/connection.ts (96%) create mode 100644 src/shared/fsafdsa create mode 100644 src/shared/model/collectionModel.ts create mode 100644 src/shared/model/mvcModel.ts create mode 100644 src/shared/model/projectmodel.ts diff --git a/BaseFE/home.html b/BaseFE/home.html deleted file mode 100644 index f9d12b3..0000000 --- a/BaseFE/home.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - Database Configuration Form - - - -

Database Configuration

-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- - -
- - - diff --git a/package.json b/package.json index 142828a..c0eedce 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon --exec tsx src/main.ts" + "start:api": "nodemon --exec tsx src/api-server/main.ts" }, "author": "", "license": "ISC", diff --git a/src/BaseModel/controller/controller.ts b/src/BaseModel/controller/controller.ts deleted file mode 100644 index a6e4d20..0000000 --- a/src/BaseModel/controller/controller.ts +++ /dev/null @@ -1,50 +0,0 @@ -import fs from "node:fs"; -import { Request, Response } from "express"; -import path from "path"; -import baseType from "../model/basemodel"; -export const createcontroller = async ( - req: Request, - res: Response -): Promise => { - console.log("req.bod: ", req.body); - const { - pathName, - organization, - BaseName, - useableLanguage, - typeOfDB, - DBName, - userName, - architecture, - } = req.body; - console.log('req.body: ', req.body); - - try { - const basePath = path.join(pathName, BaseName, "src"); - 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 baseType(organization).create({ - organization, - BaseName, - useableLanguage, - typeOfDB, - DBName, - createdBy: userName, - architecture, - }); - } else { - res.send(`Folder already exists: ${fullPath}`); - console.log(`Folder already exists: ${folder}`); - } - }); - } catch (error: unknown) { - res.send(error); - } -}; diff --git a/src/BaseModel/controller/fileModelController.ts b/src/BaseModel/controller/fileModelController.ts deleted file mode 100644 index 8d4d24a..0000000 --- a/src/BaseModel/controller/fileModelController.ts +++ /dev/null @@ -1,101 +0,0 @@ -import fs from "node:fs"; -import { Request, Response } from "express"; -import path from "path"; -import baseType from "../model/basemodel"; -import FileMode from "../model/fileModel"; -export const fileModelCreatecontroller = async ( - req: Request, - res: Response -): Promise => { - console.log("req.body: ", req.body); - const { - pathName, - baseId, - modelName, - organization, - attributes, - } = req.body; - - try { -const findBaseName=await baseType(organization).findById(baseId) -console.log('baseId: ', baseId); -console.log('findBaseName: ', findBaseName); - - - 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); - } -}; diff --git a/src/BaseModel/model/basemodel.ts b/src/BaseModel/model/basemodel.ts deleted file mode 100644 index cfaf3fb..0000000 --- a/src/BaseModel/model/basemodel.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -export interface IBase extends Document { - BaseName: string; - createdBy: string; - description: string; - members: [string]; - useableLanguage: string; - typeOfDB: string; - DBName: string; - architecture: string; -} -const baseSchema: Schema = new Schema({ - BaseName: { type: String }, - createdBy: { type: String }, - description: { type: String }, - DBName: { type: String }, - typeOfDB: { type: String }, - useableLanguage: { type: String }, - architecture: { type: String }, - members: { type: [String] }, -}); - -const baseType = (db: any) => { - return MainModel(db, "Base", baseSchema, "Base"); -}; -export default baseType; diff --git a/src/BaseModel/model/fileModel.ts b/src/BaseModel/model/fileModel.ts deleted file mode 100644 index 4b95acf..0000000 --- a/src/BaseModel/model/fileModel.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Schema, Document } from "mongoose"; -import MainModel from "../connection/connection"; -import { IBase } from "./basemodel"; -interface IFileModel extends Document { - baseId: IBase["_id"]; - modelName: string; - attributes: []; - createdAt: number; -} -const baseFileModelSchema: Schema = new Schema({ - baseId: { type: Schema.Types.ObjectId, ref: "Base" }, - modelName: { type: String, required: true }, - attributes: { type: [], required: true }, - createdAt: { type: Number, default: Date.now() } -}); - -const FileMode = (db: any) => { - return MainModel(db, "Model", baseFileModelSchema, "Modle"); -}; -export default FileMode; diff --git a/src/api-server/controller/controller.ts b/src/api-server/controller/controller.ts new file mode 100644 index 0000000..8105ac4 --- /dev/null +++ b/src/api-server/controller/controller.ts @@ -0,0 +1,302 @@ +import fs from "node:fs"; +import { Request, Response } from "express"; +import path from "path"; +import MVCarcModel from "../../shared/model/mvcModel"; +import ProjectType from "../../shared/model/projectmodel"; +export const createcontroller = async ( + req: Request, + res: Response +): Promise => { + const { + pathName, + organization, + BaseName, + useableLanguage, + typeOfDB, + DBName, + userName, + architecture, + } = req.body; + + try { + const existing = await ProjectType(organization).findOne({ + createdBy: userName, + DBName: DBName, + typeOfDB: typeOfDB, + useableLanguage: useableLanguage, + architecture: architecture.toLowerCase(), + }); + if (existing) { + return res.status(403).json({ + message: "Project Already Exists", + }); + } else { + if (architecture.toLowerCase() === "mvc") { + const basePath = path.join(pathName, BaseName, "src"); + let folders: any[]; + const existingMvcForBase = await MVCarcModel(organization).findOne({ + BaseName: BaseName, + architecture: architecture.toLowerCase(), + }); + if (!existingMvcForBase) { + const getUniqueBasePath = ( + pathName: string, + BaseName: string + ): { finalBaseName: string; fullPath: string } => { + let counter = 0; + let newBaseName = BaseName; + let fullPath = path.join(pathName, newBaseName, "src"); + if (fs.existsSync(basePath)) { + counter++; + newBaseName = `${BaseName}-${counter}`; + fullPath = path.join(pathName, newBaseName, "src"); + } + + return { finalBaseName: newBaseName, fullPath }; + }; + const folderStructureFunction = async ( + folders: string[], + rootPath: string + ): Promise => { + const folderStatus: string[] = []; + for (const folder of folders) { + const fullPath = path.join(rootPath, folder); + if (!fs.existsSync(fullPath)) { + fs.mkdirSync(fullPath, { recursive: true }); + folderStatus.push(`Created: ${folder}`); + console.log("folder: ", folder); + BaseDataSave.folderNames.push(folder); + await BaseDataSave.save(); + } else { + folderStatus.push(`Already exists: ${folder}`); + } + } + return folderStatus; + }; + const mainFileCreate = async (rootPath: string): Promise => { + const mainfile = path.join(rootPath, "app.ts"); + try { + await fs.promises.access(rootPath); + } catch { + await fs.promises.mkdir(rootPath, { recursive: true }); + } + try { + await fs.promises.access(mainfile); + return res + .status(200) + .json({ message: "Model file already exists in this name" }); + } catch { + await fs.promises.writeFile(mainfile, ""); + } + }; + let folderStatus: string[] = []; + let basicName: string; + let rootPath: string; + if (fs.existsSync(basePath)) { + let { finalBaseName, fullPath } = getUniqueBasePath( + pathName, + BaseName + ); + basicName = finalBaseName; + rootPath = fullPath; + fs.mkdirSync(fullPath, { recursive: true }); + mainFileCreate(rootPath); + } else { + basicName = BaseName; + rootPath = basePath; + fs.mkdirSync(basePath, { recursive: true }); + mainFileCreate(rootPath); + } + let BaseDataSave = await ProjectType(organization).create({ + organization, + BaseName: basicName, + useableLanguage, + typeOfDB, + DBName, + createdBy: userName, + architecture: architecture.toLowerCase(), + }); + const MVCCreation = await MVCarcModel(organization).create({ + BaseName: basicName, + baseId: BaseDataSave._id, + createdBy: userName, + controllers: true, + routes: true, + models: true, + services: true, + middleware: true, + utils: true, + config: true, + }); + const mvcData = MVCCreation.toObject(); + + const excludedKeys = ["baseId", "_id", "__v"]; + const folders = Object.keys(mvcData).filter( + (key) => !excludedKeys.includes(key) && mvcData[key] === true + ); + + folderStatus = await folderStructureFunction(folders, rootPath); + return res.status(201).json({ + message: "Base structure created successfully", + folderStatus, + }); + } + } else { + console.log("New Architecture flow"); + } + } + } catch (error: unknown) { + res.send("error"); + } +}; + +// export const createcontroller = async ( +// req: Request, +// res: Response +// ): Promise => { +// const { +// pathName, +// organization, +// BaseName, +// useableLanguage, +// typeOfDB, +// DBName, +// userName, +// architecture, +// } = req.body; + +// try { +// const existing = await ProjectType(organization).findOne({ +// createdBy: userName, +// DBName: DBName, +// typeOfDB: typeOfDB, +// useableLanguage: useableLanguage, +// architecture: architecture.toLowerCase(), +// }); +// if (existing) { +// return res.status(403).json({ +// message: "Project Already Exists", +// }); +// } else { +// if (architecture.toLowerCase() === "mvc") { +// const basePath = path.join(pathName, BaseName, "src"); +// let folders: any[]; +// const existingMvcForBase = await MVCarcModel(organization).findOne({ +// BaseName: BaseName, +// architecture: architecture.toLowerCase(), +// }); +// if (!existingMvcForBase) { +// const getUniqueBasePath = ( +// pathName: string, +// BaseName: string +// ): { finalBaseName: string; fullPath: string } => { +// let counter = 0; +// let newBaseName = BaseName; +// let fullPath = path.join(pathName, newBaseName, "src"); +// if (fs.existsSync(basePath)) { +// counter++; +// newBaseName = `${BaseName}-${counter}`; +// fullPath = path.join(pathName, newBaseName, "src"); +// } + +// return { finalBaseName: newBaseName, fullPath }; +// }; +// const folderStructureFunction = async ( +// folders: string[], +// rootPath: string +// ): Promise => { +// const folderStatus: string[] = []; +// for (const folder of folders) { +// const fullPath = path.join(rootPath, folder); +// if (!fs.existsSync(fullPath)) { +// fs.mkdirSync(fullPath, { recursive: true }); +// folderStatus.push(`Created: ${folder}`); +// console.log("folder: ", folder); +// BaseDataSave.folderNames.push(folder); +// await BaseDataSave.save(); +// } else { +// folderStatus.push(`Already exists: ${folder}`); +// } +// } +// return folderStatus; +// }; +// const mainFileCreate = async (rootPath: string): Promise => { +// const mainfile = path.join(rootPath, "app.ts"); +// try { +// await fs.promises.access(rootPath); +// } catch { +// await fs.promises.mkdir(rootPath, { recursive: true }); +// } +// try { +// await fs.promises.access(mainfile); +// return res +// .status(200) +// .json({ message: "Model file already exists in this name" }); +// } catch { +// await fs.promises.writeFile(mainfile, ""); +// } +// }; +// let folderStatus: string[] = []; +// let basicName: string; +// let rootPath: string; +// if (fs.existsSync(basePath)) { +// let { finalBaseName, fullPath } = getUniqueBasePath( +// pathName, +// BaseName +// ); +// basicName = finalBaseName; +// rootPath = fullPath; +// fs.mkdirSync(fullPath, { recursive: true }); +// mainFileCreate(rootPath); +// } else { +// basicName = BaseName; +// rootPath = basePath; +// fs.mkdirSync(basePath, { recursive: true }); +// mainFileCreate(rootPath); +// } +// let BaseDataSave = await ProjectType(organization).create({ +// organization, +// BaseName: basicName, +// useableLanguage, +// typeOfDB, +// DBName, +// createdBy: userName, +// architecture: architecture.toLowerCase(), +// }); +// const MVCCreation = await MVCarcModel(organization).create({ +// BaseName: basicName, +// baseId: BaseDataSave._id, +// createdBy: userName, +// controllers: true, +// routes: true, +// models: true, +// services: true, +// middleware: true, +// utils: true, +// config: true, +// }); +// const mvcData = MVCCreation.toObject(); + +// const excludedKeys = [ +// "baseId", +// "_id", +// "__v", +// ]; +// const folders = Object.keys(mvcData).filter( +// (key) => !excludedKeys.includes(key) && mvcData[key] === true +// ); + +// folderStatus = await folderStructureFunction(folders, rootPath); +// return res.status(201).json({ +// message: "Base structure created successfully", +// folderStatus, +// }); +// } +// } else { +// console.log("New Architecture flow"); +// } +// } +// } catch (error: unknown) { +// res.send("error"); +// } +// }; diff --git a/src/api-server/controller/fileModelController.ts b/src/api-server/controller/fileModelController.ts new file mode 100644 index 0000000..76096b5 --- /dev/null +++ b/src/api-server/controller/fileModelController.ts @@ -0,0 +1,98 @@ +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 => { + console.log("req.body: ", req.body); + const { pathName, baseId, modelName, organization, attributes } = req.body; + + try { + const findBaseName = await baseType(organization).findById(baseId); + console.log("baseId: ", baseId); + console.log("findBaseName: ", findBaseName); + + 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); + } +}; diff --git a/src/main.ts b/src/api-server/main.ts similarity index 81% rename from src/main.ts rename to src/api-server/main.ts index 4a71f8e..ae41058 100644 --- a/src/main.ts +++ b/src/api-server/main.ts @@ -1,12 +1,12 @@ -import express from "express"; -const app = express(); -import appRoutes from "./BaseModel/routes/routes"; -import bodyParser from "body-parser"; -import cors from "cors"; -app.use(bodyParser.json()); -app.use(cors()); -app.use(appRoutes); -const port = 9696; -app.listen(port, () => { - console.log(`Port is running on the ${port}`); -}); +import express from "express"; +const app = express(); +import appRoutes from "../api-server/routes/routes"; +import bodyParser from "body-parser"; +import cors from "cors"; +app.use(bodyParser.json()); +app.use(cors()); +app.use(appRoutes); +const port = 9696; +app.listen(port, () => { + console.log(`Port is running on the ${port}`); +}); diff --git a/src/BaseModel/routes/routes.ts b/src/api-server/routes/routes.ts similarity index 55% rename from src/BaseModel/routes/routes.ts rename to src/api-server/routes/routes.ts index 1a49974..6681b73 100644 --- a/src/BaseModel/routes/routes.ts +++ b/src/api-server/routes/routes.ts @@ -1,8 +1,8 @@ -import express from "express"; -import { createcontroller } from "../controller/controller"; -import { fileModelCreatecontroller } from "../controller/fileModelController"; -const appRoutes = express.Router(); - -appRoutes.post("/createfolder", createcontroller); -appRoutes.post("/createfileModel", fileModelCreatecontroller); +import express from "express"; +import { createcontroller } from "../../api-server/controller/controller"; +import { fileModelCreatecontroller } from "../../api-server/controller/fileModelController"; +const appRoutes = express.Router(); + +appRoutes.post("/createfolder", createcontroller); +appRoutes.post("/createfileModel", fileModelCreatecontroller); export default appRoutes \ No newline at end of file diff --git a/src/BaseModel/connection/connection.ts b/src/shared/connection/connection.ts similarity index 96% rename from src/BaseModel/connection/connection.ts rename to src/shared/connection/connection.ts index 5db917e..6a76248 100644 --- a/src/BaseModel/connection/connection.ts +++ b/src/shared/connection/connection.ts @@ -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 = ( - db: string, - modelName: string, - schema: Schema, - collectionName: string -): Model => { - 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(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(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 = ( + db: string, + modelName: string, + schema: Schema, + collectionName: string +): Model => { + 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(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(modelName, schema, collectionName); + } catch (error) { + console.error("Database connection error:", (error as Error).message); + throw error; + } +}; + +export default MainModel; diff --git a/src/shared/fsafdsa b/src/shared/fsafdsa new file mode 100644 index 0000000..e69de29 diff --git a/src/shared/model/collectionModel.ts b/src/shared/model/collectionModel.ts new file mode 100644 index 0000000..fd88dfc --- /dev/null +++ b/src/shared/model/collectionModel.ts @@ -0,0 +1,24 @@ +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +import { IProject } from "./projectmodel"; +interface IFileModel extends Document { + projectId: IProject["_id"]; + collectionNodeName: string; + attributes: []; + createdAt: number; + isArchive: boolean; + position: [number, number, number]; +} +const collectionSchema: Schema = new Schema({ + projectId: { type: Schema.Types.ObjectId, ref: "Project" }, + collectionNodeName: { type: String, required: true }, + position: { type: [Number], required: true }, + isArchive: { type: Boolean, default: false }, + attributes: { type: [], required: true }, + createdAt: { type: Number, default: Date.now() }, +}); + +const collectionsModel = (db: any) => { + return MainModel(db, "collectionNode", collectionSchema, "collectionNode"); +}; +export default collectionsModel; diff --git a/src/shared/model/mvcModel.ts b/src/shared/model/mvcModel.ts new file mode 100644 index 0000000..cd0ba95 --- /dev/null +++ b/src/shared/model/mvcModel.ts @@ -0,0 +1,41 @@ +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 }, + }, + { _id: false } +); +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, "MVCArc", mvcSchema, "MVCArc"); +}; +export default MVCarcModel; diff --git a/src/shared/model/projectmodel.ts b/src/shared/model/projectmodel.ts new file mode 100644 index 0000000..97dac12 --- /dev/null +++ b/src/shared/model/projectmodel.ts @@ -0,0 +1,36 @@ +import { Schema, Document } from "mongoose"; +import MainModel from "../connection/connection"; +export interface IProject extends Document { + projectName: string; + slug: string; + isArchive: boolean; + createdBy: string; + description: string; + members: [string]; + useableLanguage: string; + typeOfDB: string; + DBName: string; + architecture: string; +} +const projectSchema: Schema = new Schema( + { + projectName: { type: String }, + 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 }, + members: { type: [String] }, + }, + { + timestamps: true, + } +); + +const ProjectType = (db: any) => { + return MainModel(db, "Project", projectSchema, "Project"); +}; +export default ProjectType;