chyz 1.0.13-rc.7 → 1.1.0-rc.0

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 (79) hide show
  1. package/BaseChyz.ts +80 -21
  2. package/Doc/Moel kullanma.md +13 -0
  3. package/Examples/Controllers/ApiController.ts +22 -22
  4. package/Examples/Controllers/BasicApiController.ts +121 -0
  5. package/Examples/Controllers/SiteController.ts +18 -8
  6. package/Examples/Models/AuthAssignment.ts +50 -0
  7. package/Examples/Models/AuthItem.ts +59 -0
  8. package/Examples/Models/AuthItemChild.ts +49 -0
  9. package/Examples/Models/Categories.ts +4 -0
  10. package/Examples/Models/KeycloakUser.ts +4 -0
  11. package/Examples/Models/User.ts +8 -1
  12. package/Examples/index.ts +22 -2
  13. package/Examples/log/app.log +14466 -0
  14. package/Examples/log/errors.log +594 -0
  15. package/Examples/package.json +5 -2
  16. package/README.md +265 -12
  17. package/base/ActionFilter.ts +1 -1
  18. package/base/BaseError.ts +4 -2
  19. package/base/DbConnection.ts +9 -5
  20. package/base/InvalidArgumentException.ts +16 -0
  21. package/base/Model.ts +231 -34
  22. package/base/ModelManager.ts +6 -1
  23. package/base/RestClient.ts +4 -4
  24. package/base/ValidationHttpException.ts +1 -1
  25. package/base/index.ts +1 -0
  26. package/dist/BaseChyz.js +49 -10
  27. package/dist/BaseChyz.js.map +1 -1
  28. package/dist/base/ActionFilter.js +1 -1
  29. package/dist/base/ActionFilter.js.map +1 -1
  30. package/dist/base/BaseError.js +6 -2
  31. package/dist/base/BaseError.js.map +1 -1
  32. package/dist/base/DbConnection.js.map +1 -1
  33. package/dist/base/InvalidArgumentException.js +18 -0
  34. package/dist/base/InvalidArgumentException.js.map +1 -0
  35. package/dist/base/Model.js +186 -4
  36. package/dist/base/Model.js.map +1 -1
  37. package/dist/base/ModelManager.js +0 -8
  38. package/dist/base/ModelManager.js.map +1 -1
  39. package/dist/base/RestClient.js +4 -4
  40. package/dist/base/RestClient.js.map +1 -1
  41. package/dist/base/ValidationHttpException.js +1 -1
  42. package/dist/base/index.js +1 -0
  43. package/dist/base/index.js.map +1 -1
  44. package/dist/filters/AccessControl.js +15 -3
  45. package/dist/filters/AccessControl.js.map +1 -1
  46. package/dist/filters/AccessRule.js +99 -38
  47. package/dist/filters/AccessRule.js.map +1 -1
  48. package/dist/filters/auth/HttpBasicAuth.js +65 -0
  49. package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
  50. package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
  51. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
  52. package/dist/filters/auth/index.js +1 -0
  53. package/dist/filters/auth/index.js.map +1 -1
  54. package/dist/package.json +2 -4
  55. package/dist/rbac/AuthAssignment.js +45 -0
  56. package/dist/rbac/AuthAssignment.js.map +1 -0
  57. package/dist/rbac/AuthItem.js +52 -0
  58. package/dist/rbac/AuthItem.js.map +1 -0
  59. package/dist/rbac/AuthItemChild.js +44 -0
  60. package/dist/rbac/AuthItemChild.js.map +1 -0
  61. package/dist/rbac/AuthManager.js +359 -0
  62. package/dist/rbac/AuthManager.js.map +1 -0
  63. package/dist/requiments/Utils.js +5 -1
  64. package/dist/requiments/Utils.js.map +1 -1
  65. package/dist/web/WebUser.js +78 -0
  66. package/dist/web/WebUser.js.map +1 -1
  67. package/filters/AccessControl.ts +19 -6
  68. package/filters/AccessRule.ts +61 -16
  69. package/filters/auth/HttpBasicAuth.ts +68 -0
  70. package/filters/auth/JwtHttpBearerAuth.ts +1 -1
  71. package/filters/auth/index.ts +1 -0
  72. package/package.json +3 -4
  73. package/rbac/AuthAssignment.ts +50 -0
  74. package/rbac/AuthItem.ts +57 -0
  75. package/rbac/AuthItemChild.ts +50 -0
  76. package/rbac/AuthManager.ts +398 -0
  77. package/requiments/Utils.ts +6 -0
  78. package/web/IdentityInterface.ts +6 -0
  79. package/web/WebUser.ts +88 -1
