jcc-express-mvc 1.2.5 → 1.2.7

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 (112) hide show
  1. package/index.js +32 -0
  2. package/lib/App.js +46 -0
  3. package/lib/Auth/AuthMiddleware.js +43 -0
  4. package/lib/Auth/index.js +94 -0
  5. package/lib/Command-Line/NodeArtisanCommand.js +69 -0
  6. package/lib/Command-Line/command.js +111 -0
  7. package/{Command-Line → lib/Command-Line}/files/Controller.js +4 -3
  8. package/{Command-Line → lib/Command-Line}/files/Migration.js +4 -3
  9. package/{Command-Line → lib/Command-Line}/files/Models.js +4 -3
  10. package/{Command-Line → lib/Command-Line}/files/Request.js +4 -3
  11. package/{Command-Line → lib/Command-Line}/files/ResourcesController.js +4 -3
  12. package/lib/Command-Line/utils.js +14 -0
  13. package/lib/Config/Config.js +17 -0
  14. package/lib/Database/src/BaseEntity.js +208 -0
  15. package/lib/Database/src/BaseModel.js +44 -0
  16. package/lib/Database/src/Builder.js +430 -0
  17. package/lib/Database/src/Cast/index.js +98 -0
  18. package/lib/Database/src/Cast/types.js +25 -0
  19. package/lib/Database/src/Date/index.js +36 -0
  20. package/lib/Database/src/Model.js +53 -0
  21. package/lib/Database/src/Query.js +16 -0
  22. package/lib/Database/src/QueryBuilder.js +354 -0
  23. package/lib/Database/src/QueryInstance.js +28 -0
  24. package/lib/Database/src/RelationBuilder.js +97 -0
  25. package/lib/Database/src/Schema/BaseSchemaEntity/index.js +26 -0
  26. package/lib/Database/src/Schema/BluePrint/index.js +257 -0
  27. package/lib/Database/src/Schema/index.js +18 -0
  28. package/lib/Database/src/db/connection.js +22 -0
  29. package/lib/Database/src/type.js +2 -0
  30. package/lib/Database/src/utils/index.js +112 -0
  31. package/lib/Error/AppError.js +12 -0
  32. package/lib/Error/AppErrorHandler.js +35 -0
  33. package/lib/Error/Constants/error.js +15 -0
  34. package/lib/Error/Constants/index.js +6 -0
  35. package/lib/HttpKernel/HttpKernel.js +12 -0
  36. package/lib/Interface/index.js +2 -0
  37. package/lib/Middlewares/index.js +109 -0
  38. package/lib/Middlewares/isLogin.js +29 -0
  39. package/lib/Passport/config.js +69 -0
  40. package/lib/Request/FormRequest.js +51 -0
  41. package/lib/Request/request.js +36 -0
  42. package/lib/Response/index.js +46 -0
  43. package/lib/Routes/RouteBuilder.js +90 -0
  44. package/lib/Routes/Router.js +95 -0
  45. package/lib/Server/index.js +45 -0
  46. package/lib/Services/ServiceContainer.js +30 -0
  47. package/lib/Services/ServiceProvider.js +49 -0
  48. package/lib/Templating-engine/engineHelper.js +127 -0
  49. package/lib/Templating-engine/expressions.js +20 -0
  50. package/lib/Templating-engine/index.js +228 -0
  51. package/lib/Type/index.js +2 -0
  52. package/lib/Validation/index.js +76 -0
  53. package/lib/Validation/rules.js +72 -0
  54. package/lib/Validation/validate.js +312 -0
  55. package/lib/util/index.js +165 -0
  56. package/package.json +3 -2
  57. package/Command-Line/NodeArtisanCommand.js +0 -93
  58. package/Command-Line/NodeTinker/db/index.js +0 -17
  59. package/Command-Line/NodeTinker/getInput.js +0 -7
  60. package/Command-Line/NodeTinker/index.js +0 -53
  61. package/Command-Line/NodeTinker/repl.js +0 -28
  62. package/Command-Line/command.js +0 -134
  63. package/Command-Line/utils.js +0 -11
  64. package/Database/src/BaseEntity.ts +0 -247
  65. package/Database/src/BaseModel.ts +0 -51
  66. package/Database/src/Builder.ts +0 -498
  67. package/Database/src/Cast/index.ts +0 -126
  68. package/Database/src/Cast/types.ts +0 -24
  69. package/Database/src/Date/index.ts +0 -52
  70. package/Database/src/Model.ts +0 -55
  71. package/Database/src/Query.ts +0 -13
  72. package/Database/src/QueryBuilder.ts +0 -426
  73. package/Database/src/QueryInstance.ts +0 -28
  74. package/Database/src/RelationBuilder.ts +0 -119
  75. package/Database/src/Schema/BaseSchemaEntity/index.ts +0 -32
  76. package/Database/src/Schema/BluePrint/index.ts +0 -287
  77. package/Database/src/Schema/index.ts +0 -15
  78. package/Database/src/Schema/migrationContent.js +0 -19
  79. package/Database/src/db/connection.ts +0 -17
  80. package/Database/src/type.ts +0 -18
  81. package/Database/src/utils/index.ts +0 -122
  82. package/index.ts +0 -36
  83. package/lib/App.ts +0 -46
  84. package/lib/Auth/AuthMiddleware.ts +0 -47
  85. package/lib/Auth/index.ts +0 -110
  86. package/lib/Config/Config.ts +0 -17
  87. package/lib/Error/AppError.ts +0 -11
  88. package/lib/Error/AppErrorHandler.ts +0 -41
  89. package/lib/Error/Constants/error.ts +0 -23
  90. package/lib/Error/Constants/index.ts +0 -5
  91. package/lib/Error/public/pageNotFound.html +0 -28
  92. package/lib/HttpKernel/HttpKernel.ts +0 -12
  93. package/lib/Interface/index.ts +0 -39
  94. package/lib/Middlewares/index.ts +0 -125
  95. package/lib/Middlewares/isLogin.ts +0 -29
  96. package/lib/Passport/config.ts +0 -74
  97. package/lib/Request/FormRequest.ts +0 -58
  98. package/lib/Request/request.ts +0 -44
  99. package/lib/Response/index.ts +0 -52
  100. package/lib/Routes/RouteBuilder.ts +0 -133
  101. package/lib/Routes/Router.ts +0 -145
  102. package/lib/Server/index.ts +0 -40
  103. package/lib/Services/ServiceContainer.ts +0 -34
  104. package/lib/Services/ServiceProvider.ts +0 -58
  105. package/lib/Templating-engine/engineHelper.ts +0 -138
  106. package/lib/Templating-engine/expressions.ts +0 -18
  107. package/lib/Templating-engine/index.ts +0 -242
  108. package/lib/Type/index.ts +0 -28
  109. package/lib/Validation/index.ts +0 -96
  110. package/lib/Validation/rules.ts +0 -107
  111. package/lib/Validation/validate.ts +0 -370
  112. package/lib/util/index.ts +0 -179
