jcc-express-mvc 1.2.4 → 1.2.6

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.
Files changed (132) hide show
  1. package/Command-Line/NodeArtisanCommand.js +93 -0
  2. package/Command-Line/NodeTinker/db/index.js +17 -0
  3. package/{src/command-line-interface → Command-Line/NodeTinker}/getInput.js +1 -1
  4. package/{src/command-line-interface → Command-Line/NodeTinker}/index.js +11 -7
  5. package/{src/command-line-interface/commands.js → Command-Line/command.js} +53 -26
  6. package/Command-Line/files/Controller.js +76 -0
  7. package/Command-Line/files/Migration.js +17 -0
  8. package/Command-Line/files/Models.js +20 -0
  9. package/Command-Line/files/Request.js +32 -0
  10. package/Command-Line/files/ResourcesController.js +77 -0
  11. package/Command-Line/utils.js +11 -0
  12. package/Database/src/BaseEntity.ts +247 -0
  13. package/Database/src/BaseModel.ts +51 -0
  14. package/Database/src/Builder.ts +498 -0
  15. package/Database/src/Cast/index.ts +126 -0
  16. package/Database/src/Cast/types.ts +24 -0
  17. package/Database/src/Date/index.ts +52 -0
  18. package/Database/src/Model.ts +55 -0
  19. package/Database/src/Query.ts +13 -0
  20. package/Database/src/QueryBuilder.ts +426 -0
  21. package/Database/src/QueryInstance.ts +28 -0
  22. package/Database/src/RelationBuilder.ts +119 -0
  23. package/Database/src/Schema/BaseSchemaEntity/index.ts +32 -0
  24. package/Database/src/Schema/BluePrint/index.ts +287 -0
  25. package/Database/src/Schema/index.ts +15 -0
  26. package/Database/src/Schema/migrationContent.js +19 -0
  27. package/Database/src/db/connection.ts +17 -0
  28. package/Database/src/type.ts +18 -0
  29. package/Database/src/utils/index.ts +122 -0
  30. package/dist/Database/src/BaseEntity.js +208 -0
  31. package/dist/Database/src/BaseModel.js +44 -0
  32. package/dist/Database/src/Builder.js +430 -0
  33. package/dist/Database/src/Cast/index.js +98 -0
  34. package/dist/Database/src/Cast/types.js +25 -0
  35. package/dist/Database/src/Date/index.js +36 -0
  36. package/dist/Database/src/Model.js +53 -0
  37. package/dist/Database/src/Query.js +16 -0
  38. package/dist/Database/src/QueryBuilder.js +354 -0
  39. package/dist/Database/src/QueryInstance.js +28 -0
  40. package/dist/Database/src/RelationBuilder.js +97 -0
  41. package/dist/Database/src/Schema/BaseSchemaEntity/index.js +26 -0
  42. package/dist/Database/src/Schema/BluePrint/index.js +257 -0
  43. package/dist/Database/src/Schema/index.js +18 -0
  44. package/dist/Database/src/db/connection.js +22 -0
  45. package/dist/Database/src/type.js +2 -0
  46. package/dist/Database/src/utils/index.js +112 -0
  47. package/dist/index.js +30 -0
  48. package/dist/lib/App.js +46 -0
  49. package/dist/lib/Auth/AuthMiddleware.js +43 -0
  50. package/dist/lib/Auth/index.js +94 -0
  51. package/dist/lib/Config/Config.js +17 -0
  52. package/dist/lib/Error/AppError.js +12 -0
  53. package/dist/lib/Error/AppErrorHandler.js +35 -0
  54. package/dist/lib/Error/Constants/error.js +15 -0
  55. package/dist/lib/Error/Constants/index.js +6 -0
  56. package/dist/lib/HttpKernel/HttpKernel.js +12 -0
  57. package/dist/lib/Interface/index.js +2 -0
  58. package/dist/lib/Middlewares/index.js +109 -0
  59. package/dist/lib/Middlewares/isLogin.js +29 -0
  60. package/dist/lib/Passport/config.js +69 -0
  61. package/dist/lib/Request/FormRequest.js +51 -0
  62. package/dist/lib/Request/request.js +36 -0
  63. package/dist/lib/Response/index.js +46 -0
  64. package/dist/lib/Routes/RouteBuilder.js +90 -0
  65. package/dist/lib/Routes/Router.js +95 -0
  66. package/dist/lib/Server/index.js +45 -0
  67. package/dist/lib/Services/ServiceContainer.js +30 -0
  68. package/dist/lib/Services/ServiceProvider.js +49 -0
  69. package/dist/lib/Templating-engine/engineHelper.js +127 -0
  70. package/dist/lib/Templating-engine/expressions.js +20 -0
  71. package/dist/lib/Templating-engine/index.js +228 -0
  72. package/dist/lib/Type/index.js +2 -0
  73. package/dist/lib/Validation/index.js +76 -0
  74. package/dist/lib/Validation/rules.js +72 -0
  75. package/dist/lib/Validation/validate.js +312 -0
  76. package/dist/lib/util/index.js +165 -0
  77. package/index.ts +36 -0
  78. package/lib/App.ts +46 -0
  79. package/lib/Auth/AuthMiddleware.ts +47 -0
  80. package/{src/Auth/index.js → lib/Auth/index.ts} +33 -12
  81. package/lib/Config/Config.ts +17 -0
  82. package/lib/Error/AppError.ts +11 -0
  83. package/lib/Error/AppErrorHandler.ts +41 -0
  84. package/lib/Error/Constants/error.ts +23 -0
  85. package/lib/Error/Constants/index.ts +5 -0
  86. package/{src/error → lib/Error}/public/pageNotFound.html +1 -1
  87. package/lib/HttpKernel/HttpKernel.ts +12 -0
  88. package/lib/Interface/index.ts +39 -0
  89. package/lib/Middlewares/index.ts +125 -0
  90. package/{src/middlware/isLogin.js → lib/Middlewares/isLogin.ts} +6 -6
  91. package/lib/Passport/config.ts +74 -0
  92. package/{src/request/FormRequest.js → lib/Request/FormRequest.ts} +13 -21
  93. package/lib/Request/request.ts +44 -0
  94. package/{src/response/index.js → lib/Response/index.ts} +9 -7
  95. package/lib/Routes/RouteBuilder.ts +133 -0
  96. package/lib/Routes/Router.ts +145 -0
  97. package/lib/Server/index.ts +40 -0
  98. package/lib/Services/ServiceContainer.ts +34 -0
  99. package/lib/Services/ServiceProvider.ts +58 -0
  100. package/{src/templating-engine/utils.js → lib/Templating-engine/engineHelper.ts} +29 -33
  101. package/lib/Templating-engine/expressions.ts +18 -0
  102. package/{src/templating-engine/index.js → lib/Templating-engine/index.ts} +60 -93
  103. package/lib/Type/index.ts +28 -0
  104. package/lib/Validation/index.ts +96 -0
  105. package/lib/Validation/rules.ts +107 -0
  106. package/{src/validation/method.js → lib/Validation/validate.ts} +75 -54
  107. package/{src/helpers.js → lib/util/index.ts} +72 -32
  108. package/package.json +4 -3
  109. package/README.md +0 -0
  110. package/index.js +0 -1
  111. package/src/Auth/protectedRoute.js +0 -41
  112. package/src/Router/Router.js +0 -113
  113. package/src/Router/Routes.js +0 -54
  114. package/src/app/index.js +0 -83
  115. package/src/command-line-interface/db.js +0 -20
  116. package/src/command-line-interface/getCommands.js +0 -94
  117. package/src/dbConnection/index.js +0 -14
  118. package/src/error/AppError.js +0 -8
  119. package/src/error/ErrorHandler.js +0 -88
  120. package/src/files/controller.js +0 -67
  121. package/src/files/model.js +0 -14
  122. package/src/files/request.js +0 -28
  123. package/src/files/resoucesController.js +0 -72
  124. package/src/index.js +0 -44
  125. package/src/middlware/index.js +0 -114
  126. package/src/passport/config.js +0 -59
  127. package/src/request/index.js +0 -38
  128. package/src/socket/index.js +0 -26
  129. package/src/utils/index.js +0 -149
  130. package/src/validation/index.js +0 -87
  131. package/src/validation/rules.js +0 -110
  132. /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
