first commit
This commit is contained in:
2854
package-lock.json
generated
2854
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "new-folder",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "nodemon --exec tsx src/main.ts"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^2.2.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.0",
|
||||
"express": "^5.1.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"mongoose": "^8.16.3",
|
||||
"nodemon": "^3.1.10",
|
||||
"path": "^0.12.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.19",
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.0.14"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "new-folder",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "nodemon --exec tsx src/main.ts"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^2.2.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.0",
|
||||
"express": "^5.1.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"mongoose": "^8.16.3",
|
||||
"nodemon": "^3.1.10",
|
||||
"path": "^0.12.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.19",
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.0.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +1,101 @@
|
||||
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<any> => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
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<any> => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
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<IFileModel> = 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;
|
||||
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<IFileModel> = 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;
|
||||
|
||||
Reference in New Issue
Block a user