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",
|
"name": "new-folder",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "nodemon --exec tsx src/main.ts"
|
"start": "nodemon --exec tsx src/main.ts"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^2.2.0",
|
"body-parser": "^2.2.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^17.2.0",
|
"dotenv": "^17.2.0",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"mongoose": "^8.16.3",
|
"mongoose": "^8.16.3",
|
||||||
"nodemon": "^3.1.10",
|
"nodemon": "^3.1.10",
|
||||||
"path": "^0.12.7"
|
"path": "^0.12.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.19",
|
"@types/cors": "^2.8.19",
|
||||||
"@types/express": "^5.0.3",
|
"@types/express": "^5.0.3",
|
||||||
"@types/node": "^24.0.14"
|
"@types/node": "^24.0.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,101 +1,101 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import baseType from "../model/basemodel";
|
import baseType from "../model/basemodel";
|
||||||
import FileMode from "../model/fileModel";
|
import FileMode from "../model/fileModel";
|
||||||
export const fileModelCreatecontroller = async (
|
export const fileModelCreatecontroller = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
console.log("req.body: ", req.body);
|
console.log("req.body: ", req.body);
|
||||||
const {
|
const {
|
||||||
pathName,
|
pathName,
|
||||||
baseId,
|
baseId,
|
||||||
modelName,
|
modelName,
|
||||||
organization,
|
organization,
|
||||||
attributes,
|
attributes,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const findBaseName=await baseType(organization).findById(baseId)
|
const findBaseName=await baseType(organization).findById(baseId)
|
||||||
console.log('baseId: ', baseId);
|
console.log('baseId: ', baseId);
|
||||||
console.log('findBaseName: ', findBaseName);
|
console.log('findBaseName: ', findBaseName);
|
||||||
|
|
||||||
|
|
||||||
const attrToSchema = (attr: any) => {
|
const attrToSchema = (attr: any) => {
|
||||||
const mapType: any = {
|
const mapType: any = {
|
||||||
string: 'String',
|
string: 'String',
|
||||||
number: 'Number',
|
number: 'Number',
|
||||||
boolean: 'Boolean'
|
boolean: 'Boolean'
|
||||||
};
|
};
|
||||||
const lines = [];
|
const lines = [];
|
||||||
for (const [key, config] of Object.entries(attr)) {
|
for (const [key, config] of Object.entries(attr)) {
|
||||||
const line: string[] = [];
|
const line: string[] = [];
|
||||||
line.push(`${key}: {`);
|
line.push(`${key}: {`);
|
||||||
line.push(` type: ${mapType[(config as any).type] || 'String'},`);
|
line.push(` type: ${mapType[(config as any).type] || 'String'},`);
|
||||||
if ((config as any).required) line.push(` required: true,`);
|
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).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).minLength) line.push(` minlength: ${(config as any).minLength},`);
|
||||||
if ((config as any).maxLength) line.push(` maxlength: ${(config as any).maxLength},`);
|
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).min !== undefined) line.push(` min: ${(config as any).min},`);
|
||||||
if ((config as any).max !== undefined) line.push(` max: ${(config as any).max},`);
|
if ((config as any).max !== undefined) line.push(` max: ${(config as any).max},`);
|
||||||
line.push('},');
|
line.push('},');
|
||||||
lines.push(line.join('\n'));
|
lines.push(line.join('\n'));
|
||||||
}
|
}
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
};
|
};
|
||||||
const schemaCode = `
|
const schemaCode = `
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
const ${modelName}Schema = new mongoose.Schema({
|
const ${modelName}Schema = new mongoose.Schema({
|
||||||
${attrToSchema(attributes)}
|
${attrToSchema(attributes)}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema);
|
export const ${modelName} = mongoose.model('${modelName}', ${modelName}Schema);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const basePath = path.join(pathName, findBaseName.BaseName, "src","Models");
|
const basePath = path.join(pathName, findBaseName.BaseName, "src","Models");
|
||||||
const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`);
|
const modelFilePath = path.join(basePath, `${modelName}SchemaModel.ts`);
|
||||||
|
|
||||||
|
|
||||||
// Read all subfolders inside basePath
|
// Read all subfolders inside basePath
|
||||||
if (!fs.existsSync(basePath)) {
|
if (!fs.existsSync(basePath)) {
|
||||||
fs.mkdirSync(basePath, { recursive: true });
|
fs.mkdirSync(basePath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(modelFilePath, schemaCode.trim());
|
fs.writeFileSync(modelFilePath, schemaCode.trim());
|
||||||
|
|
||||||
return res.status(200).json({ message: 'Model file created successfully.' });
|
return res.status(200).json({ message: 'Model file created successfully.' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const folders = ["Controller", "Routes", "Models", "Services"];
|
// const folders = ["Controller", "Routes", "Models", "Services"];
|
||||||
|
|
||||||
|
|
||||||
// if (!fs.existsSync(basePath)) {
|
// if (!fs.existsSync(basePath)) {
|
||||||
// fs.mkdirSync(basePath, { recursive: true });
|
// fs.mkdirSync(basePath, { recursive: true });
|
||||||
// console.log(`Created root path: ${basePath}`);
|
// console.log(`Created root path: ${basePath}`);
|
||||||
// }
|
// }
|
||||||
// folders.forEach(async (folder) => {
|
// folders.forEach(async (folder) => {
|
||||||
// const fullPath = path.join(basePath, folder);
|
// const fullPath = path.join(basePath, folder);
|
||||||
// if (!fs.existsSync(fullPath)) {
|
// if (!fs.existsSync(fullPath)) {
|
||||||
// fs.mkdirSync(fullPath, { recursive: true });
|
// fs.mkdirSync(fullPath, { recursive: true });
|
||||||
// const BaseDataSave = await FileMode(organization).create({
|
// const BaseDataSave = await FileMode(organization).create({
|
||||||
// baseId,
|
// baseId,
|
||||||
// modelName,
|
// modelName,
|
||||||
// attributes,
|
// attributes,
|
||||||
|
|
||||||
// });
|
// });
|
||||||
// } else {
|
// } else {
|
||||||
// res.send(`Folder already exists: ${fullPath}`);
|
// res.send(`Folder already exists: ${fullPath}`);
|
||||||
// console.log(`Folder already exists: ${folder}`);
|
// console.log(`Folder already exists: ${folder}`);
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
res.send(error);
|
res.send(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
export interface IBase extends Document {
|
export interface IBase extends Document {
|
||||||
BaseName: string;
|
BaseName: string;
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
description: string;
|
description: string;
|
||||||
members: [string];
|
members: [string];
|
||||||
useableLanguage: string;
|
useableLanguage: string;
|
||||||
typeOfDB: string;
|
typeOfDB: string;
|
||||||
DBName: string;
|
DBName: string;
|
||||||
architecture: string;
|
architecture: string;
|
||||||
}
|
}
|
||||||
const baseSchema: Schema = new Schema({
|
const baseSchema: Schema = new Schema({
|
||||||
BaseName: { type: String },
|
BaseName: { type: String },
|
||||||
createdBy: { type: String },
|
createdBy: { type: String },
|
||||||
description: { type: String },
|
description: { type: String },
|
||||||
DBName: { type: String },
|
DBName: { type: String },
|
||||||
typeOfDB: { type: String },
|
typeOfDB: { type: String },
|
||||||
useableLanguage: { type: String },
|
useableLanguage: { type: String },
|
||||||
architecture: { type: String },
|
architecture: { type: String },
|
||||||
members: { type: [String] },
|
members: { type: [String] },
|
||||||
});
|
});
|
||||||
|
|
||||||
const baseType = (db: any) => {
|
const baseType = (db: any) => {
|
||||||
return MainModel(db, "Base", baseSchema, "Base");
|
return MainModel(db, "Base", baseSchema, "Base");
|
||||||
};
|
};
|
||||||
export default baseType;
|
export default baseType;
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../connection/connection";
|
import MainModel from "../connection/connection";
|
||||||
import { IBase } from "./basemodel";
|
import { IBase } from "./basemodel";
|
||||||
interface IFileModel extends Document {
|
interface IFileModel extends Document {
|
||||||
baseId: IBase["_id"];
|
baseId: IBase["_id"];
|
||||||
modelName: string;
|
modelName: string;
|
||||||
attributes: [];
|
attributes: [];
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
}
|
}
|
||||||
const baseFileModelSchema: Schema<IFileModel> = new Schema({
|
const baseFileModelSchema: Schema<IFileModel> = new Schema({
|
||||||
baseId: { type: Schema.Types.ObjectId, ref: "Base" },
|
baseId: { type: Schema.Types.ObjectId, ref: "Base" },
|
||||||
modelName: { type: String, required: true },
|
modelName: { type: String, required: true },
|
||||||
attributes: { type: [], required: true },
|
attributes: { type: [], required: true },
|
||||||
createdAt: { type: Number, default: Date.now() }
|
createdAt: { type: Number, default: Date.now() }
|
||||||
});
|
});
|
||||||
|
|
||||||
const FileMode = (db: any) => {
|
const FileMode = (db: any) => {
|
||||||
return MainModel(db, "Model", baseFileModelSchema, "Modle");
|
return MainModel(db, "Model", baseFileModelSchema, "Modle");
|
||||||
};
|
};
|
||||||
export default FileMode;
|
export default FileMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user