+ }
@@ -4,4 +4,4 @@ const getInput = async (input) => {
4
4
  const cli = new TinkerNode();
5
5
  return cli.extractCommand(input);
6
6
  };
7
- module.exports = getInput; // Export the getDbCommandLineArgv function
7
+ module.exports = getInput;
@@ -1,9 +1,12 @@
1
- const { getModel } = require("../helpers");
2
- const Database = require("./db");
1
+ const appRootPath = require("app-root-path").path;
3
2
 
4
- class TinkerNode extends Database {
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 createController = require("../files/controller"); // Function to create a controller file
4
- const createModel = require("../files/model"); // Function to create a model file
5
- const resourceController = require("../files/resoucesController"); // Function to create a resource controller file
6
- const createRequest = require("../files/request"); // Function to create a request file
7
- const rootPath = require("app-root-path").path; // Module to get the root path of the application
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}.js`)) {
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}.js`,
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}.js`,
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/Controllers/Api`); // Resolve path to API controllers directory
42
- if (fs.existsSync(`${apiPath}/${controllerName}.js`)) {
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}.js`,
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}.js`,
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}.js`)) {
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}.js`, createModel(modelName)); // Create a model file
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/Request`); // Resolve path to request files directory
86
- if (fs.existsSync(`${requestPath}/${requestName}.js`)) {
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}.js`,
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
+ };