package/BaseChyz.ts CHANGED
@@ -6,10 +6,48 @@ import Utils from "./requiments/Utils";
6
6
  import {ModelManager} from "./base";
7
7
 
8
8
 
9
+ const https = require('https');
9
10
  const express = require("express");
10
11
  const log4js = require("log4js");
11
12
  const fs = require('fs');
12
- const validate = require('validate');
13
+ const validate = require('validate.js');
14
+
15
+ /**
16
+ * Use
17
+ * selectedBox: {
18
+ * array: {
19
+ * id: {
20
+ * numericality: {
21
+ * onlyInteger: true,
22
+ * greaterThan: 0
23
+ * }
24
+ * }
25
+ * }
26
+ * },
27
+ * @param arrayItems
28
+ * @param itemConstraints
29
+ */
30
+ validate.validators.array = (arrayItems: any, itemConstraints: any) => {
31
+ const arrayItemErrors = arrayItems.reduce((errors: any, item: any, index: any) => {
32
+ const error = validate(item, itemConstraints);
33
+ if (error) errors[index] = {error: error};
34
+ return errors;
35
+ }, {});
36
+
37
+ return Utils.isEmpty(arrayItemErrors) ? null : {errors: arrayItemErrors};
38
+ };
39
+
40
+
41
+ validate.validators.tokenString = (items: any, itemConstraints: any) => {
42
+ let arrayItems = items.split(",");
43
+ const arrayItemErrors = arrayItems.reduce((errors: any, item: any, index: any) => {
44
+ const error = validate(item, itemConstraints);
45
+ if (error) errors[index] = {error: error};
46
+ return errors;
47
+ }, {});
48
+
49
+ return Utils.isEmpty(arrayItemErrors) ? null : {errors: arrayItemErrors};
50
+ };
13
51
 
14
52
  var ip = require('ip');
15
53
  var bodyParser = require('body-parser')
