jcc-express-mvc 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Command-Line/NodeArtisanCommand.js +93 -0
- package/Command-Line/NodeTinker/db/index.js +17 -0
- package/{src/command-line-interface → Command-Line/NodeTinker}/getInput.js +1 -1
- package/{src/command-line-interface → Command-Line/NodeTinker}/index.js +11 -7
- package/{src/command-line-interface/commands.js → Command-Line/command.js} +53 -26
- package/Command-Line/files/Controller.js +76 -0
- package/Command-Line/files/Migration.js +17 -0
- package/Command-Line/files/Models.js +20 -0
- package/Command-Line/files/Request.js +32 -0
- package/Command-Line/files/ResourcesController.js +77 -0
- package/Command-Line/utils.js +11 -0
- package/Database/src/BaseEntity.ts +247 -0
- package/Database/src/BaseModel.ts +51 -0
- package/Database/src/Builder.ts +498 -0
- package/Database/src/Cast/index.ts +126 -0
- package/Database/src/Cast/types.ts +24 -0
- package/Database/src/Date/index.ts +52 -0
- package/Database/src/Model.ts +55 -0
- package/Database/src/Query.ts +13 -0
- package/Database/src/QueryBuilder.ts +426 -0
- package/Database/src/QueryInstance.ts +28 -0
- package/Database/src/RelationBuilder.ts +119 -0
- package/Database/src/Schema/BaseSchemaEntity/index.ts +32 -0
- package/Database/src/Schema/BluePrint/index.ts +287 -0
- package/Database/src/Schema/index.ts +15 -0
- package/Database/src/Schema/migrationContent.js +19 -0
- package/Database/src/db/connection.ts +17 -0
- package/Database/src/type.ts +18 -0
- package/Database/src/utils/index.ts +122 -0
- package/index.ts +36 -0
- package/lib/App.ts +46 -0
- package/lib/Auth/AuthMiddleware.ts +47 -0
- package/{src/Auth/index.js → lib/Auth/index.ts} +33 -12
- package/lib/Config/Config.ts +17 -0
- package/lib/Error/AppError.ts +11 -0
- package/lib/Error/AppErrorHandler.ts +41 -0
- package/lib/Error/Constants/error.ts +23 -0
- package/lib/Error/Constants/index.ts +5 -0
- package/{src/error → lib/Error}/public/pageNotFound.html +1 -1
- package/lib/HttpKernel/HttpKernel.ts +12 -0
- package/lib/Interface/index.ts +39 -0
- package/lib/Middlewares/index.ts +125 -0
- package/{src/middlware/isLogin.js → lib/Middlewares/isLogin.ts} +6 -6
- package/lib/Passport/config.ts +74 -0
- package/{src/request/FormRequest.js → lib/Request/FormRequest.ts} +13 -21
- package/lib/Request/request.ts +44 -0
- package/{src/response/index.js → lib/Response/index.ts} +9 -7
- package/lib/Routes/RouteBuilder.ts +133 -0
- package/lib/Routes/Router.ts +145 -0
- package/lib/Server/index.ts +40 -0
- package/lib/Services/ServiceContainer.ts +34 -0
- package/lib/Services/ServiceProvider.ts +58 -0
- package/{src/templating-engine/utils.js → lib/Templating-engine/engineHelper.ts} +29 -33
- package/lib/Templating-engine/expressions.ts +18 -0
- package/{src/templating-engine/index.js → lib/Templating-engine/index.ts} +60 -93
- package/lib/Type/index.ts +28 -0
- package/lib/Validation/index.ts +96 -0
- package/lib/Validation/rules.ts +107 -0
- package/{src/validation/method.js → lib/Validation/validate.ts} +75 -54
- package/{src/helpers.js → lib/util/index.ts} +72 -32
- package/package.json +1 -1
- package/README.md +0 -0
- package/index.js +0 -1
- package/src/Auth/protectedRoute.js +0 -41
- package/src/Router/Router.js +0 -113
- package/src/Router/Routes.js +0 -54
- package/src/app/index.js +0 -83
- package/src/command-line-interface/db.js +0 -20
- package/src/command-line-interface/getCommands.js +0 -94
- package/src/dbConnection/index.js +0 -14
- package/src/error/AppError.js +0 -8
- package/src/error/ErrorHandler.js +0 -88
- package/src/files/controller.js +0 -67
- package/src/files/model.js +0 -14
- package/src/files/request.js +0 -28
- package/src/files/resoucesController.js +0 -72
- package/src/index.js +0 -44
- package/src/middlware/index.js +0 -114
- package/src/passport/config.js +0 -59
- package/src/request/index.js +0 -38
- package/src/socket/index.js +0 -26
- package/src/utils/index.js +0 -149
- package/src/validation/index.js +0 -87
- package/src/validation/rules.js +0 -110
- /package/{src/command-line-interface/REPL.js → Command-Line/NodeTinker/repl.js} +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const runCommand = require("./command");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Function to parse command line arguments and execute corresponding commands
|
|
5
|
+
@param {commandArg} commandArg -string
|
|
6
|
+
@returns {any} -any
|
|
7
|
+
* */
|
|
8
|
+
const NodeArtisanCommand = (commandArg = []) => {
|
|
9
|
+
let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
|
|
10
|
+
let command = commandArg[index].split(":")[1];
|
|
11
|
+
// If the command is for creating an API controller with resources
|
|
12
|
+
if (
|
|
13
|
+
commandArg.length === index + 4 &&
|
|
14
|
+
(command === "apiController" || command === "ApiController") &&
|
|
15
|
+
(commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")
|
|
16
|
+
) {
|
|
17
|
+
runCommand.addModel(commandArg[2]); // Add a model with the provided name
|
|
18
|
+
return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If the command is for creating a web controller with resources
|
|
22
|
+
if (
|
|
23
|
+
commandArg.length === 4 &&
|
|
24
|
+
(command === "controller" || command === "Controller") &&
|
|
25
|
+
(commandArg[3] === "--resources" || commandArg[3] === "-r")
|
|
26
|
+
) {
|
|
27
|
+
runCommand.addModel(commandArg[2]); // Add a model with the provided name
|
|
28
|
+
return runCommand.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If the command is for creating an admin controller with resources
|
|
32
|
+
|
|
33
|
+
// If the command is for creating a web controller
|
|
34
|
+
if (
|
|
35
|
+
commandArg.length === index + 3 &&
|
|
36
|
+
(command === "controller" || command === "Controller")
|
|
37
|
+
) {
|
|
38
|
+
return runCommand.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If the command is for creating an API controller
|
|
42
|
+
if (
|
|
43
|
+
commandArg.length === index + 3 &&
|
|
44
|
+
(command === "apiController" || command === "ApiController")
|
|
45
|
+
) {
|
|
46
|
+
return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If the command is for creating a model
|
|
50
|
+
if (
|
|
51
|
+
commandArg.length === index + 2 &&
|
|
52
|
+
(command === "model" || command === "Model")
|
|
53
|
+
) {
|
|
54
|
+
return runCommand.addModel(commandArg[index + 1]); // Add a model
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If the command is for creating a web controller without specifying a model
|
|
58
|
+
if (
|
|
59
|
+
commandArg.length === index + 2 &&
|
|
60
|
+
(command === "controller" || command === "Controller")
|
|
61
|
+
) {
|
|
62
|
+
return runCommand.addWeb(commandArg[index + 1], false); // Add a web controller without a model
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// If the command is for creating an API controller without specifying a model
|
|
66
|
+
if (
|
|
67
|
+
commandArg.length === index + 2 &&
|
|
68
|
+
(command === "apiController" || command === "ApiController")
|
|
69
|
+
) {
|
|
70
|
+
return runCommand.addApi(commandArg[index + 1], false); // Add an API controller without a model
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If the command is for creating a request file
|
|
74
|
+
if (
|
|
75
|
+
commandArg.length === index + 2 &&
|
|
76
|
+
(command === "Request" || command === "request")
|
|
77
|
+
) {
|
|
78
|
+
return runCommand.addRequest(commandArg[index + 1]); // Add a request file
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// If the command is for creating a request file
|
|
82
|
+
if (
|
|
83
|
+
commandArg.length === index + 2 &&
|
|
84
|
+
(command === "Migration" || command === "migration")
|
|
85
|
+
) {
|
|
86
|
+
return runCommand.addMigration(commandArg[index + 1]); // Add a request file
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If the command is not recognized, display "Command not found"
|
|
90
|
+
return runCommand.notFound();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = NodeArtisanCommand;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const mysql = require("mysql2/promise.js");
|
|
2
|
+
class Database {
|
|
3
|
+
async connect() {
|
|
4
|
+
return await mysql.createConnection({
|
|
5
|
+
host: process.env.DB_HOST || "",
|
|
6
|
+
user: process.env.DB_USERNAME,
|
|
7
|
+
password: process.env.DB_PASSWORD,
|
|
8
|
+
database: process.env.DB_DATABASE,
|
|
9
|
+
port: Number(process.env.DB_PORT) || 0,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async runQuery(sqlQuery) {
|
|
14
|
+
const [results] = await (await this.connect()).query(sqlQuery);
|
|
15
|
+
return results;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
const
|
|
2
|
-
const Database = require("./db");
|
|
1
|
+
const appRootPath = require("app-root-path").path;
|
|
3
2
|
|
|
4
|
-
class TinkerNode
|
|
3
|
+
class TinkerNode {
|
|
5
4
|
#allowedMethodsRegex = /[^\s{}()\[\]\(\)0-9a-zA-Z',_.:@]/g;
|
|
6
5
|
|
|
6
|
+
getModel(file) {
|
|
7
|
+
return require(`${appRootPath}/app/Models/${file}`);
|
|
8
|
+
}
|
|
9
|
+
|
|
7
10
|
sanitizedInput(input) {
|
|
8
11
|
return input.replace(this.#allowedMethodsRegex, "");
|
|
9
12
|
}
|
|
@@ -20,26 +23,27 @@ class TinkerNode extends Database {
|
|
|
20
23
|
throw new Error("Invalid Mongoose query:", input);
|
|
21
24
|
}
|
|
22
25
|
const model = data[0];
|
|
23
|
-
|
|
24
26
|
data.splice(0, 1);
|
|
25
|
-
|
|
26
27
|
return { model, methods: data.join(".") };
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
async extractCommand(input) {
|
|
30
31
|
try {
|
|
31
32
|
const { model, methods } = this.validatedInput(input);
|
|
33
|
+
|
|
34
|
+
return console.log(this.getModel(`${model}.ts`));
|
|
35
|
+
|
|
32
36
|
const queryFunction = new Function(
|
|
33
37
|
"model",
|
|
34
38
|
"getModel",
|
|
35
39
|
`
|
|
36
40
|
const modelName = getModel(model)
|
|
37
41
|
return modelName.${methods}
|
|
38
|
-
|
|
42
|
+
`,
|
|
39
43
|
);
|
|
40
44
|
|
|
41
45
|
this.connect();
|
|
42
|
-
return queryFunction(model, getModel);
|
|
46
|
+
return queryFunction(model, this.getModel);
|
|
43
47
|
} catch (error) {
|
|
44
48
|
return console.error("Error " + error?.message);
|
|
45
49
|
}
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
const path = require("path");
|
|
2
2
|
const fs = require("fs");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
3
|
+
const appRootPath = require("app-root-path");
|
|
4
|
+
const createController = require("./files/Controller");
|
|
5
|
+
const createModel = require("./files/Models");
|
|
6
|
+
const resourceController = require("./files/ResourcesController");
|
|
7
|
+
const createRequest = require("./files/Request");
|
|
8
|
+
const createMigration = require("./files/Migration");
|
|
8
9
|
const colors = require("colors"); // Module for adding color to console output
|
|
10
|
+
const { formatDate } = require("./utils");
|
|
11
|
+
|
|
12
|
+
const rootPath = appRootPath.path;
|
|
9
13
|
|
|
10
14
|
class Command {
|
|
11
15
|
// Method to add a web controller
|
|
12
16
|
addWeb(controllerName, modelName = false) {
|
|
13
17
|
try {
|
|
14
|
-
let webControllerPath = path.resolve(`${rootPath}/app/Controllers`); // Resolve path to web controllers directory
|
|
15
|
-
if (fs.existsSync(`${webControllerPath}/${controllerName}.
|
|
18
|
+
let webControllerPath = path.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
|
|
19
|
+
if (fs.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
|
|
16
20
|
// Check if controller file already exists
|
|
17
21
|
return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
|
|
18
22
|
}
|
|
19
|
-
if (modelName) {
|
|
23
|
+
if (modelName && typeof modelName === "string") {
|
|
20
24
|
// If model name is provided, create a resource controller
|
|
21
25
|
fs.writeFileSync(
|
|
22
|
-
`${webControllerPath}/${controllerName}.
|
|
23
|
-
resourceController(controllerName, modelName)
|
|
26
|
+
`${webControllerPath}/${controllerName}.ts`,
|
|
27
|
+
resourceController(controllerName, modelName),
|
|
24
28
|
);
|
|
25
29
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
26
30
|
}
|
|
27
31
|
fs.writeFileSync(
|
|
28
|
-
`${webControllerPath}/${controllerName}.
|
|
29
|
-
createController(controllerName) // Create a basic controller file
|
|
32
|
+
`${webControllerPath}/${controllerName}.ts`,
|
|
33
|
+
createController(controllerName), // Create a basic controller file
|
|
30
34
|
);
|
|
31
35
|
|
|
32
36
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
@@ -38,24 +42,24 @@ class Command {
|
|
|
38
42
|
// Method to add an API controller
|
|
39
43
|
addApi(controllerName, modelName = false) {
|
|
40
44
|
try {
|
|
41
|
-
let apiPath = path.resolve(`${rootPath}/app/
|
|
42
|
-
if (fs.existsSync(`${apiPath}/${controllerName}.
|
|
45
|
+
let apiPath = path.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
|
|
46
|
+
if (fs.existsSync(`${apiPath}/${controllerName}.ts`)) {
|
|
43
47
|
// Check if API controller file already exists
|
|
44
48
|
return console.log(
|
|
45
|
-
`${controllerName} api controller already exist`.yellow
|
|
49
|
+
`${controllerName} api controller already exist`.yellow,
|
|
46
50
|
); // Log a warning if API controller already exists
|
|
47
51
|
}
|
|
48
|
-
if (modelName) {
|
|
52
|
+
if (modelName && typeof modelName === "string") {
|
|
49
53
|
// If model name is provided, create a resource controller
|
|
50
54
|
fs.writeFileSync(
|
|
51
|
-
`${apiPath}/${controllerName}.
|
|
52
|
-
resourceController(controllerName, modelName)
|
|
55
|
+
`${apiPath}/${controllerName}.ts`,
|
|
56
|
+
resourceController(controllerName, modelName),
|
|
53
57
|
);
|
|
54
58
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
55
59
|
}
|
|
56
60
|
fs.writeFileSync(
|
|
57
|
-
`${apiPath}/${controllerName}.
|
|
58
|
-
createController(controllerName) // Create a basic controller file
|
|
61
|
+
`${apiPath}/${controllerName}.ts`,
|
|
62
|
+
createController(controllerName), // Create a basic controller file
|
|
59
63
|
);
|
|
60
64
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
61
65
|
} catch (err) {
|
|
@@ -68,11 +72,11 @@ class Command {
|
|
|
68
72
|
addModel(modelName) {
|
|
69
73
|
try {
|
|
70
74
|
let modelPath = path.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
|
|
71
|
-
if (fs.existsSync(`${modelPath}/${modelName}.
|
|
75
|
+
if (fs.existsSync(`${modelPath}/${modelName}.ts`)) {
|
|
72
76
|
// Check if model file already exists
|
|
73
77
|
return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
|
|
74
78
|
}
|
|
75
|
-
fs.writeFileSync(`${modelPath}/${modelName}.
|
|
79
|
+
fs.writeFileSync(`${modelPath}/${modelName}.ts`, createModel(modelName)); // Create a model file
|
|
76
80
|
return console.log(`${modelName} model added successfully`.green); // Log success message
|
|
77
81
|
} catch (err) {
|
|
78
82
|
return console.log(`${modelName} model not added`.red); // Log error if model addition fails
|
|
@@ -82,15 +86,15 @@ class Command {
|
|
|
82
86
|
// Method to add a request file
|
|
83
87
|
addRequest(requestName) {
|
|
84
88
|
try {
|
|
85
|
-
let requestPath = path.resolve(`${rootPath}/app/
|
|
86
|
-
if (fs.existsSync(`${requestPath}/${requestName}.
|
|
89
|
+
let requestPath = path.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
|
|
90
|
+
if (fs.existsSync(`${requestPath}/${requestName}.ts`)) {
|
|
87
91
|
// Check if request file already exists
|
|
88
92
|
return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
fs.writeFileSync(
|
|
92
|
-
`${requestPath}/${requestName}.
|
|
93
|
-
createRequest(requestName) // Create a request file
|
|
96
|
+
`${requestPath}/${requestName}.ts`,
|
|
97
|
+
createRequest(requestName), // Create a request file
|
|
94
98
|
);
|
|
95
99
|
return console.log(`${requestName} added successfully`.green); // Log success message
|
|
96
100
|
} catch (err) {
|
|
@@ -98,6 +102,29 @@ class Command {
|
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
|
|
105
|
+
// Method to add a request file
|
|
106
|
+
addMigration(migrationName) {
|
|
107
|
+
try {
|
|
108
|
+
const tableName = migrationName.replace(/(create_|_table)/g, "");
|
|
109
|
+
|
|
110
|
+
let migrationPath = path.resolve(`${rootPath}/database/migrations`);
|
|
111
|
+
// Resolve path to request files directory
|
|
112
|
+
const fullName = `${formatDate()}_${migrationName}`;
|
|
113
|
+
if (fs.existsSync(`${migrationPath}/${fullName}.ts`)) {
|
|
114
|
+
// Check if request file already exists
|
|
115
|
+
return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fs.writeFileSync(
|
|
119
|
+
`${migrationPath}/${fullName}.ts`,
|
|
120
|
+
createMigration(tableName), // Create a request file
|
|
121
|
+
);
|
|
122
|
+
return console.log(`${fullName} added successfully`.green); // Log success message
|
|
123
|
+
} catch (err) {
|
|
124
|
+
return console.log(`${fullName} request not added`.red, { err }); // Log error if request addition fails
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
101
128
|
// Method to handle a command not found
|
|
102
129
|
notFound() {
|
|
103
130
|
return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create a controller file
|
|
3
|
+
* @param name string
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
const createController = (name) => {
|
|
7
|
+
return `
|
|
8
|
+
import {Request, Response,Next} from "jcc-express-mvc"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class ${name}{
|
|
13
|
+
/**
|
|
14
|
+
*@access public
|
|
15
|
+
* @return Express Request Response
|
|
16
|
+
*/
|
|
17
|
+
create(req:Request,res:Response,next:Next)
|
|
18
|
+
{
|
|
19
|
+
//
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*@access public
|
|
23
|
+
* @return Express Request Response
|
|
24
|
+
*/
|
|
25
|
+
index(req:Request,res:Response,next:Next)
|
|
26
|
+
{
|
|
27
|
+
//
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*@access public
|
|
33
|
+
* @return Express Request Response
|
|
34
|
+
*/
|
|
35
|
+
store(req:Request,res:Response,next:Next)
|
|
36
|
+
{
|
|
37
|
+
//
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*@access public
|
|
42
|
+
*@param {id} - string
|
|
43
|
+
* @return Express Request Response
|
|
44
|
+
*/
|
|
45
|
+
show(req:Request,res:Response,next:Next)
|
|
46
|
+
{
|
|
47
|
+
//
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
*@access public
|
|
53
|
+
* @param {id} - string
|
|
54
|
+
* @return Express Request Response
|
|
55
|
+
*/
|
|
56
|
+
update(req:Request,res:Response,next:Next)
|
|
57
|
+
{
|
|
58
|
+
//
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*@access public
|
|
63
|
+
* @param {id} - string
|
|
64
|
+
* @return Express Response
|
|
65
|
+
*/
|
|
66
|
+
destroy(req:Request,res:Response,next:Next)
|
|
67
|
+
{
|
|
68
|
+
//
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
module.exports = createController;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const inflection = require("inflection");
|
|
2
|
+
const createMigration = (table) => {
|
|
3
|
+
return `
|
|
4
|
+
import {Schema} from "";
|
|
5
|
+
class Migration {
|
|
6
|
+
up() {
|
|
7
|
+
return Schema.create("${inflection.pluralize(table)}", (table) => {
|
|
8
|
+
table.id();
|
|
9
|
+
table.timestamps();
|
|
10
|
+
table.softDeletes();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = createMigration;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create a model file
|
|
3
|
+
* @param name - string
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
const createModel = (name) => {
|
|
7
|
+
return `
|
|
8
|
+
import {Model} from "jcc-express-mvc"
|
|
9
|
+
|
|
10
|
+
export class ${name} extends Model{
|
|
11
|
+
//
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = createModel;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create a request file
|
|
3
|
+
* @param name - string
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
const createRequest = (fileName) => {
|
|
7
|
+
return `
|
|
8
|
+
import { getModel, FormRequest,Request } = from "jcc-express-mvc";
|
|
9
|
+
|
|
10
|
+
export class ${fileName} extends FormRequest {
|
|
11
|
+
constructor(req:Request) {
|
|
12
|
+
super(req);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
async rules ()
|
|
17
|
+
{
|
|
18
|
+
await this.apiValidate({
|
|
19
|
+
//
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async save()
|
|
24
|
+
{
|
|
25
|
+
await this.rules()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = createRequest;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create a resources file
|
|
3
|
+
* @param name - string
|
|
4
|
+
* @returns string
|
|
5
|
+
*/
|
|
6
|
+
const resourceController = (controller, model) => {
|
|
7
|
+
return `const {getModel }= require("jcc-express-mvc")
|
|
8
|
+
const ${model} = getModel('${model}')
|
|
9
|
+
export class ${controller} {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @return Express Request Response
|
|
14
|
+
*/
|
|
15
|
+
async create(req:Request,res:Response,next:Next)
|
|
16
|
+
{
|
|
17
|
+
return res.render();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @return Express Request Response
|
|
23
|
+
*/
|
|
24
|
+
async index(req:Request,res:Response,next:Next)
|
|
25
|
+
{
|
|
26
|
+
return res.json({message: await ${model}.all(),success:true})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
*
|
|
32
|
+
* @return Express Request Response
|
|
33
|
+
*/
|
|
34
|
+
async store(req:Request,res:Response,next:Next)
|
|
35
|
+
{
|
|
36
|
+
const data = {...req.body}
|
|
37
|
+
return res.json({message: await ${model}.create(data)})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param id
|
|
43
|
+
* @return Express Request Response
|
|
44
|
+
*/
|
|
45
|
+
async show(req:Request,res:Response,next:Next)
|
|
46
|
+
{
|
|
47
|
+
return res.json({message: await ${model}.find(req.params.id)})
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* @param id
|
|
55
|
+
* @return Express Request Response
|
|
56
|
+
*/
|
|
57
|
+
async update(req:Request,res:Response,next:Next)
|
|
58
|
+
{
|
|
59
|
+
const data = {...req.body}
|
|
60
|
+
return res.json({message: await ${model}.update(req.params.id,data)});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param id
|
|
66
|
+
* @return Express Response
|
|
67
|
+
*/
|
|
68
|
+
async destroy(req:Request,res:Response,next:Next)
|
|
69
|
+
{
|
|
70
|
+
return res.json({message:await ${model}.delete(req.params.id)})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
module.exports = resourceController;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
exports.formatDate = () => {
|
|
2
|
+
const date = new Date();
|
|
3
|
+
const year = date.getFullYear();
|
|
4
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
5
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
6
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
7
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
8
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
9
|
+
|
|
10
|
+
return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
|
|
11
|
+
};
|