chyz 1.0.13-rc.19 → 1.0.13-rc.4

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 (211) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +8 -46
  2. package/BaseChyz.js.map +1 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/README.md +16 -267
  6. package/{dist/base → base}/ActionFilter.js +1 -1
  7. package/{dist/base → base}/ActionFilter.js.map +1 -1
  8. package/{dist/base → base}/BaseError.js +1 -5
  9. package/base/BaseError.js.map +1 -0
  10. package/{dist/base → base}/BaseObject.js +0 -0
  11. package/{dist/base → base}/BaseObject.js.map +0 -0
  12. package/{dist/base → base}/Behavior.js +0 -0
  13. package/{dist/base → base}/Behavior.js.map +0 -0
  14. package/{dist/base → base}/Component.js +0 -0
  15. package/{dist/base → base}/Component.js.map +0 -0
  16. package/{dist/base → base}/Configurable.js +0 -0
  17. package/{dist/base → base}/Configurable.js.map +0 -0
  18. package/{dist/base → base}/Controller.js +0 -0
  19. package/{dist/base → base}/Controller.js.map +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js +0 -0
  21. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  22. package/{dist/base → base}/DbConnection.js +0 -0
  23. package/{dist/base → base}/DbConnection.js.map +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  25. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  26. package/{dist/base → base}/InvalidConfigException.js +0 -0
  27. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  28. package/{dist/base → base}/Model.js +30 -37
  29. package/base/Model.js.map +1 -0
  30. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  31. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  32. package/{dist/base → base}/RestClient.js +4 -4
  33. package/base/RestClient.js.map +1 -0
  34. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  35. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  36. package/{dist/base → base}/ValidationHttpException.js +1 -1
  37. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  38. package/{dist/base → base}/db/Exception.js +0 -0
  39. package/{dist/base → base}/db/Exception.js.map +0 -0
  40. package/{dist/base → base}/index.js +0 -2
  41. package/{dist/base → base}/index.js.map +1 -1
  42. package/{dist/decorator → decorator}/Middleware.js +0 -0
  43. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  44. package/{dist/decorator → decorator}/controller.js +0 -0
  45. package/{dist/decorator → decorator}/controller.js.map +0 -0
  46. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  47. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  48. package/{dist/decorator → decorator}/get.js +0 -0
  49. package/{dist/decorator → decorator}/get.js.map +0 -0
  50. package/{dist/decorator → decorator}/index.js +0 -0
  51. package/{dist/decorator → decorator}/index.js.map +0 -0
  52. package/{dist/decorator → decorator}/post.js +0 -0
  53. package/{dist/decorator → decorator}/post.js.map +0 -0
  54. package/{dist/filters → filters}/AccessControl.js +3 -15
  55. package/filters/AccessControl.js.map +1 -0
  56. package/filters/AccessRule.js +79 -0
  57. package/filters/AccessRule.js.map +1 -0
  58. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  59. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  60. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  61. package/{dist/filters → filters}/auth/AuthMethod.js.map +0 -0
  62. package/{requiments/Glob.ts → filters/auth/HttpBasicAuth.js} +2 -3
  63. package/filters/auth/HttpBasicAuth.js.map +1 -0
  64. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  65. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  66. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  67. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  68. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +1 -1
  69. package/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  70. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  71. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  72. package/{dist/filters → filters}/auth/index.js +0 -1
  73. package/{dist/filters → filters}/auth/index.js.map +1 -1
  74. package/{dist/filters → filters}/index.js +0 -0
  75. package/{dist/filters → filters}/index.js.map +0 -0
  76. package/{dist/index.js → index.js} +0 -0
  77. package/{dist/index.js.map → index.js.map} +0 -0
  78. package/{dist/model → model}/RouteDefinition.js +0 -0
  79. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  80. package/package.json +7 -6
  81. package/{dist/requiments → requiments}/Glob.js +0 -0
  82. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  83. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  84. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  85. package/{dist/requiments → requiments}/Utils.js +0 -0
  86. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  87. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  88. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  89. package/{dist/validators → validators}/CompareValidator.js +0 -0
  90. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  91. package/{dist/validators → validators}/DateValidator.js +0 -0
  92. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  93. package/{dist/validators → validators}/EmailValidator.js +0 -0
  94. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  95. package/{dist/validators → validators}/Validator.js +0 -0
  96. package/{dist/validators → validators}/Validator.js.map +0 -0
  97. package/{dist/web → web}/IdentityInterface.js +0 -0
  98. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  99. package/web/WebUser.js +88 -0
  100. package/web/WebUser.js.map +1 -0
  101. package/BaseChyz.ts +0 -399
  102. package/Chyz.ts +0 -11
  103. package/Doc/Moel kullanma.md +0 -13
  104. package/Examples/Controllers/ApiController.ts +0 -140
  105. package/Examples/Controllers/BasicApiController.ts +0 -121
  106. package/Examples/Controllers/KeyCloakController.ts +0 -100
  107. package/Examples/Controllers/PublicController.ts +0 -42
  108. package/Examples/Controllers/SiteController.ts +0 -149
  109. package/Examples/Models/AuthAssignment.ts +0 -50
  110. package/Examples/Models/AuthItem.ts +0 -59
  111. package/Examples/Models/AuthItemChild.ts +0 -49
  112. package/Examples/Models/Categories.ts +0 -47
  113. package/Examples/Models/Customer.ts +0 -115
  114. package/Examples/Models/KeycloakUser.ts +0 -70
  115. package/Examples/Models/Order.ts +0 -64
  116. package/Examples/Models/OrderItem.ts +0 -27
  117. package/Examples/Models/ProductModels.ts +0 -49
  118. package/Examples/Models/ProductToCategories.ts +0 -46
  119. package/Examples/Models/Products.ts +0 -50
  120. package/Examples/Models/Stocks.ts +0 -60
  121. package/Examples/Models/User.ts +0 -107
  122. package/Examples/Models/UserPermission.ts +0 -37
  123. package/Examples/Models/index.ts +0 -19
  124. package/Examples/index-keycloack.ts +0 -78
  125. package/Examples/index.ts +0 -45
  126. package/Examples/keycloak.json +0 -7
  127. package/Examples/log/access.log +0 -0
  128. package/Examples/log/app.log +0 -10379
  129. package/Examples/log/errors.log +0 -1984
  130. package/Examples/package.json +0 -46
  131. package/Examples/tsconfig.json +0 -21
  132. package/base/ActionFilter.ts +0 -71
  133. package/base/BaseError.ts +0 -28
  134. package/base/BaseObject.ts +0 -19
  135. package/base/Behavior.ts +0 -6
  136. package/base/Component.ts +0 -66
  137. package/base/Configurable.ts +0 -10
  138. package/base/Controller.ts +0 -84
  139. package/base/DataErrorDbException.ts +0 -16
  140. package/base/DbConnection.ts +0 -51
  141. package/base/ForbiddenHttpException.ts +0 -15
  142. package/base/InvalidArgumentException.ts +0 -16
  143. package/base/InvalidConfigException.ts +0 -16
  144. package/base/Model.ts +0 -363
  145. package/base/ModelManager.ts +0 -19
  146. package/base/NotFoundHttpException.ts +0 -14
  147. package/base/RestClient.ts +0 -28
  148. package/base/UnauthorizedHttpException.ts +0 -17
  149. package/base/ValidationHttpException.ts +0 -14
  150. package/base/db/Exception.ts +0 -14
  151. package/base/index.ts +0 -18
  152. package/decorator/Middleware.ts +0 -9
  153. package/decorator/controller.ts +0 -22
  154. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  155. package/decorator/get.ts +0 -37
  156. package/decorator/index.ts +0 -3
  157. package/decorator/post.ts +0 -36
  158. package/dist/BaseChyz.js.map +0 -1
  159. package/dist/base/BaseError.js.map +0 -1
  160. package/dist/base/InvalidArgumentException.js +0 -18
  161. package/dist/base/InvalidArgumentException.js.map +0 -1
  162. package/dist/base/Model.js.map +0 -1
  163. package/dist/base/ModelManager.js +0 -9
  164. package/dist/base/ModelManager.js.map +0 -1
  165. package/dist/base/RestClient.js.map +0 -1
  166. package/dist/filters/AccessControl.js.map +0 -1
  167. package/dist/filters/AccessRule.js +0 -140
  168. package/dist/filters/AccessRule.js.map +0 -1
  169. package/dist/filters/auth/HttpBasicAuth.js +0 -73
  170. package/dist/filters/auth/HttpBasicAuth.js.map +0 -1
  171. package/dist/filters/auth/JwtHttpBearerAuth.js.map +0 -1
  172. package/dist/log/config/log4js.json +0 -55
  173. package/dist/package.json +0 -55
  174. package/dist/rbac/AuthAssignment.js +0 -45
  175. package/dist/rbac/AuthAssignment.js.map +0 -1
  176. package/dist/rbac/AuthItem.js +0 -52
  177. package/dist/rbac/AuthItem.js.map +0 -1
  178. package/dist/rbac/AuthItemChild.js +0 -44
  179. package/dist/rbac/AuthItemChild.js.map +0 -1
  180. package/dist/rbac/AuthManager.js +0 -359
  181. package/dist/rbac/AuthManager.js.map +0 -1
  182. package/dist/web/WebUser.js +0 -166
  183. package/dist/web/WebUser.js.map +0 -1
  184. package/filters/AccessControl.ts +0 -77
  185. package/filters/AccessRule.ts +0 -182
  186. package/filters/auth/AuthInterface.ts +0 -34
  187. package/filters/auth/AuthMethod.ts +0 -88
  188. package/filters/auth/HttpBasicAuth.ts +0 -75
  189. package/filters/auth/HttpBearerAuth.ts +0 -31
  190. package/filters/auth/HttpHeaderAuth.ts +0 -53
  191. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  192. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  193. package/filters/auth/index.ts +0 -4
  194. package/filters/index.ts +0 -2
  195. package/index.ts +0 -14
  196. package/model/RouteDefinition.ts +0 -18
  197. package/package-lock.json +0 -5259
  198. package/rbac/AuthAssignment.ts +0 -50
  199. package/rbac/AuthItem.ts +0 -57
  200. package/rbac/AuthItemChild.ts +0 -50
  201. package/rbac/AuthManager.ts +0 -398
  202. package/requiments/ReflectUtil.ts +0 -26
  203. package/requiments/Utils.ts +0 -57
  204. package/tsconfig.json +0 -18
  205. package/validators/BooleanValidator.ts +0 -0
  206. package/validators/CompareValidator.ts +0 -0
  207. package/validators/DateValidator.ts +0 -0
  208. package/validators/EmailValidator.ts +0 -0
  209. package/validators/Validator.ts +0 -27
  210. package/web/IdentityInterface.ts +0 -68
  211. package/web/WebUser.ts +0 -187