@@ -23,7 +61,7 @@ export default class BaseChyz {
23
61
  private _port: number = 3001;
24
62
  static db: any;
25
63
  static routes: any;
26
- private static _validate:any=validate;
64
+ private static _validate: any = validate;
27
65
  private _logConfig: any = require('./log/config/log4js.json') ?? {}
28
66
  private _controllerpath: string = "Controllers"
29
67
  private static controllers: Array<Controller> = []
@@ -48,8 +86,7 @@ export default class BaseChyz {
48
86
  }
49
87
 
50
88
  init() {
51
- this.logProvider().level = log4js.levels.ALL;
52
- this.logProvider().configure(this._logConfig);
89
+
53
90
 
54
91
  /**
55
92
  * set request id
@@ -140,13 +177,23 @@ export default class BaseChyz {
140
177
  this.config = config;
141
178
 
142
179
 
180
+ // logger setting
181
+ this.logProvider().level = log4js.levels.ALL;
182
+ this.logProvider().configure(this._logConfig);
183
+
143
184
  let components = Utils.findKeyValue(config, "components")
144
185
  if (components) {
145
186
  for (const componentsKey in components) {
187
+
146
188
  let comp = components[componentsKey];
147
189
  BaseChyz.debug("Create Component ", componentsKey)
148
- BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
149
- BaseChyz.components[componentsKey]?.init();
190
+ try {
191
+ BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
192
+ BaseChyz.components[componentsKey]?.init();
193
+ } catch (e) {
194
+ BaseChyz.error("Create Component ", e)
195
+ }
196
+
150
197
  }
151
198
  }
152
199
 
@@ -155,13 +202,12 @@ export default class BaseChyz {
155
202
  if (middlewares) {
156
203
  for (const middlewareKey in middlewares) {
157
204
  let middleware1 = middlewares[middlewareKey];
158
- BaseChyz.debug("Create middlewares ", middlewareKey)
205
+ BaseChyz.logs().debug("Create middlewares ", middlewareKey)
159
206
  BaseChyz.middlewares[middlewareKey] = middleware1;
160
207
  // BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
161
208
  }
162
209
  }
163
210
 
164
-
165
211
  this.init();
166
212
 
167
213
  return this;
@@ -233,8 +279,8 @@ export default class BaseChyz {
233
279
  if (res.headersSent) {
234
280
  return next(err)
235
281
  }
236
- res.status(500)
237
- res.json('error', {error: err})
282
+
283
+ res.status(500).json({error: err})
238
284
  }
239
285
 
240
286
  public static getComponent(key: any) {
@@ -258,14 +304,14 @@ export default class BaseChyz {
258
304
  // @ts-ignore
259
305
  let className = file.split(".")[0] + "Class";
260
306
  if (model[className])
261
- models[className.replace("Class","")] = new model[className];
307
+ models[className.replace("Class", "")] = new model[className];
262
308
  }
263
309
  })
264
310
 
265
311
  ModelManager._register(models);
266
312
 
267
313
  for (const key of Object.keys(ModelManager)) {
268
- if(key!="_register"){
314
+ if (key != "_register") {
269
315
  ModelManager[key].init();
270
316
  }
271
317
  }
@@ -305,7 +351,7 @@ export default class BaseChyz {
305
351
  BaseChyz.debug(`Call Request id ${instance.id}`)
306
352
  await instance.beforeAction(route, req, res)
307
353
  next()
308
- } catch (e) {
354
+ } catch (e: any) {
309
355
  BaseChyz.error(e);
310
356
 
311
357
  res.status(e.statusCode || 500)
@@ -343,8 +389,8 @@ export default class BaseChyz {
343
389
 
344
390
  public middleware() {
345
391
 
346
- BaseChyz.express.use(bodyParser.json())
347
- BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
392
+ BaseChyz.express.use(bodyParser.json({limit: '1mb'}));
393
+ BaseChyz.express.use(bodyParser.urlencoded({limit: '1mb', extended: true})); // support encoded bodies
348
394
  BaseChyz.express.use(methodOverride());
349
395
  BaseChyz.express.use(methodOverride());
350
396
 
@@ -381,12 +427,25 @@ export default class BaseChyz {
381
427
  public Start() {
382
428
 
383
429
  BaseChyz.info("Express Server Starting")
384
- BaseChyz.express.listen(this._port, () => {
385
- BaseChyz.info("Express Server Start ")
386
- BaseChyz.info(`Liten Port ${this._port}`)
387
- BaseChyz.info(`http://localhost:${this._port}`)
388
- BaseChyz.info(`http://${ip.address()}:${this._port}`)
389
- })
430
+
431
+ if (this.config?.ssl) {
432
+ const httpsServer = https.createServer(this.config?.ssl , BaseChyz.express);
433
+ httpsServer.listen(this._port, () => {
434
+ BaseChyz.info("Express Server Start ")
435
+ BaseChyz.info(`Liten Port ${this._port}`)
436
+ BaseChyz.info(`https://localhost:${this._port}`)
437
+ BaseChyz.info(`https://${ip.address()}:${this._port}`)
438
+ })
439
+ }else{
440
+ BaseChyz.express.listen(this._port, () => {
441
+ BaseChyz.info("Express Server Start ")
442
+ BaseChyz.info(`Liten Port ${this._port}`)
443
+ BaseChyz.info(`http://localhost:${this._port}`)
444
+ BaseChyz.info(`http://${ip.address()}:${this._port}`)
445
+ })
446
+ }
447
+
448
+
390
449
  return this;
391
450
  }
392
451
 
@@ -0,0 +1,13 @@
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
+
@@ -18,7 +18,8 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
18
18
 
19
19
  import {ValidationHttpException} from "../../base";
20
20
  import {ForbiddenHttpException} from "../../base";
21
-
21
+ import {ProductsClass} from "../Models/Products";
22
+ import {AccessControl} from "../../filters";
22
23
 
23
24
 
24
25
  @controller("/api")
@@ -35,22 +36,18 @@ class ApiController extends Controller {
35
36
  "class": JwtHttpBearerAuth,
36
37
  // "auth": this.myCheck
37
38
  },
38
- // 'access': {
39
- // 'class': AccessControl,
40
- // 'only': ['login', 'logout', 'signup'],
41
- // 'rules': [
42
- // {
43
- // 'allow': true,
44
- // 'actions': ['login', 'index'],
45
- // 'roles': ['?'],
46
- // },
47
- // {
48
- // 'allow': true,
49
- // 'actions': ['logout', "logout2"],
50
- // 'roles': ['@'],
51
- // }
52
- // ]
53
- // }
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
+ }
54
51
  }]
55
52
  }
56
53
 
@@ -68,9 +65,9 @@ class ApiController extends Controller {
68
65
  data.Customer["2fa"] = "true";
69
66
 
70
67
  //Customer Model Create
71
- let customer = ModelManager.Customer;
68
+ let customer = ModelManager.Customer.save();
72
69
  //Order Model Create
73
- let order = ModelManager.Order;
70
+ let order = ModelManager.Order;
74
71
 
75
72
 
76
73
  let transaction
@@ -113,20 +110,23 @@ class ApiController extends Controller {
113
110
 
114
111
  @get("order/list")
115
112
  async listOrder(req: Request, res: Response) {
116
- let product = await ModelManager.Products.findAll({include: [ModelManager.ProductModels.model()]});
113
+ const {Products}: { Products: ProductsClass } = ModelManager;
114
+ let product = await Products.cache().findAll( );
117
115
  return res.json(product)
118
116
 
119
117
  }
120
118
 
121
119
  @get("categories")
122
120
  async Categories(req: Request, res: Response) {
123
- let product = await ModelManager.Categories.findAll( {include:[
121
+ let product = await ModelManager.Categories.findAll({
122
+ include: [
124
123
  {
125
124
  model: ModelManager.Products.model(),
126
125
  // as: 'product',
127
126
  // through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
128
127
  }
129
- ]} );
128
+ ]
129
+ });
130
130
  return res.json(product)
131
131
 
132
132
  }
@@ -0,0 +1,121 @@
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
@@ -26,11 +26,12 @@ class SiteController extends Controller {
26
26
  public myCheck(token) {
27
27
  console.log("myyyyyyyyyyyyyyyyyyyyy")
28
28
  }
29
+
29
30
  public behaviors(): any[] {
30
31
  return [{
31
32
  'authenticator': {
32
33
  "class": JwtHttpBearerAuth,
33
- "except":["index","login"]
34
+ "except": ["index", "login"]
34
35
  // "auth": this.myCheck
35
36
  }
36
37
  }]
@@ -88,25 +89,33 @@ class SiteController extends Controller {
88
89
  // @ts-ignore
89
90
  let xForwardedFor = (req.headers['x-forwarded-for'] || '').replace(/:\d+$/, '');
90
91
  let ip = xForwardedFor || req.socket.remoteAddress;
91
- var source: string = req.headers['user-agent'] || '';
92
+ var source: string = req.headers['user-agent'] || '';
92
93
  if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
93
- source = req.headers['x-ucbrowser-ua']+"";
94
+ source = req.headers['x-ucbrowser-ua'] + "";
94
95
  }
95
96
  token = await JsonWebToken.sign({
96
97
  user: user.id,
97
98
  ip: ip,
98
99
  agent: source,
99
- }, user.authkey, {expiresIn: '1h'});
100
+ platform: "admin",
101
+ role: [
102
+ "admin"
103
+ ],
104
+ permissions: [
105
+ "xxxx",
106
+
107
+ ],
108
+ }, user.authkey, null);
100
109
 
101
- BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
110
+ BaseChyz.debug("Db user create access token", username, "expiresIn", "1h")
102
111
  return res.json({token: token})
103
112
  } else {
104
113
  let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
105
- res.status(500).json( error.toJSON())
114
+ res.status(500).json(error.toJSON())
106
115
  }
107
116
  } else {
108
117
  let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
109
- res.status(500).json( error.toJSON())
118
+ res.status(500).json(error.toJSON())
110
119
  }
111
120
 
112
121
 
@@ -136,4 +145,5 @@ class SiteController extends Controller {
136
145
  return res.send("Post Controller")
137
146
  }
138
147
  }
139
- module.exports=SiteController
148
+
149
+ module.exports = SiteController
@@ -0,0 +1,50 @@
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 {DataTypes, Model, ModelManager, Relation} from "../../base";
9
+
10
+ export class AuthAssignmentClass extends Model {
11
+ [x: string]: any;
12
+
13
+ tableName() {
14
+ return 'auth_assignment';
15
+ }
16
+ attributes() {
17
+ return {
18
+
19
+ // Model attributes are defined here
20
+ item_name: {
21
+ type: DataTypes.STRING,
22
+ primaryKey:true,
23
+ allowNull: false
24
+ },
25
+ user_id : {
26
+ type: DataTypes.STRING,
27
+ allowNull: false
28
+ }
29
+
30
+ }
31
+ }
32
+
33
+ init(){
34
+ super.init();
35
+ this.model().removeAttribute('id')
36
+ }
37
+
38
+ relations(): Relation[] {
39
+ return [
40
+ {
41
+ type: "hasMany",
42
+ foreignKey: "name",
43
+ sourceKey:'item_name',
44
+ model: ModelManager.AuthItem.model()
45
+ }
46
+ ]
47
+ }
48
+
49
+ }
50
+
@@ -0,0 +1,59 @@
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 {DataTypes, Model, ModelManager, Relation} from "../../base";
11
+
12
+ export class AuthItemClass extends Model {
13
+ [x: string]: any;
14
+
15
+ tableName() {
16
+ return 'auth_item';
17
+ }
18
+
19
+ attributes() {
20
+ return {
21
+ // Model attributes are defined here
22
+ name: {
23
+ type: DataTypes.STRING,
24
+ primaryKey:true,
25
+ allowNull: false
26
+ },
27
+ type: {
28
+ type: DataTypes.INTEGER,
29
+ allowNull: false
30
+ },
31
+ description: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false
34
+ },
35
+ rule_name: {
36
+ type: DataTypes.STRING,
37
+ allowNull: false
38
+ }
39
+
40
+ }
41
+ }
42
+
43
+ init() {
44
+ super.init();
45
+ this.model().removeAttribute('id')
46
+ }
47
+
48
+ // relations(): Relation[] {
49
+ // return [
50
+ // {
51
+ // type: "hasOne",
52
+ // foreignKey: "item_name",
53
+ // model: ModelManager.AuthAssignment.model()
54
+ // }
55
+ // ]
56
+ // }
57
+
58
+ }
59
+
@@ -0,0 +1,49 @@
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
+ import {DataTypes, Model, ModelManager, Relation} from "../../base";
10
+
11
+ export class AuthItemChildClass extends Model {
12
+ [x: string]: any;
13
+
14
+ tableName() {
15
+ return 'auth_item_child';
16
+ }
17
+
18
+ attributes() {
19
+ return {
20
+ // Model attributes are defined here
21
+ parent: {
22
+ type: DataTypes.STRING,
23
+ primaryKey: true,
24
+ allowNull: false
25
+ },
26
+ child: {
27
+ type: DataTypes.STRING,
28
+ allowNull: false
29
+ }
30
+ }
31
+ }
32
+
33
+ init() {
34
+ super.init();
35
+ this.model().removeAttribute('id')
36
+ }
37
+
38
+ relations(): Relation[] {
39
+ return [
40
+ {
41
+ type: "hasOne",
42
+ foreignKey: "item_name",
43
+ model: ModelManager.AuthAssignment.model()
44
+ }
45
+ ]
46
+ }
47
+
48
+ }
49
+
@@ -5,10 +5,14 @@
5
5
  * Github:https://github.com/cihan53/
6
6
  */
7
7
  import {DataTypes, Model, ModelManager, Relation} from "../../base";
8
+ import {BaseChyz} from "../../index";
8
9
 
9
10
  export class CategoriesClass extends Model {
10
11
  [x: string]: any;
11
12
 
13
+ constructor( ) {
14
+ super(BaseChyz.getComponent("db2").db);
15
+ }
12
16
  tableName() {
13
17
  return 'categories';
14
18
  }
@@ -61,6 +61,10 @@ export class KeycloakUser implements IdentityInterface {
61
61
  return null;
62
62
  // return keycloak.protect('realm:user');
63
63
  }
64
+
65
+ can(permissionName: string, params: any[], allowCaching: boolean): boolean | null {
66
+ return undefined;
67
+ }
64
68
  }
65
69
 
66
70
 
@@ -28,6 +28,11 @@ export class User extends Model implements IdentityInterface {
28
28
  throw new Error("Method not implemented.");
29
29
  }
30
30
 
31
+ can(permissionName: string, params: any[], allowCaching: boolean): boolean | null {
32
+ throw new Error("Method not implemented.");
33
+ }
34
+
35
+
31
36
  getAuthKey(): string {
32
37
  throw new Error("Method not implemented.");
33
38
  }
@@ -71,8 +76,8 @@ export class User extends Model implements IdentityInterface {
71
76
  }
72
77
 
73
78
  async findIdentityByAccessToken(token, type) {
74
- let decoded = JsonWebToken.decode(token, {complete: true})
75
79
 
80
+ let decoded = JsonWebToken.decode(token, {complete: true})
76
81
  if(!decoded.payload.user) {
77
82
  return null;
78
83
  }
@@ -97,4 +102,6 @@ export class User extends Model implements IdentityInterface {
97
102
  }
98
103
 
99
104
 
105
+
106
+
100
107
  }