chyz 1.0.13-rc.4 → 1.0.13-rc.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.
Files changed (180) hide show
  1. package/BaseChyz.ts +384 -0
  2. package/Chyz.ts +11 -0
  3. package/Examples/Controllers/ApiController.ts +140 -0
  4. package/Examples/Controllers/KeyCloakController.ts +100 -0
  5. package/Examples/Controllers/PublicController.ts +42 -0
  6. package/Examples/Controllers/SiteController.ts +139 -0
  7. package/Examples/Models/Categories.ts +48 -0
  8. package/Examples/Models/Customer.ts +115 -0
  9. package/Examples/Models/KeycloakUser.ts +66 -0
  10. package/Examples/Models/Order.ts +64 -0
  11. package/Examples/Models/OrderItem.ts +27 -0
  12. package/Examples/Models/ProductModels.ts +49 -0
  13. package/Examples/Models/ProductToCategories.ts +46 -0
  14. package/Examples/Models/Products.ts +50 -0
  15. package/Examples/Models/Stocks.ts +60 -0
  16. package/Examples/Models/User.ts +100 -0
  17. package/Examples/Models/UserPermission.ts +37 -0
  18. package/Examples/Models/index.ts +19 -0
  19. package/Examples/index-keycloack.ts +78 -0
  20. package/Examples/index.ts +40 -0
  21. package/Examples/keycloak.json +7 -0
  22. package/Examples/log/access.log +0 -0
  23. package/Examples/log/app.log +6057 -0
  24. package/Examples/log/errors.log +1526 -0
  25. package/Examples/package.json +46 -0
  26. package/Examples/tsconfig.json +21 -0
  27. package/base/ActionFilter.ts +71 -0
  28. package/base/BaseError.ts +26 -0
  29. package/base/BaseObject.ts +19 -0
  30. package/base/Behavior.ts +6 -0
  31. package/base/Component.ts +66 -0
  32. package/base/Configurable.ts +10 -0
  33. package/base/Controller.ts +84 -0
  34. package/base/DataErrorDbException.ts +16 -0
  35. package/base/DbConnection.ts +51 -0
  36. package/base/ForbiddenHttpException.ts +15 -0
  37. package/base/InvalidConfigException.ts +16 -0
  38. package/base/Model.ts +358 -0
  39. package/base/ModelManager.ts +14 -0
  40. package/base/NotFoundHttpException.ts +14 -0
  41. package/base/RestClient.ts +28 -0
  42. package/base/UnauthorizedHttpException.ts +17 -0
  43. package/base/ValidationHttpException.ts +14 -0
  44. package/base/db/Exception.ts +14 -0
  45. package/base/index.ts +17 -0
  46. package/decorator/Middleware.ts +9 -0
  47. package/decorator/controller.ts +22 -0
  48. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  49. package/decorator/get.ts +37 -0
  50. package/decorator/index.ts +3 -0
  51. package/decorator/post.ts +36 -0
  52. package/{BaseChyz.js → dist/BaseChyz.js} +29 -4
  53. package/dist/BaseChyz.js.map +1 -0
  54. package/{Chyz.js → dist/Chyz.js} +0 -0
  55. package/{Chyz.js.map → dist/Chyz.js.map} +0 -0
  56. package/{base → dist/base}/ActionFilter.js +0 -0
  57. package/{base → dist/base}/ActionFilter.js.map +0 -0
  58. package/{base → dist/base}/BaseError.js +0 -0
  59. package/{base → dist/base}/BaseError.js.map +0 -0
  60. package/{base → dist/base}/BaseObject.js +0 -0
  61. package/{base → dist/base}/BaseObject.js.map +0 -0
  62. package/{base → dist/base}/Behavior.js +0 -0
  63. package/{base → dist/base}/Behavior.js.map +0 -0
  64. package/{base → dist/base}/Component.js +0 -0
  65. package/{base → dist/base}/Component.js.map +0 -0
  66. package/{base → dist/base}/Configurable.js +0 -0
  67. package/{base → dist/base}/Configurable.js.map +0 -0
  68. package/{base → dist/base}/Controller.js +0 -0
  69. package/{base → dist/base}/Controller.js.map +0 -0
  70. package/{base → dist/base}/DataErrorDbException.js +0 -0
  71. package/{base → dist/base}/DataErrorDbException.js.map +0 -0
  72. package/{base → dist/base}/DbConnection.js +0 -0
  73. package/{base → dist/base}/DbConnection.js.map +0 -0
  74. package/{base → dist/base}/ForbiddenHttpException.js +0 -0
  75. package/{base → dist/base}/ForbiddenHttpException.js.map +0 -0
  76. package/{base → dist/base}/InvalidConfigException.js +0 -0
  77. package/{base → dist/base}/InvalidConfigException.js.map +0 -0
  78. package/{base → dist/base}/Model.js +32 -28
  79. package/dist/base/Model.js.map +1 -0
  80. package/dist/base/ModelManager.js +17 -0
  81. package/dist/base/ModelManager.js.map +1 -0
  82. package/{base → dist/base}/NotFoundHttpException.js +0 -0
  83. package/{base → dist/base}/NotFoundHttpException.js.map +0 -0
  84. package/{base → dist/base}/RestClient.js +0 -0
  85. package/{base → dist/base}/RestClient.js.map +0 -0
  86. package/{base → dist/base}/UnauthorizedHttpException.js +0 -0
  87. package/{base → dist/base}/UnauthorizedHttpException.js.map +0 -0
  88. package/{base → dist/base}/ValidationHttpException.js +0 -0
  89. package/{base → dist/base}/ValidationHttpException.js.map +0 -0
  90. package/{base → dist/base}/db/Exception.js +0 -0
  91. package/{base → dist/base}/db/Exception.js.map +0 -0
  92. package/{base → dist/base}/index.js +1 -0
  93. package/{base → dist/base}/index.js.map +1 -1
  94. package/{decorator → dist/decorator}/Middleware.js +0 -0
  95. package/{decorator → dist/decorator}/Middleware.js.map +0 -0
  96. package/{decorator → dist/decorator}/controller.js +0 -0
  97. package/{decorator → dist/decorator}/controller.js.map +0 -0
  98. package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js +0 -0
  99. package/{decorator → dist/decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  100. package/{decorator → dist/decorator}/get.js +0 -0
  101. package/{decorator → dist/decorator}/get.js.map +0 -0
  102. package/{decorator → dist/decorator}/index.js +0 -0
  103. package/{decorator → dist/decorator}/index.js.map +0 -0
  104. package/{decorator → dist/decorator}/post.js +0 -0
  105. package/{decorator → dist/decorator}/post.js.map +0 -0
  106. package/{filters → dist/filters}/AccessControl.js +0 -0
  107. package/{filters → dist/filters}/AccessControl.js.map +0 -0
  108. package/{filters → dist/filters}/AccessRule.js +0 -0
  109. package/{filters → dist/filters}/AccessRule.js.map +0 -0
  110. package/{filters → dist/filters}/auth/AuthInterface.js +0 -0
  111. package/{filters → dist/filters}/auth/AuthInterface.js.map +0 -0
  112. package/{filters → dist/filters}/auth/AuthMethod.js +0 -0
  113. package/{filters → dist/filters}/auth/AuthMethod.js.map +0 -0
  114. package/{filters → dist/filters}/auth/HttpBasicAuth.js +0 -0
  115. package/{filters → dist/filters}/auth/HttpBasicAuth.js.map +0 -0
  116. package/{filters → dist/filters}/auth/HttpBearerAuth.js +0 -0
  117. package/{filters → dist/filters}/auth/HttpBearerAuth.js.map +0 -0
  118. package/{filters → dist/filters}/auth/HttpHeaderAuth.js +0 -0
  119. package/{filters → dist/filters}/auth/HttpHeaderAuth.js.map +0 -0
  120. package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js +0 -0
  121. package/{filters → dist/filters}/auth/JwtHttpBearerAuth.js.map +0 -0
  122. package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  123. package/{filters → dist/filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  124. package/{filters → dist/filters}/auth/index.js +0 -0
  125. package/{filters → dist/filters}/auth/index.js.map +0 -0
  126. package/{filters → dist/filters}/index.js +0 -0
  127. package/{filters → dist/filters}/index.js.map +0 -0
  128. package/{index.js → dist/index.js} +0 -0
  129. package/{index.js.map → dist/index.js.map} +0 -0
  130. package/dist/log/config/log4js.json +55 -0
  131. package/{model → dist/model}/RouteDefinition.js +0 -0
  132. package/{model → dist/model}/RouteDefinition.js.map +0 -0
  133. package/{requiments → dist/requiments}/Glob.js +0 -0
  134. package/{requiments → dist/requiments}/Glob.js.map +0 -0
  135. package/{requiments → dist/requiments}/ReflectUtil.js +0 -0
  136. package/{requiments → dist/requiments}/ReflectUtil.js.map +0 -0
  137. package/{requiments → dist/requiments}/Utils.js +0 -0
  138. package/{requiments → dist/requiments}/Utils.js.map +0 -0
  139. package/{validators → dist/validators}/BooleanValidator.js +0 -0
  140. package/{validators → dist/validators}/BooleanValidator.js.map +0 -0
  141. package/{validators → dist/validators}/CompareValidator.js +0 -0
  142. package/{validators → dist/validators}/CompareValidator.js.map +0 -0
  143. package/{validators → dist/validators}/DateValidator.js +0 -0
  144. package/{validators → dist/validators}/DateValidator.js.map +0 -0
  145. package/{validators → dist/validators}/EmailValidator.js +0 -0
  146. package/{validators → dist/validators}/EmailValidator.js.map +0 -0
  147. package/{validators → dist/validators}/Validator.js +0 -0
  148. package/{validators → dist/validators}/Validator.js.map +0 -0
  149. package/{web → dist/web}/IdentityInterface.js +0 -0
  150. package/{web → dist/web}/IdentityInterface.js.map +0 -0
  151. package/{web → dist/web}/WebUser.js +0 -0
  152. package/{web → dist/web}/WebUser.js.map +0 -0
  153. package/filters/AccessControl.ts +64 -0
  154. package/filters/AccessRule.ts +137 -0
  155. package/filters/auth/AuthInterface.ts +34 -0
  156. package/filters/auth/AuthMethod.ts +88 -0
  157. package/filters/auth/HttpBasicAuth.ts +7 -0
  158. package/filters/auth/HttpBearerAuth.ts +31 -0
  159. package/filters/auth/HttpHeaderAuth.ts +53 -0
  160. package/filters/auth/JwtHttpBearerAuth.ts +80 -0
  161. package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
  162. package/filters/auth/index.ts +3 -0
  163. package/filters/index.ts +2 -0
  164. package/index.ts +14 -0
  165. package/model/RouteDefinition.ts +18 -0
  166. package/package-lock.json +5259 -0
  167. package/package.json +3 -3
  168. package/requiments/Glob.ts +9 -0
  169. package/requiments/ReflectUtil.ts +26 -0
  170. package/requiments/Utils.ts +57 -0
  171. package/tsconfig.json +18 -0
  172. package/validators/BooleanValidator.ts +0 -0
  173. package/validators/CompareValidator.ts +0 -0
  174. package/validators/DateValidator.ts +0 -0
  175. package/validators/EmailValidator.ts +0 -0
  176. package/validators/Validator.ts +27 -0
  177. package/web/IdentityInterface.ts +62 -0
  178. package/web/WebUser.ts +100 -0
  179. package/BaseChyz.js.map +0 -1
  180. package/base/Model.js.map +0 -1
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "edis-manager-node",
3
+ "version": "1.0.0",
4
+ "description": "Entranet ve Erken Deprem Bildirim Sistemi (EDİS) entegrasyonu",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "dev": "nodemon index.ts",
8
+ "debug": "ts-node index.ts",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/cihan53/edis-manager-node.git"
14
+ },
15
+ "author": "",
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/cihan53/edis-manager-node/issues"
19
+ },
20
+ "homepage": "https://github.com/cihan53/edis-manager-node#readme",
21
+ "dependencies": {
22
+ "babel-plugin-transform-decorators-legacy": "^1.3.5",
23
+ "bcrypt": "^5.0.1",
24
+ "body-parser": "^1.19.0",
25
+ "dotenv-flow": "^3.2.0",
26
+ "express": "^4.17.1",
27
+ "glob": "^7.1.7",
28
+ "jsonwebtoken": "^8.5.1",
29
+ "keycloak-connect": "^15.0.2",
30
+ "lodash": "^4.17.21",
31
+ "log4js": "^6.3.0",
32
+ "method-override": "^3.0.0",
33
+ "passport": "^0.4.1",
34
+ "pg": "^8.7.1",
35
+ "pg-hstore": "^2.3.4",
36
+ "reflect-metadata": "^0.1.13",
37
+ "sequelize": "^6.6.5"
38
+ },
39
+ "devDependencies": {
40
+ "@types/express": "^4.17.13",
41
+ "@types/node": "^16.4.13",
42
+ "nodemon": "^2.0.12",
43
+ "ts-node": "^10.2.0",
44
+ "typescript": "^4.3.5"
45
+ }
46
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "experimentalDecorators": true,
5
+ "emitDecoratorMetadata": true,
6
+ // "isolatedModules": true,
7
+ "removeComments": true,
8
+ // "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "moduleResolution": "node"
11
+ },
12
+ "exclude": [
13
+ "node_modules"
14
+ ],
15
+ "include": [
16
+ "__tests__/**/*.ts",
17
+ "Controllers/**/*.ts",
18
+ "Models/**/*.ts",
19
+ "environment.d.ts",
20
+ ]
21
+ }
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+ import {NextFunction, Request, Response} from "express";
9
+ import Utils from "../requiments/Utils";
10
+ import {Behavior} from "./Behavior";
11
+
12
+ export class ActionFilter extends Behavior {
13
+
14
+ public only: any;
15
+
16
+ /**
17
+ * @var array list of action IDs that this filter should not apply to.
18
+ * @see only
19
+ */
20
+ public except = [];
21
+
22
+
23
+ public init() {
24
+
25
+ }
26
+
27
+ public async beforeFilter(route: any, req: Request, res: Response) {
28
+ if (!this.isActive(route)) {
29
+ return;
30
+ }
31
+
32
+ await this.beforeAction(route, req, res)
33
+ }
34
+
35
+ protected isActive(action: any) {
36
+ let id = action.id;
37
+ let onlyMatch: boolean = false;
38
+ let exceptMatch: boolean = false;
39
+ if (Utils.isEmpty(this.only)) {
40
+ onlyMatch = true;
41
+ } else {
42
+ onlyMatch = false;
43
+ for (const onlyKey of this.only) {
44
+ if (Utils.matchWildcard(action, onlyKey)) {
45
+ onlyMatch = true;
46
+ break;
47
+ }
48
+ }
49
+ }
50
+
51
+ for (const exceptKey in this.except) {
52
+ let pattern = this.except[exceptKey];
53
+ let match = id.match(pattern)
54
+ if (match && match.length > 0) {
55
+ exceptMatch = true;
56
+ }
57
+ }
58
+
59
+ return !exceptMatch && onlyMatch;
60
+ }
61
+
62
+ /**
63
+ * This method is invoked right before an action is to be executed (after all possible filters.)
64
+ * You may override this method to do last-minute preparation for the action.
65
+ * @param Action $action the action to be executed.
66
+ * @return bool whether the action should continue to be executed.
67
+ */
68
+ public async beforeAction(route: any, req: Request, res: Response) {
69
+ return true;
70
+ }
71
+ }
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ export class BaseError extends Error {
9
+ private statusCode: number;
10
+
11
+ constructor(message: string,statusCode=500) {
12
+ super(message);
13
+ this.message=message;
14
+ this.name = this.constructor.name // good practice
15
+ this.statusCode = statusCode // error code for responding to client
16
+ Error.captureStackTrace(this)
17
+ }
18
+
19
+ toString(){
20
+ return `${this.name}[${this.statusCode}] ${this.message}`
21
+ }
22
+ toJSON(){
23
+ return {code: this?.statusCode, name: this.name, message: this.message}
24
+ }
25
+ }
26
+
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {Configurable} from "./Configurable";
9
+ import BaseChyz from "../BaseChyz";
10
+
11
+ export class BaseObject implements Configurable {
12
+
13
+
14
+ public init() {
15
+
16
+ BaseChyz.debug("BaseObject init.....",)
17
+
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ import {BaseObject} from "./BaseObject";
2
+
3
+ export class Behavior extends BaseObject
4
+ {
5
+
6
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseObject} from "./BaseObject";
9
+ import {ActionFilter} from "./ActionFilter";
10
+ import Utils from "../requiments/Utils";
11
+
12
+ export class Component extends BaseObject {
13
+
14
+ /**
15
+ * @var array the attached event handlers (event name => handlers)
16
+ */
17
+ private _events = [];
18
+
19
+
20
+ /**
21
+ * @var Behavior[]|null the attached behaviors (behavior name => behavior). This is `null` when not initialized.
22
+ */
23
+
24
+ private _behaviors: Array<ActionFilter> = [];
25
+
26
+
27
+ /**
28
+ * Returns a list of behaviors that this component should behave as.
29
+ */
30
+ public behaviors() {
31
+ return [];
32
+ }
33
+
34
+
35
+ get getBehaviors(): any {
36
+ return this._behaviors;
37
+ }
38
+
39
+ /**
40
+ * Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
41
+ */
42
+ public ensureBehaviors() {
43
+ if (this._behaviors.length == 0) {
44
+ this._behaviors = [];
45
+ if (this.behaviors().length > 0) {
46
+ this.behaviors().forEach(behavior => {
47
+ Object.keys(behavior).forEach((name: string) => {
48
+ this.attachBehaviorInternal(name, behavior)
49
+ });
50
+ })
51
+ }
52
+
53
+ }
54
+ }
55
+
56
+
57
+ private attachBehaviorInternal(name: any, behavior: any) {
58
+ if (!this._behaviors.hasOwnProperty(name)) {
59
+ let beh = Utils.createObject(new behavior[name].class, behavior[name])
60
+ beh.init()
61
+ this._behaviors[name] = beh;
62
+ }
63
+ return behavior;
64
+ }
65
+
66
+ }
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ export interface Configurable{
9
+
10
+ }
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {Component} from "./Component";
9
+ import {RouteDefinition} from "../model/RouteDefinition";
10
+ import {Request, Response} from "express";
11
+
12
+ export class Controller extends Component {
13
+
14
+
15
+ /**
16
+ * @var string the ID of this controller.
17
+ */
18
+ public id: string;
19
+ public defaultAction = 'index';
20
+
21
+ constructor(config: any) {
22
+ super();
23
+ this.id = this.constructor.name.replace("Controller", "").toLowerCase();
24
+ }
25
+
26
+ public init() {
27
+ super.init();
28
+ }
29
+
30
+
31
+ /**
32
+ * This method is invoked right before an action is executed.
33
+ * @param $action
34
+ */
35
+ public async beforeAction(route: RouteDefinition, req: Request, res: Response) {
36
+ if (route.id == "" || route.id == "/")
37
+ this.id = this.defaultAction
38
+
39
+ this.ensureBehaviors()
40
+ for (const name of Object.keys(this.getBehaviors)) {
41
+ await this.getBehaviors[name].beforeFilter(route, req, res);
42
+ }
43
+
44
+ }
45
+
46
+ /**
47
+ * This method is invoked right after an action is executed.
48
+ * @param action
49
+ */
50
+ public afterAction(action: any, req: Request, res: Response) {
51
+
52
+ }
53
+
54
+ /**
55
+ *
56
+
57
+ Checks the privilege of the current user.
58
+
59
+ This method should be overridden to check whether the current user has the privilege to run the specified action against the specified data model. If the user does not have access, a yii\web\ForbiddenHttpException should be thrown.
60
+
61
+ */
62
+ public checkAccess(action: any, model = null, params: any = []) {
63
+
64
+ }
65
+
66
+ /**
67
+ * Send data formatted as JSON.
68
+
69
+ This method is a shortcut for sending data formatted as JSON. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will b
70
+ */
71
+ asJson(data: any) {
72
+
73
+ }
74
+
75
+ /**
76
+ * Send data formatted as XML.
77
+
78
+ This method is a shortcut for sending data formatted as XML. It will return the response application component after configuring the format and setting the data that should be formatted. A common usage will be:
79
+ */
80
+ asXml(data: any) {
81
+
82
+ }
83
+
84
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+
10
+ import {BaseError} from "./BaseError";
11
+
12
+ export class DataErrorDbException extends BaseError {
13
+ constructor ( public message: string) {
14
+ super(message,502);
15
+ }
16
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+ const {Sequelize} = require("sequelize");
9
+ import {Component} from "./Component";
10
+ import BaseChyz from "../BaseChyz";
11
+
12
+ export class DbConnection extends Component {
13
+
14
+ public database!: string;
15
+ public username!: string
16
+ public password!: string
17
+ public options?: object
18
+ public _transaction:any;
19
+
20
+ private _db: any
21
+
22
+ async init() {
23
+ const sequelize = new Sequelize(this.database, this.username, this.password, this.options);
24
+ this._db = sequelize;
25
+ sequelize
26
+ .authenticate()
27
+ .then(() => {
28
+ BaseChyz.info('Connection has been established successfully.');
29
+ })
30
+ .catch((err: any) => {
31
+ BaseChyz.error('Unable to connect to the database:', err);
32
+
33
+ });
34
+
35
+ // await this.connect();
36
+ }
37
+
38
+
39
+ get db(): any {
40
+ return this._db;
41
+ }
42
+
43
+ set db(value: any) {
44
+ this._db = value;
45
+ }
46
+
47
+ public transaction(){
48
+ return this.db.transaction();
49
+ }
50
+
51
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+ export class ForbiddenHttpException extends BaseError {
10
+ constructor ( message: string) {
11
+ super(message,403);
12
+ }
13
+ }
14
+
15
+
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+
9
+
10
+ import {BaseError} from "./BaseError";
11
+
12
+ export class InvalidConfigException extends BaseError {
13
+ constructor ( public message: string) {
14
+ super(message,500);
15
+ }
16
+ }