package/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.artisanCommand = exports.Schema = exports.Model = exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.FormRequest = exports.apiAuth = exports.auth = exports.Auth = exports.config = exports.HttpKernel = exports.server = exports.ApiRoute = exports.Route = void 0;
7
+ const Config_1 = __importDefault(require("./lib/Config/Config"));
8
+ const App_1 = require("./lib/App");
9
+ const HttpKernel_1 = __importDefault(require("./lib/HttpKernel/HttpKernel"));
10
+ const Auth_1 = __importDefault(require("./lib/Auth"));
11
+ const AuthMiddleware_1 = require("./lib/Auth/AuthMiddleware");
12
+ const FormRequest_1 = require("./lib/Request/FormRequest");
13
+ const util_1 = require("./lib/util");
14
+ const Schema_1 = require("./lib/Database/src/Schema");
15
+ const Model_1 = require("./lib/Database/src/Model");
16
+ const NodeArtisanCommand_1 = require("./lib/Command-Line/NodeArtisanCommand");
17
+ exports.Route = App_1.app.webRoutes();
18
+ exports.ApiRoute = App_1.app.apiRoutes();
19
+ exports.server = App_1.app.httpServer();
20
+ exports.HttpKernel = HttpKernel_1.default;
21
+ exports.config = Config_1.default;
22
+ exports.Auth = Auth_1.default;
23
+ exports.auth = AuthMiddleware_1.authMiddleware.auth;
24
+ exports.apiAuth = AuthMiddleware_1.authMiddleware.apiAuth;
25
+ exports.FormRequest = FormRequest_1.FormRequest;
26
+ exports.bcrypt = util_1.bcrypt;
27
+ exports.jwtSign = util_1.jwtSign;
28
+ exports.jwtVerify = util_1.jwtVerify;
29
+ exports.verifyHash = util_1.verifyHash;
30
+ exports.Model = Model_1.Model;
31
+ exports.Schema = Schema_1.Schema;
32
+ exports.artisanCommand = NodeArtisanCommand_1.NodeArtisanCommand;
package/lib/App.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.app = void 0;
7
+ const Router_1 = require("./Routes/Router");
8
+ const Config_1 = __importDefault(require("./Config/Config"));
9
+ const Middlewares_1 = require("./Middlewares");
10
+ const Server_1 = require("./Server");
11
+ const util_1 = require("./util");
12
+ const Constants_1 = require("./Error/Constants");
13
+ class App extends Server_1.HttpSever {
14
+ // private app = express();
15
+ constructor() {
16
+ super();
17
+ new Middlewares_1.Middleware(this.express, this.app);
18
+ }
19
+ webRoutes() {
20
+ return new Router_1.Router(this.app, { prefixUrl: "", basePath: "" });
21
+ }
22
+ /**
23
+ * Method to define API routes.
24
+ * @returns {object} - Instance of Routes class for API routes.
25
+ */
26
+ apiRoutes() {
27
+ return new Router_1.Router(this.app, { basePath: "/api", prefixUrl: "" });
28
+ }
29
+ /**
30
+ * Method to configure and start the server.
31
+ * @returns {object} - Object containing server run method and server instance.
32
+ */
33
+ httpServer() {
34
+ const server = this.server(Number(Config_1.default.get(Constants_1.PORT, "3000")));
35
+ const httpErrors = this.httpErrors;
36
+ const app = this.app;
37
+ return {
38
+ listen() {
39
+ (0, util_1.loadRoutes)();
40
+ httpErrors(app);
41
+ return server;
42
+ },
43
+ };
44
+ }
45
+ }
46
+ exports.app = new App();
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authMiddleware = void 0;
4
+ const util_1 = require("../util");
5
+ class AuthMiddleware {
6
+ apiAuth(request, response, next) {
7
+ let token;
8
+ if (request.headers.authorization &&
9
+ request.headers.authorization.startsWith("Bearer")) {
10
+ token = request.headers.authorization.split(" ")[1];
11
+ }
12
+ else if (request.cookies.token) {
13
+ token = request.cookies.token;
14
+ }
15
+ else if (request.header("x-auth-token")) {
16
+ token = request.header("x-auth-token");
17
+ }
18
+ if (!token) {
19
+ return response.json({ message: "Not authorize" }).status(401);
20
+ }
21
+ try {
22
+ request.id = (0, util_1.jwtVerify)(token);
23
+ // request.id = jwtVerify(token, process.env.JWT_SECRET);
24
+ //
25
+ next();
26
+ }
27
+ catch (err) {
28
+ next(err);
29
+ return response.json({ message: "Not authorize" }).status(401);
30
+ }
31
+ }
32
+ auth(request, response, next) {
33
+ let url = "";
34
+ if (request.url) {
35
+ url = request.url;
36
+ request.session["appRedirect"] = url;
37
+ }
38
+ return request.isAuthenticated()
39
+ ? next()
40
+ : response.redirect(url ? `/login?redirect=${url}` : "/login");
41
+ }
42
+ }
43
+ exports.authMiddleware = new AuthMiddleware();
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const passport_1 = __importDefault(require("passport")); // Import Passport for authentication
7
+ const util_1 = require("../util"); // Import helper functions for database operations and password hashing
8
+ const User = (0, util_1.getModel)("User"); // Get the User model from database
9
+ class Authentication {
10
+ // Method to authenticate user login
11
+ static async login(data = {}, password = "") {
12
+ try {
13
+ const user = await User.findOne(data); //.select("+password"); // Find user by provided data and include password field
14
+ if (!user) {
15
+ return false; // If user not found, return false
16
+ }
17
+ //return (await verifyHash(password, user.password))
18
+ true ? user : false; // Verify password hash and return user if successful, otherwise false
19
+ }
20
+ catch (error) {
21
+ return new Error(error.message); // Return error if any exception occurs during login
22
+ }
23
+ }
24
+ // Middleware to check if user is an admin
25
+ static async isAdmin(req, res, next) {
26
+ try {
27
+ const user = await User.findById(req.id); // Find user by ID extracted from request
28
+ if (!user) {
29
+ return res.json({ message: "Not authorized" }).status(403); // If user not found, return 403 Forbidden
30
+ }
31
+ // Check if user has admin privileges
32
+ if (!user.role ||
33
+ !user.roleType ||
34
+ !user.isAdmin ||
35
+ !(user.role === "admin" ||
36
+ user.role === "Admin" ||
37
+ user.roleType === "admin" ||
38
+ user.roleType === "Admin" ||
39
+ user.isAdmin === true ||
40
+ user.isAdmin === "admin" ||
41
+ user.isAdmin === "Admin")) {
42
+ return res.json({ message: "Not authorized" }).status(403); // If user doesn't have admin privileges, return 403 Forbidden
43
+ }
44
+ next(); // If user is admin, proceed to next middleware
45
+ }
46
+ catch (error) {
47
+ next(error); // Pass any errors to the error handling middleware
48
+ }
49
+ }
50
+ // Middleware to verify user email
51
+ static async verifyEmail(req, res, next) {
52
+ try {
53
+ const user = await User.findById(req?.id); // Find user by ID extracted from request
54
+ if (!user) {
55
+ return res.json({ message: "Not authorized" }).status(403); // If user not found, return 403 Forbidden
56
+ }
57
+ // Check if user's email is verified
58
+ if (!user.verify_email && !user.verifyEmail) {
59
+ return res.json({ message: "Please verify your email" }).status(403); // If email is not verified, return 403 Forbidden
60
+ }
61
+ next(); // If email is verified, proceed to next middleware
62
+ }
63
+ catch (error) {
64
+ next(error); // Pass any errors to the error handling middleware
65
+ }
66
+ }
67
+ // Method to handle authentication attempt
68
+ static attempt(req, res, next) {
69
+ try {
70
+ let redirectBack = req.previsiousUrls[1];
71
+ // Retrieve the previous URL
72
+ const appRedirect = req.session["appRedirect"]; // Retrieve redirect URL from session
73
+ const redirectPath = appRedirect ? appRedirect : "/home"; // Determine the redirect path
74
+ // Use Passport's local authentication strategy
75
+ return passport_1.default.authenticate("local", {
76
+ successRedirect: redirectPath, // Redirect on successful authentication
77
+ failureRedirect: `${redirectBack ? redirectBack : "/login"}`, // Redirect on failed authentication
78
+ failureFlash: true, // Enable flash messages on failed authentication
79
+ })(req, res, next); // Call Passport's authentication middleware
80
+ }
81
+ catch (error) {
82
+ next(error); // Pass any errors to the error handling middleware
83
+ }
84
+ }
85
+ static logout(req, res, next) {
86
+ return req.logout((err) => {
87
+ if (err) {
88
+ next(err);
89
+ }
90
+ return res.redirect("/login");
91
+ });
92
+ }
93
+ }
94
+ exports.default = Authentication;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeArtisanCommand = void 0;
7
+ const command_1 = __importDefault(require("./command"));
8
+ /**
9
+ Function to parse command line arguments and execute corresponding commands
10
+ @param {commandArg} commandArg -string
11
+ @returns {any} -any
12
+ * */
13
+ const NodeArtisanCommand = (commandArg = []) => {
14
+ let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
15
+ let command = commandArg[index].split(":")[1];
16
+ // If the command is for creating an API controller with resources
17
+ if (commandArg.length === index + 4 &&
18
+ (command === "apiController" || command === "ApiController") &&
19
+ (commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")) {
20
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
21
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
22
+ }
23
+ // If the command is for creating a web controller with resources
24
+ if (commandArg.length === 4 &&
25
+ (command === "controller" || command === "Controller") &&
26
+ (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
27
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
28
+ return command_1.default.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
29
+ }
30
+ // If the command is for creating an admin controller with resources
31
+ // If the command is for creating a web controller
32
+ if (commandArg.length === index + 3 &&
33
+ (command === "controller" || command === "Controller")) {
34
+ return command_1.default.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
35
+ }
36
+ // If the command is for creating an API controller
37
+ if (commandArg.length === index + 3 &&
38
+ (command === "apiController" || command === "ApiController")) {
39
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
40
+ }
41
+ // If the command is for creating a model
42
+ if (commandArg.length === index + 2 &&
43
+ (command === "model" || command === "Model")) {
44
+ return command_1.default.addModel(commandArg[index + 1]); // Add a model
45
+ }
46
+ // If the command is for creating a web controller without specifying a model
47
+ if (commandArg.length === index + 2 &&
48
+ (command === "controller" || command === "Controller")) {
49
+ return command_1.default.addWeb(commandArg[index + 1], false); // Add a web controller without a model
50
+ }
51
+ // If the command is for creating an API controller without specifying a model
52
+ if (commandArg.length === index + 2 &&
53
+ (command === "apiController" || command === "ApiController")) {
54
+ return command_1.default.addApi(commandArg[index + 1], false); // Add an API controller without a model
55
+ }
56
+ // If the command is for creating a request file
57
+ if (commandArg.length === index + 2 &&
58
+ (command === "Request" || command === "request")) {
59
+ return command_1.default.addRequest(commandArg[index + 1]); // Add a request file
60
+ }
61
+ // If the command is for creating a request file
62
+ if (commandArg.length === index + 2 &&
63
+ (command === "Migration" || command === "migration")) {
64
+ return command_1.default.addMigration(commandArg[index + 1]); // Add a request file
65
+ }
66
+ // If the command is not recognized, display "Command not found"
67
+ return command_1.default.notFound();
68
+ };
69
+ exports.NodeArtisanCommand = NodeArtisanCommand;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const app_root_path_1 = __importDefault(require("app-root-path"));
9
+ const Controller_1 = __importDefault(require("./files/Controller"));
10
+ const Models_1 = __importDefault(require("./files/Models"));
11
+ const ResourcesController_1 = __importDefault(require("./files/ResourcesController"));
12
+ const Request_1 = __importDefault(require("./files/Request"));
13
+ const Migration_1 = __importDefault(require("./files/Migration"));
14
+ const utils_1 = require("./utils");
15
+ const rootPath = app_root_path_1.default.path;
16
+ class Command {
17
+ // Method to add a web controller
18
+ addWeb(controllerName, modelName = false) {
19
+ try {
20
+ let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
21
+ if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
22
+ // Check if controller file already exists
23
+ return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
24
+ }
25
+ if (modelName && typeof modelName === "string") {
26
+ // If model name is provided, create a resource controller
27
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
28
+ return console.log(`${controllerName} added successfully`.green); // Log success message
29
+ }
30
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
31
+ return console.log(`${controllerName} added successfully`.green); // Log success message
32
+ }
33
+ catch (err) {
34
+ console.log(`${controllerName} admin controller not added`.red); // Log error if controller addition fails
35
+ }
36
+ }
37
+ // Method to add an API controller
38
+ addApi(controllerName, modelName = false) {
39
+ try {
40
+ let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
41
+ if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
42
+ // Check if API controller file already exists
43
+ return console.log(`${controllerName} api controller already exist`.yellow); // Log a warning if API controller already exists
44
+ }
45
+ if (modelName && typeof modelName === "string") {
46
+ // If model name is provided, create a resource controller
47
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
48
+ return console.log(`${controllerName} added successfully`.green); // Log success message
49
+ }
50
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
51
+ return console.log(`${controllerName} added successfully`.green); // Log success message
52
+ }
53
+ catch (err) {
54
+ console.log(err.message);
55
+ console.log(`${controllerName} api controller not added`.red); // Log error if controller addition fails
56
+ }
57
+ }
58
+ // Method to add a model
59
+ addModel(modelName) {
60
+ try {
61
+ let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
62
+ if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
63
+ // Check if model file already exists
64
+ return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
65
+ }
66
+ fs_1.default.writeFileSync(`${modelPath}/${modelName}.ts`, (0, Models_1.default)(modelName)); // Create a model file
67
+ return console.log(`${modelName} model added successfully`.green); // Log success message
68
+ }
69
+ catch (err) {
70
+ return console.log(`${modelName} model not added`.red); // Log error if model addition fails
71
+ }
72
+ }
73
+ // Method to add a request file
74
+ addRequest(requestName) {
75
+ try {
76
+ let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
77
+ if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
78
+ // Check if request file already exists
79
+ return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
80
+ }
81
+ fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
82
+ return console.log(`${requestName} added successfully`.green); // Log success message
83
+ }
84
+ catch (err) {
85
+ return console.log(`${requestName} request not added`.red, { err }); // Log error if request addition fails
86
+ }
87
+ }
88
+ // Method to add a request file
89
+ addMigration(migrationName) {
90
+ try {
91
+ const tableName = migrationName.replace(/(create_|_table)/g, "");
92
+ let migrationPath = path_1.default.resolve(`${rootPath}/database/migrations`);
93
+ // Resolve path to request files directory
94
+ const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
95
+ if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
96
+ // Check if request file already exists
97
+ return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
98
+ }
99
+ fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
100
+ return console.log(`${fullName} added successfully`.green); // Log success message
101
+ }
102
+ catch (err) {
103
+ return console.log(`${migrationName} migration not added`.red, { err }); // Log error if request addition fails
104
+ }
105
+ }
106
+ // Method to handle a command not found
107
+ notFound() {
108
+ return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
109
+ }
110
+ }
111
+ exports.default = new Command(); // Export an instance of the Command class
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a controller file
3
5
  * @param name string