package/BaseChyz.ts DELETED
@@ -1,399 +0,0 @@
1
- import 'reflect-metadata';
2
- import {RouteDefinition} from "./model/RouteDefinition";
3
- import {NextFunction, Request, Response} from "express";
4
- import {Controller} from "./base/Controller";
5
- import Utils from "./requiments/Utils";
6
- import {ModelManager} from "./base";
7
-
8
-
9
- const express = require("express");
10
- const log4js = require("log4js");
11
- const fs = require('fs');
12
- const validate = require('validate.js');
13
-
14
- var ip = require('ip');
15
- var bodyParser = require('body-parser')
16
- var methodOverride = require('method-override')
17
-
18
- export {Request, Response, NextFunction} from "express";
19
- export default class BaseChyz {
20
- private config: any;
21
- static app: string;
22
- static express = express()
23
- private _port: number = 3001;
24
- static db: any;
25
- static routes: any;
26
- private static _validate:any=validate;
27
- private _logConfig: any = require('./log/config/log4js.json') ?? {}
28
- private _controllerpath: string = "Controllers"
29
- private static controllers: Array<Controller> = []
30
- public static components: any = {}
31
- public static middlewares: any = {}
32
-
33
-
34
- get logConfig(): any {
35
- return this._logConfig;
36
- }
37
-
38
- set logConfig(value: any) {
39
- this._logConfig = value;
40
- }
41
-
42
- get controllerpath(): string {
43
- return this._controllerpath;
44
- }
45
-
46
- set controllerpath(value: string) {
47
- this._controllerpath = value;
48
- }
49
-
50
- init() {
51
- this.logProvider().level = log4js.levels.ALL;
52
- this.logProvider().configure(this._logConfig);
53
-
54
- /**
55
- * set request id
56
- */
57
- Object.defineProperty(BaseChyz.express.request, 'reqId', {
58
- configurable: true,
59
- enumerable: true,
60
- writable: true
61
- })
62
-
63
- Object.defineProperty(BaseChyz.express.request, 'user', {
64
- configurable: true,
65
- enumerable: true,
66
- writable: true
67
- })
68
-
69
- Object.defineProperty(BaseChyz.express.request, 'identity', {
70
- configurable: true,
71
- enumerable: true,
72
- writable: true
73
- })
74
-
75
-
76
- /**
77
- * server port setting
78
- */
79
- if (this.config.hasOwnProperty("port"))
80
- this.port = this.config.port;
81
-
82
- /**
83
- * controller path
84
- */
85
- if (this.config.controllerpath) {
86
- this.controllerpath = this.config.controllerpath
87
- }
88
-
89
-
90
- /**
91
- * Model Register
92
- */
93
-
94
- this.loadModels();
95
-
96
- /**
97
- * Express Server
98
- */
99
- this.middleware()
100
-
101
- /**
102
- * Load Controller
103
- */
104
- this.loadController();
105
-
106
-
107
- }
108
-
109
- /**
110
- * Listen port number
111
- * Server port number get
112
- */
113
- get port(): number {
114
- return this._port;
115
- }
116
-
117
- /**
118
- * Listen port number
119
- * Server port number setting
120
- * @param value
121
- */
122
- set port(value: number) {
123
- this._port = value;
124
- }
125
-
126
-
127
- static get validate(): any {
128
- return this._validate;
129
- }
130
-
131
- static set validate(value: any) {
132
- this._validate = value;
133
- }
134
-
135
- app(config: any = {}): BaseChyz {
136
-
137
- /**
138
- * Config set
139
- */
140
- this.config = config;
141
-
142
-
143
- let components = Utils.findKeyValue(config, "components")
144
- if (components) {
145
- for (const componentsKey in components) {
146
- let comp = components[componentsKey];
147
- BaseChyz.logs().info("Create Component ", componentsKey)
148
- try {
149
- BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
150
- BaseChyz.components[componentsKey]?.init();
151
- }catch (e) {
152
- console.error(e)
153
- }
154
-
155
- }
156
- }
157
-
158
-
159
- let middlewares = Utils.findKeyValue(config, "middlewares")
160
- if (middlewares) {
161
- for (const middlewareKey in middlewares) {
162
- let middleware1 = middlewares[middlewareKey];
163
- BaseChyz.logs().debug("Create middlewares ", middlewareKey)
164
- BaseChyz.middlewares[middlewareKey] = middleware1;
165
- // BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
166
- }
167
- }
168
-
169
-
170
- this.init();
171
-
172
- return this;
173
- }
174
-
175
-
176
- public logProvider() {
177
- return log4js;
178
- }
179
-
180
- public getLogger() {
181
- return this.logProvider().getLogger(this.constructor.name);
182
- }
183
-
184
- static logs(...args: any[]) {
185
- return log4js.getLogger(this.name);
186
- }
187
-
188
- public static trace(...args: any[]) {
189
- BaseChyz.logs().fatal(...arguments)
190
- }
191
-
192
- public static debug(...args: any[]) {
193
- BaseChyz.logs().debug(...arguments)
194
- }
195
-
196
- public static info(...args: any[]) {
197
- BaseChyz.logs().info(...arguments)
198
- }
199
-
200
- public static warn(...args: any[]) {
201
- BaseChyz.logs().warn(...arguments)
202
- }
203
-
204
- public static error(...args: any[]) {
205
- BaseChyz.logs().error(...arguments)
206
- }
207
-
208
- public static fatal(...args: any[]) {
209
- BaseChyz.logs().fatal(...arguments)
210
- }
211
-
212
-
213
- public static warning(...args: any[]) {
214
- BaseChyz.logs().warn(...arguments)
215
- }
216
-
217
- public static t(text: string) {
218
- return text;
219
- }
220
-
221
-
222
- public errorLogger(error: any, req: any, res: any, next: any) { // for logging errors
223
- BaseChyz.error(error)
224
- next(error) // forward to next middleware
225
- }
226
-
227
- public errorResponder(error: any, req: any, res: any, next: any) { // responding to client
228
- if (error.type == 'redirect')
229
- res.redirect('/error')
230
- else if (error.type == 'time-out') // arbitrary condition check
231
- res.status(408).json(error)
232
- else
233
- next(error) // forwarding exceptional case to fail-safe middleware
234
- }
235
-
236
-
237
- public errorHandler(err: any, req: any, res: any, next: any) {
238
- if (res.headersSent) {
239
- return next(err)
240
- }
241
- res.status(500)
242
- res.json('error', {error: err})
243
- }
244
-
245
- public static getComponent(key: any) {
246
- return BaseChyz.components[key] ?? null
247
- }
248
-
249
-
250
- public static getMiddlewares(key: any) {
251
- return BaseChyz.middlewares[key] ?? null
252
- }
253
-
254
- /**
255
- * load model
256
- */
257
- async loadModels() {
258
- let models: any = {}
259
- let path = `${this._controllerpath}/../Models`;
260
- fs.readdirSync(path).forEach((file: string) => {
261
- if (file !== "index.ts") {
262
- let model = require(`${path}/${file}`);
263
- // @ts-ignore
264
- let className = file.split(".")[0] + "Class";
265
- if (model[className])
266
- models[className.replace("Class","")] = new model[className];
267
- }
268
- })
269
-
270
- ModelManager._register(models);
271
-
272
- for (const key of Object.keys(ModelManager)) {
273
- if(key!="_register"){
274
- ModelManager[key].init();
275
- }
276
- }
277
- }
278
-
279
- /**
280
- * load contoller
281
- */
282
- async loadController() {
283
- let articlesEndpoints: string[] = [];
284
- fs.readdirSync(`${this._controllerpath}/`).forEach((file: string) => {
285
- let controller = require(`${this._controllerpath}/${file}`);
286
-
287
- // This is our instantiated class
288
- const instance: Controller = new controller();
289
-
290
- BaseChyz.controllers.push(instance);
291
-
292
- // The prefix saved to our controller
293
- // @ts-ignore
294
- const prefix = Reflect.getMetadata('prefix', controller);
295
- // Our `routes` array containing all our routes for this controller
296
- // @ts-ignore
297
- const routes: Array<RouteDefinition> = Reflect.getMetadata('routes', controller);
298
- BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`)
299
-
300
- if (routes) {
301
- routes.forEach(route => {
302
-
303
- let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
304
- route.id = actionId;
305
- BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`))
306
-
307
- BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`),
308
- async (req: Request, res: Response, next: NextFunction) => {
309
- try {
310
- BaseChyz.debug(`Call Request id ${instance.id}`)
311
- await instance.beforeAction(route, req, res)
312
- next()
313
- } catch (e) {
314
- BaseChyz.error(e);
315
-
316
- res.status(e.statusCode || 500)
317
- res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
318
- // next(e)
319
- }
320
-
321
- },
322
- async (req: Request, res: Response, next: NextFunction) => {
323
- try {
324
- // @ts-ignore
325
- BaseChyz.debug("Request ID ", req.reqId)
326
- // @ts-ignore
327
- await instance[route.methodName](req, res, next);
328
- instance.afterAction(route, req, res);
329
- } catch (e) {
330
- if (e instanceof Error) {
331
- BaseChyz.error(e)
332
-
333
- // @ts-ignore
334
- res.status(e.statusCode || 500)
335
- // @ts-ignore
336
- res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
337
- } else {
338
- res.json(e)
339
- }
340
- }
341
- })
342
-
343
-
344
- });
345
- }
346
- })
347
- }
348
-
349
- public middleware() {
350
-
351
- BaseChyz.express.use(bodyParser.json())
352
- BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
353
- BaseChyz.express.use(methodOverride());
354
- BaseChyz.express.use(methodOverride());
355
-
356
-
357
- // CORS
358
- BaseChyz.express.use(function (req: any, res: Response, next: any) {
359
- // @ts-ignore
360
- req.reqId = Utils.uniqueId("chyzzzz_")
361
- res.setHeader('Content-Type', 'application/json');
362
- res.setHeader("Access-Control-Allow-Origin", "*");
363
- res.setHeader("Access-Control-Allow-Credentials", "true");
364
- res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
365
- res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
366
- next();
367
- });
368
-
369
- //Middlewares
370
- for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
371
- if (!Utils.isFunction(middleware1)) {
372
- let keycloak = BaseChyz.middlewares[middleware1].keycloak;
373
- BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
374
- } else {
375
- BaseChyz.express.use(BaseChyz.middlewares[middleware1]);
376
- }
377
-
378
- }
379
-
380
-
381
- BaseChyz.express.use(this.errorResponder)
382
- BaseChyz.express.use(this.errorHandler)
383
- }
384
-
385
-
386
- public Start() {
387
-
388
- BaseChyz.info("Express Server Starting")
389
- BaseChyz.express.listen(this._port, () => {
390
- BaseChyz.info("Express Server Start ")
391
- BaseChyz.info(`Liten Port ${this._port}`)
392
- BaseChyz.info(`http://localhost:${this._port}`)
393
- BaseChyz.info(`http://${ip.address()}:${this._port}`)
394
- })
395
- return this;
396
- }
397
-
398
-
399
- }
package/Chyz.ts DELETED
@@ -1,11 +0,0 @@
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 BaseChyz from "./BaseChyz";
9
- const Chyz = new BaseChyz();
10
-
11
- export default Chyz;
@@ -1,13 +0,0 @@
1
- ##Model
2
-
3
- Model sınıfı "Sequelize" üzerine inşa edildmiştir ( ileriki zamanlarda farklı yöntemlerde eklemeyi planlıyorum)
4
-
5
- ##public function
6
-
7
- ###getDb:
8
- ###get sequelize:
9
- ###set sequelize:
10
- ###get errors:
11
- ###set errors:
12
- ###init:
13
-
@@ -1,140 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
4
- * Author: Cihan Ozturk
5
- * E-mail: cihan@chy.com.tr
6
- * Github:https://github.com/cihan53/
7
- *
8
- */
9
-
10
- import {Controller, ModelManager} from "../../base";
11
- import BaseChyz from "../../BaseChyz";
12
- // @ts-ignore
13
- import {Request, Response} from "express";
14
- import {get} from "../../decorator";
15
- import {post} from "../../decorator";
16
- import {controller} from "../../decorator";
17
- import {JwtHttpBearerAuth} from "../../filters/auth";
18
-
19
- import {ValidationHttpException} from "../../base";
20
- import {ForbiddenHttpException} from "../../base";
21
- import {ProductsClass} from "../Models/Products";
22
- import {AccessControl} from "../../filters";
23
-
24
-
25
- @controller("/api")
26
- class ApiController extends Controller {
27
-
28
- public myCheck(token) {
29
- console.log("myyyyyyyyyyyyyyyyyyyyy")
30
- }
31
-
32
- public behaviors(): any[] {
33
-
34
- return [{
35
- 'authenticator': {
36
- "class": JwtHttpBearerAuth,
37
- // "auth": this.myCheck
38
- },
39
- 'access': {
40
- 'class': AccessControl,
41
- 'only': ['order/list' ],
42
- 'rules': [
43
-
44
- {
45
- 'allow': true,
46
- 'actions': ['order/list' ],
47
- 'roles': ['edis-manager'],
48
- }
49
- ]
50
- }
51
- }]
52
- }
53
-
54
- @get("/")
55
- Index(req: Request, res: Response) {
56
-
57
- BaseChyz.logs().info("Site Controller Burası", this.id)
58
- return res.json({message: "index sayfası"})
59
- }
60
-
61
- @post("orderCreate")
62
- async Login(req: Request, res: Response) {
63
- let data = req.body;
64
- data.Customer.status = "true";
65
- data.Customer["2fa"] = "true";
66
-
67
- //Customer Model Create
68
- let customer = ModelManager.Customer.save();
69
- //Order Model Create
70
- let order = ModelManager.Order;
71
-
72
-
73
- let transaction
74
- try {
75
- // get transaction
76
- transaction = await BaseChyz.getComponent("db").transaction();
77
- customer.load(data, "Customer");//load customer data
78
- let cus: any = await customer.save({}, {transaction});
79
-
80
- if (!cus) {
81
- throw new ValidationHttpException(customer.errors);
82
- }
83
-
84
- data.Order.customer_id = cus.id;
85
- // data.Order.total = 0;
86
- // data.Order.status = true;
87
- order.load(data, "Order");
88
- let res1 = await order.save({}, {transaction});
89
- if (!res1) {
90
- throw new ValidationHttpException(order.errors);
91
- }
92
-
93
- // commit
94
- await transaction.commit();
95
-
96
- } catch (e) {
97
- if (transaction) {
98
- await transaction.rollback();
99
- BaseChyz.warn("Rollback transaction")
100
- }
101
-
102
- if (e instanceof ValidationHttpException)
103
- throw new ValidationHttpException(e.message)
104
- else
105
- throw new ForbiddenHttpException(e.message)
106
- }
107
- return res.send("Post Controller")
108
- }
109
-
110
-
111
- @get("order/list")
112
- async listOrder(req: Request, res: Response) {
113
- const {Products}: { Products: ProductsClass } = ModelManager;
114
- let product = await Products.findAll( );
115
- return res.json(product)
116
-
117
- }
118
-
119
- @get("categories")
120
- async Categories(req: Request, res: Response) {
121
- let product = await ModelManager.Categories.findAll({
122
- include: [
123
- {
124
- model: ModelManager.Products.model(),
125
- // as: 'product',
126
- // through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
127
- }
128
- ]
129
- });
130
- return res.json(product)
131
-
132
- }
133
-
134
- error(req: Request, res: Response) {
135
- BaseChyz.logs().info("Error Sayfası")
136
- return res.send("Post Controller")
137
- }
138
- }
139
-
140
- module.exports = ApiController
@@ -1,121 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
4
- * Author: Cihan Ozturk
5
- * E-mail: cihan@chy.com.tr
6
- * Github:https://github.com/cihan53/
7
- *
8
- */
9
-
10
- import {Controller, ForbiddenHttpException, ModelManager, ValidationHttpException} from "../../base";
11
- import BaseChyz from "../../BaseChyz";
12
- // @ts-ignore
13
- import {Request, Response} from "express";
14
- import {controller, get, post} from "../../decorator";
15
- import {ProductsClass} from "../Models/Products";
16
- import {HttpBasicAuth} from "../../filters/auth/HttpBasicAuth";
17
-
18
-
19
- @controller("/basic/api")
20
- class ApiController extends Controller {
21
-
22
-
23
-
24
- public behaviors(): any[] {
25
-
26
- return [{
27
- 'authenticator': {
28
- "class": HttpBasicAuth,
29
- // "auth": this.myCheck
30
- }
31
- }]
32
- }
33
-
34
- @get("/")
35
- Index(req: Request, res: Response) {
36
-
37
- BaseChyz.logs().info("Site Controller Burası", this.id)
38
- return res.json({message: "index sayfası"})
39
- }
40
-
41
- @post("orderCreate")
42
- async Login(req: Request, res: Response) {
43
- let data = req.body;
44
- data.Customer.status = "true";
45
- data.Customer["2fa"] = "true";
46
-
47
- //Customer Model Create
48
- let customer = ModelManager.Customer.save();
49
- //Order Model Create
50
- let order = ModelManager.Order;
51
-
52
-
53
- let transaction
54
- try {
55
- // get transaction
56
- transaction = await BaseChyz.getComponent("db").transaction();
57
- customer.load(data, "Customer");//load customer data
58
- let cus: any = await customer.save({}, {transaction});
59
-
60
- if (!cus) {
61
- throw new ValidationHttpException(customer.errors);
62
- }
63
-
64
- data.Order.customer_id = cus.id;
65
- // data.Order.total = 0;
66
- // data.Order.status = true;
67
- order.load(data, "Order");
68
- let res1 = await order.save({}, {transaction});
69
- if (!res1) {
70
- throw new ValidationHttpException(order.errors);
71
- }
72
-
73
- // commit
74
- await transaction.commit();
75
-
76
- } catch (e) {
77
- if (transaction) {
78
- await transaction.rollback();
79
- BaseChyz.warn("Rollback transaction")
80
- }
81
-
82
- if (e instanceof ValidationHttpException)
83
- throw new ValidationHttpException(e.message)
84
- else
85
- throw new ForbiddenHttpException(e.message)
86
- }
87
- return res.send("Post Controller")
88
- }
89
-
90
-
91
- @get("order/list")
92
- async listOrder(req: Request, res: Response) {
93
- const {Products}: { Products: ProductsClass } = ModelManager;
94
- let product = await Products.findAll({include: [ModelManager.ProductModels.model()]});
95
- return res.json(product)
96
-
97
- }
98
-
99
- @get("categories")
100
- async Categories(req: Request, res: Response) {
101
- let product = await ModelManager.Categories.findAll({
102
- include: [
103
- {
104
- model: ModelManager.Products.model(),
105
- // as: 'product',
106
- // through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
107
- }
108
- ]
109
- });
110
- return res.json(product)
111
-
112
- }
113
-
114
-
115
- error(req: Request, res: Response) {
116
- BaseChyz.logs().info("Error Sayfası")
117
- return res.send("Post Controller")
118
- }
119
- }
120
-
121
- module.exports = ApiController