4
6
  * @returns string
5
7
  */
6
8
  const createController = (name) => {
7
- return `
9
+ return `
8
10
  import {Request, Response,Next} from "jcc-express-mvc"
9
11
 
10
12
 
@@ -72,5 +74,4 @@ const createController = (name) => {
72
74
  }
73
75
  `;
74
76
  };
75
-
76
- module.exports = createController;
77
+ exports.default = createController;
@@ -1,6 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const inflection = require("inflection");
2
4
  const createMigration = (table) => {
3
- return `
5
+ return `
4
6
  import {Schema} from "";
5
7
  class Migration {
6
8
  up() {
@@ -13,5 +15,4 @@ class Migration {
13
15
  }
14
16
  `;
15
17
  };
16
-
17
- module.exports = createMigration;
18
+ exports.default = createMigration;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a model file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const createModel = (name) => {
7
- return `
9
+ return `
8
10
  import {Model} from "jcc-express-mvc"
9
11
 
10
12
  export class ${name} extends Model{
@@ -16,5 +18,4 @@ const createModel = (name) => {
16
18
 
17
19
  `;
18
20
  };
19
-
20
- module.exports = createModel;
21
+ exports.default = createModel;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a request file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const createRequest = (fileName) => {
7
- return `
9
+ return `
8
10
  import { getModel, FormRequest,Request } = from "jcc-express-mvc";
9
11
 
10
12
  export class ${fileName} extends FormRequest {
@@ -28,5 +30,4 @@ const createRequest = (fileName) => {
28
30
 
29
31
  `;
30
32
  };
31
-
32
- module.exports = createRequest;
33
+ exports.default = createRequest;
@@ -1,10 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a resources file
3
5
  * @param name - string
4
6
  * @returns string
5
7
  */
6
8
  const resourceController = (controller, model) => {
7
- return `const {getModel }= require("jcc-express-mvc")
9
+ return `const {getModel }= require("jcc-express-mvc")
8
10
  const ${model} = getModel('${model}')
9
11
  export class ${controller} {
10
12
 
@@ -73,5 +75,4 @@ const resourceController = (controller, model) => {
73
75
  }
74
76
  `;
75
77
  };
76
-
77
- module.exports = resourceController;
78
+ exports.default = resourceController;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDate = void 0;
4
+ const formatDate = () => {
5
+ const date = new Date();
6
+ const year = date.getFullYear();
7
+ const month = String(date.getMonth() + 1).padStart(2, "0");
8
+ const day = String(date.getDate()).padStart(2, "0");
9
+ const hours = String(date.getHours()).padStart(2, "0");
10
+ const minutes = String(date.getMinutes()).padStart(2, "0");
11
+ const seconds = String(date.getSeconds()).padStart(2, "0");
12
+ return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
13
+ };
14
+ exports.formatDate = formatDate;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const dotenv_1 = __importDefault(require("dotenv"));
7
+ const app_root_path_1 = __importDefault(require("app-root-path"));
8
+ class Config {
9
+ constructor() {
10
+ dotenv_1.default.config({ path: `${app_root_path_1.default.path}/.env` });
11
+ this.config = process.env;
12
+ }
13
+ get(key, defaultValue = "") {
14
+ return this.config[key] || defaultValue;
15
+ }
16
+ }
17
+ exports.default = new Config();