chyz 1.0.12-rc.7 → 1.0.13-rc.2

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 (96) hide show
  1. package/BaseChyz.ts +76 -14
  2. package/Chyz.ts +0 -3
  3. package/Examples/Controllers/ApiController.ts +88 -30
  4. package/Examples/Controllers/KeyCloakController.ts +100 -0
  5. package/Examples/Controllers/PublicController.ts +5 -7
  6. package/Examples/Controllers/SiteController.ts +82 -32
  7. package/Examples/Models/Categories.ts +36 -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 +50 -0
  13. package/Examples/Models/ProductToCategories.ts +35 -0
  14. package/Examples/Models/Products.ts +49 -0
  15. package/Examples/Models/Stocks.ts +60 -0
  16. package/Examples/Models/User.ts +66 -35
  17. package/Examples/Models/UserPermission.ts +37 -0
  18. package/Examples/index-keycloack.ts +78 -0
  19. package/Examples/index.ts +16 -15
  20. package/Examples/keycloak.json +7 -0
  21. package/Examples/log/app.log +903 -1034
  22. package/Examples/log/errors.log +79 -256
  23. package/Examples/package.json +46 -44
  24. package/Examples/tsconfig.json +1 -1
  25. package/Examples/yarn.lock +2549 -0
  26. package/README.md +118 -16
  27. package/base/ActionFilter.ts +2 -2
  28. package/base/BaseError.ts +2 -2
  29. package/base/DataErrorDbException.ts +1 -1
  30. package/base/DbConnection.ts +8 -2
  31. package/base/ForbiddenHttpException.ts +1 -1
  32. package/base/InvalidConfigException.ts +1 -1
  33. package/base/Model.ts +204 -15
  34. package/base/NotFoundHttpException.ts +1 -1
  35. package/base/RestClient.ts +28 -0
  36. package/base/UnauthorizedHttpException.ts +2 -1
  37. package/base/ValidationHttpException.ts +14 -0
  38. package/base/db/Exception.ts +14 -0
  39. package/base/index.ts +2 -0
  40. package/dist/BaseChyz.js +72 -25
  41. package/dist/BaseChyz.js.map +1 -1
  42. package/dist/Chyz.js.map +1 -1
  43. package/dist/base/ActionFilter.js +2 -2
  44. package/dist/base/ActionFilter.js.map +1 -1
  45. package/dist/base/BaseError.js +2 -2
  46. package/dist/base/BaseError.js.map +1 -1
  47. package/dist/base/DataErrorDbException.js +1 -1
  48. package/dist/base/DataErrorDbException.js.map +1 -1
  49. package/dist/base/DbConnection.js +9 -2
  50. package/dist/base/DbConnection.js.map +1 -1
  51. package/dist/base/ForbiddenHttpException.js +1 -1
  52. package/dist/base/ForbiddenHttpException.js.map +1 -1
  53. package/dist/base/InvalidConfigException.js +1 -1
  54. package/dist/base/InvalidConfigException.js.map +1 -1
  55. package/dist/base/Model.js +181 -13
  56. package/dist/base/Model.js.map +1 -1
  57. package/dist/base/NotFoundHttpException.js +1 -1
  58. package/dist/base/NotFoundHttpException.js.map +1 -1
  59. package/dist/base/RestClient.js +27 -0
  60. package/dist/base/RestClient.js.map +1 -0
  61. package/dist/base/UnauthorizedHttpException.js +1 -1
  62. package/dist/base/UnauthorizedHttpException.js.map +1 -1
  63. package/dist/base/ValidationHttpException.js +18 -0
  64. package/dist/base/ValidationHttpException.js.map +1 -0
  65. package/dist/base/db/Exception.js +16 -0
  66. package/dist/base/db/Exception.js.map +1 -0
  67. package/dist/base/index.js +2 -0
  68. package/dist/base/index.js.map +1 -1
  69. package/dist/filters/AccessControl.js +2 -2
  70. package/dist/filters/AccessControl.js.map +1 -1
  71. package/dist/filters/AccessRule.js.map +1 -1
  72. package/dist/filters/auth/AuthMethod.js +2 -2
  73. package/dist/filters/auth/AuthMethod.js.map +1 -1
  74. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -1
  75. package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
  76. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
  77. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
  78. package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
  79. package/dist/index.js +29 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/web/{User.js → WebUser.js} +12 -7
  82. package/dist/web/WebUser.js.map +1 -0
  83. package/filters/AccessControl.ts +3 -3
  84. package/filters/AccessRule.ts +2 -2
  85. package/filters/auth/AuthMethod.ts +4 -4
  86. package/filters/auth/HttpHeaderAuth.ts +2 -2
  87. package/filters/auth/JwtHttpBearerAuth.ts +4 -5
  88. package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
  89. package/index.ts +14 -0
  90. package/package.json +55 -52
  91. package/web/{User.ts → WebUser.ts} +10 -6
  92. package/.idea/Chy-Nodejs-Framework.iml +0 -12
  93. package/.idea/jsLibraryMappings.xml +0 -6
  94. package/.idea/modules.xml +0 -8
  95. package/.idea/vcs.xml +0 -6
  96. package/dist/web/User.js.map +0 -1
package/README.md CHANGED
@@ -12,18 +12,26 @@ Klasör Yapısı<br>
12
12
  index.ts<br>
13
13
 
14
14
  `##Başlangıç<br>
15
- yarn start
15
+ yarn start
16
+
17
+ ## index.ts alanlar düzenlenmeli.
18
+
19
+ ```typescript
20
+ require('dotenv-flow').config();
21
+
22
+ import BaseChyz from "chyz/dist/BaseChyz";
23
+ import Chyz, {DbConnection} from "chyz/dist";
24
+ import {WebUser} from "../web/WebUser";
25
+ import {User} from "./Models/User";
16
26
 
17
- ##index.ts alanlar düzenlenmeli.
18
- ```js
19
27
  let config = {
20
28
  components: {
21
- db:{
22
- class:DbConnection,
29
+ db: {
30
+ class: DbConnection,
23
31
  database: process.env.DBDATABASE,
24
- username:process.env.DBUSER,
25
- password:process.env.DBPASS,
26
- options:{
32
+ username: process.env.DBUSER,
33
+ password: process.env.DBPASS,
34
+ options: {
27
35
  host: process.env.DBHOST,
28
36
  dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
29
37
  // disable logging; default: console.log
@@ -31,21 +39,22 @@ let config = {
31
39
  }
32
40
  },
33
41
  user: {
34
- 'class': User,
35
- 'identityClass':Identity
42
+ 'class': WebUser,
43
+ 'identityClass': User
36
44
  }
37
45
  }
38
46
  }
39
47
  Chyz.app(config).Start();
40
48
  ```
41
49
 
42
- ##Create Model
50
+ ## Create Model
51
+
43
52
  Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
44
53
 
45
- ```js
46
- import {Model,DataTypes} from "chyz/base/Model";
54
+ ```typescript
55
+ import {Model, DataTypes} from "chyz/base/Model";
47
56
 
48
- export class Customer extends Model {
57
+ export class CustomerCLass extends Model {
49
58
  public tableName() {
50
59
  return 'customer';
51
60
  }
@@ -77,11 +86,104 @@ export class Customer extends Model {
77
86
  }
78
87
 
79
88
  }
89
+ const Customer= new CustomerCLass();
90
+ export { Customer };
91
+
92
+ ```
93
+ ````typescript
94
+ export class ProductsClass extends Model {
95
+ [x: string]: any;
96
+
97
+ tableName() {
98
+ return 'products';
99
+ }
100
+
101
+ attributes() {
102
+ return {
103
+ // Model attributes are defined here
104
+ title: {
105
+ type: DataTypes.STRING,
106
+ allowNull: false
107
+ },
108
+ model_id: {
109
+ type: DataTypes.INTEGER,
110
+ allowNull: false
111
+ },
112
+ properties: {
113
+ type: DataTypes.STRING,
114
+ allowNull: false
115
+ }
116
+
117
+ }
118
+ }
119
+
120
+ relations(): Relation[] {
121
+ return [
122
+ {
123
+ type: "hasOne",
124
+ foreignKey: "id",
125
+ sourceKey: "customer_id",
126
+ model: Customer.model()
127
+ }
128
+ ]
129
+ }
130
+ }
131
+
132
+ const Products = new ProductsClass()
133
+ export {Products}
134
+ ````
135
+
136
+ ## Http POST ve GET verilerini model'e yükleme
137
+
138
+ ````typescript
139
+
140
+ /**
141
+ * post data
142
+ * {
143
+ * "Customer":{
144
+ * "firstname":"cihan",
145
+ * "lastname":"ozturk"
146
+ * ....
147
+ * }
148
+ * }
149
+ * @type {Customer}
150
+ */
151
+ import {Customer} from "./Customer";
152
+ //Customer Model Create
153
+ let customer: Customer = Customer;
154
+ customer.load(req.body, "Customer");//load customer data
155
+ let cus: any = await customer.save();
156
+
157
+
158
+ ````
159
+ ## Transaction
160
+ Transaction oluşturma
161
+
162
+
163
+ ```typescript
164
+ let transaction
165
+ try {
166
+ // get transaction
167
+ transaction = await BaseChyz.getComponent("db").transaction();
168
+ //Customer Model Create
169
+ let customer: Customer = new Customer();
170
+ customer.load(data, "Customer");//load customer data
171
+ let cus: any = await customer.save({}, {transaction});
172
+ if (!cus) {
173
+ throw new ValidationHttpException(customer.errors);
174
+ }
175
+ } catch (e) {
176
+ if (transaction) {
177
+ await transaction.rollback();
178
+ BaseChyz.warn("Rollback transaction")
179
+ }
180
+ ...
181
+ }
80
182
  ```
81
183
 
82
- ##Yetkilendirme için kullanıcı modeli
184
+ ## Yetkilendirme için kullanıcı modeli
83
185
 
84
- ```js
186
+ ```typescript
85
187
  /*
86
188
  * Copyright (c) 2021. Chy Bilgisayar Bilisim
87
189
  * Author: Cihan Ozturk
@@ -25,7 +25,7 @@ export class ActionFilter extends Behavior {
25
25
  }
26
26
 
27
27
  public async beforeFilter(route: any, req: Request, res: Response) {
28
- if (!this.isActive(route.id)) {
28
+ if (!this.isActive(route)) {
29
29
  return;
30
30
  }
31
31
 
@@ -51,7 +51,7 @@ export class ActionFilter extends Behavior {
51
51
  for (const exceptKey in this.except) {
52
52
  let pattern = this.except[exceptKey];
53
53
  let match = id.match(pattern)
54
- if (match.length > 0) {
54
+ if (match && match.length > 0) {
55
55
  exceptMatch = true;
56
56
  }
57
57
  }
package/base/BaseError.ts CHANGED
@@ -8,11 +8,11 @@
8
8
  export class BaseError extends Error {
9
9
  private statusCode: number;
10
10
 
11
- constructor(message: string) {
11
+ constructor(message: string,statusCode=500) {
12
12
  super(message);
13
13
  this.message=message;
14
14
  this.name = this.constructor.name // good practice
15
- this.statusCode = 500 // error code for responding to client
15
+ this.statusCode = statusCode // error code for responding to client
16
16
  Error.captureStackTrace(this)
17
17
  }
18
18
 
@@ -11,6 +11,6 @@ import {BaseError} from "./BaseError";
11
11
 
12
12
  export class DataErrorDbException extends BaseError {
13
13
  constructor ( public message: string) {
14
- super(message);
14
+ super(message,502);
15
15
  }
16
16
  }
@@ -15,6 +15,7 @@ export class DbConnection extends Component {
15
15
  public username!: string
16
16
  public password!: string
17
17
  public options?: object
18
+ public _transaction:any;
18
19
 
19
20
  private _db: any
20
21
 
@@ -24,10 +25,10 @@ export class DbConnection extends Component {
24
25
  sequelize
25
26
  .authenticate()
26
27
  .then(() => {
27
- console.log('Connection has been established successfully.');
28
+ BaseChyz.info('Connection has been established successfully.');
28
29
  })
29
30
  .catch((err: any) => {
30
- console.error('Unable to connect to the database:', err);
31
+ BaseChyz.error('Unable to connect to the database:', err);
31
32
 
32
33
  });
33
34
 
@@ -42,4 +43,9 @@ export class DbConnection extends Component {
42
43
  set db(value: any) {
43
44
  this._db = value;
44
45
  }
46
+
47
+ public transaction(){
48
+ return this.db.transaction();
49
+ }
50
+
45
51
  }
@@ -8,7 +8,7 @@
8
8
  import {BaseError} from "./BaseError";
9
9
  export class ForbiddenHttpException extends BaseError {
10
10
  constructor ( message: string) {
11
- super(message);
11
+ super(message,403);
12
12
  }
13
13
  }
14
14
 
@@ -11,6 +11,6 @@ import {BaseError} from "./BaseError";
11
11
 
12
12
  export class InvalidConfigException extends BaseError {
13
13
  constructor ( public message: string) {
14
- super(message);
14
+ super(message,500);
15
15
  }
16
16
  }
package/base/Model.ts CHANGED
@@ -9,9 +9,21 @@ import BaseChyz from "../BaseChyz";
9
9
  import Utils from "../requiments/Utils";
10
10
  import {Component} from "./Component";
11
11
  import {InvalidConfigException} from "./InvalidConfigException";
12
- import {DataTypes} from "sequelize";
12
+ import {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, Model as SModel, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
13
+ import {Exception} from "./db/Exception";
13
14
 
14
- export {DataTypes} from "sequelize";
15
+ export {DataTypes, NOW} from "sequelize";
16
+
17
+ export interface Relation{
18
+ type: "hasOne" | "hasMany" | "belongsToMany" | "belongsTo",
19
+ allowNull?:boolean,
20
+ sourceKey:string,
21
+ model:SModel,
22
+ foreignKey:string,
23
+ name?:string,
24
+ through?:string,
25
+ as?:string
26
+ }
15
27
 
16
28
  /**
17
29
  * ValidateMe.init({
@@ -66,24 +78,64 @@ export {DataTypes} from "sequelize";
66
78
  }
67
79
  }, { sequelize });
68
80
  */
81
+
69
82
  export class Model extends Component {
70
- private sequelize: any
83
+ _sequelize: any ;
71
84
  private _tableName: string;
72
85
  private _model: any;
73
86
  private _attributes: any = {};
87
+ private _errors: any = {}
88
+
74
89
 
75
- constructor() {
90
+ constructor(sequelize?: IDBDatabase) {
76
91
  super();
77
92
  this._tableName = this.constructor.name;
78
- this.sequelize = BaseChyz.getComponent("db").db;
93
+ // this._sequelize = BaseChyz.getComponent("db").db;
94
+ if (sequelize != null)
95
+ this._sequelize = sequelize;
96
+ else
97
+ this._sequelize = BaseChyz.getComponent("db").db;
79
98
 
80
99
  if (!Utils.isEmpty(this.attributes())) {
81
-
82
- this._model = this.sequelize.define(this.constructor.name, this.attributes(), {
100
+ this._model = this._sequelize.define(this.constructor.name, this.attributes(), {
83
101
  tableName: this.tableName(),
84
102
  timestamps: false
85
103
  });
86
104
 
105
+
106
+
107
+ /**
108
+ * init buraya
109
+ */
110
+
111
+ for (const relation of this.relations()) {
112
+ let m = relation.model;
113
+
114
+ if(relation.type=="hasOne" ){
115
+ // @ts-ignore
116
+ delete relation.model
117
+ this.model().hasOne(m, relation );
118
+ }
119
+
120
+ if(relation.type=="hasMany" ){
121
+ // @ts-ignore
122
+ delete relation.model;
123
+ this.model().hasMany(m, relation );
124
+ }
125
+
126
+ if(relation.type=="belongsTo" ){
127
+ // @ts-ignore
128
+ delete relation.model;
129
+ this.model().belongsTo(m, relation );
130
+ }
131
+
132
+ if(relation.type=="belongsToMany" ){
133
+ // @ts-ignore
134
+ delete relation.model;
135
+ this.model().belongsToMany(m, relation );
136
+ }
137
+ }
138
+
87
139
  } else {
88
140
  throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
89
141
  }
@@ -92,10 +144,43 @@ export class Model extends Component {
92
144
 
93
145
  }
94
146
 
147
+
148
+ /**
149
+ * Returns the database connection used by this AR class.
150
+ * By default, the "db" application component is used as the database connection.
151
+ * You may override this method if you want to use a different database connection.
152
+ * @return Connection the database connection used by this AR class.
153
+ */
154
+ public static getDb()
155
+ {
156
+ return BaseChyz.getComponent("db").db
157
+ }
158
+
159
+ get sequelize(): any {
160
+ return this._sequelize;
161
+ }
162
+
163
+ set sequelize(value: any) {
164
+ this._sequelize = value;
165
+ }
166
+
167
+
168
+ /**
169
+ *
170
+ */
171
+ get errors(): any {
172
+ return this._errors;
173
+ }
174
+
175
+ set errors(value: any) {
176
+ this._errors = value;
177
+ }
178
+
95
179
  public init() {
96
- BaseChyz.debug("Model init....",this.constructor.name)
180
+ BaseChyz.debug("Model init....", this.constructor.name)
97
181
  }
98
182
 
183
+
99
184
  public tableName() {
100
185
  return this._tableName;
101
186
  }
@@ -112,21 +197,98 @@ export class Model extends Component {
112
197
  return this._model;
113
198
  }
114
199
 
115
- public save() {
200
+ public async save(params = {}, options = {}) {
116
201
  // now instantiate an object
117
- return this._model.build(this._attributes).save()
202
+ let p = Object.assign(params, this._attributes)
203
+ let result: any;
204
+ try {
205
+ result = await this.model().create(p, options)
206
+ } catch (e) {
207
+ BaseChyz.debug(`Model[${this.constructor.name}].create`, e)
208
+ if (e instanceof ValidationError) {
209
+ let validationErrorItems = e.errors;
210
+ validationErrorItems.forEach(({message, path}) => {
211
+ // @ts-ignore
212
+ this._errors[path] = message
213
+ })
214
+
215
+ return false;
216
+ } else if (e instanceof DatabaseError) {
217
+
218
+ } else if (e instanceof TimeoutError) {
219
+
220
+ } else if (e instanceof UniqueConstraintError) {
221
+
222
+ } else if (e instanceof ForeignKeyConstraintError) {
223
+
224
+ } else if (e instanceof ExclusionConstraintError) {
225
+
226
+ }
227
+ throw new Exception(e.message, this.errors, e.code);
228
+ }
229
+
230
+ return result;
231
+
118
232
  }
119
233
 
120
- public update() {
121
- return this._model.build(this._attributes).update()
234
+ public async bulkCreate(params = {}, options = {}) {
235
+ // now instantiate an object
236
+ let p = Object.assign(params, this._attributes)
237
+ let result: any;
238
+ try {
239
+ result = await this.model().bulkCreate(p, options)
240
+ } catch (e) {
241
+ BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`, e)
242
+ if (e instanceof ValidationError) {
243
+ let validationErrorItems = e.errors;
244
+ validationErrorItems.forEach(({message, path}) => {
245
+ // @ts-ignore
246
+ this._errors[path] = message
247
+ })
248
+
249
+ return false;
250
+ } else if (e instanceof DatabaseError) {
251
+
252
+ } else if (e instanceof TimeoutError) {
253
+
254
+ } else if (e instanceof UniqueConstraintError) {
255
+
256
+ } else if (e instanceof ForeignKeyConstraintError) {
257
+
258
+ } else if (e instanceof ExclusionConstraintError) {
259
+
260
+ }
261
+ throw new Exception(e.message, this.errors, e.code);
262
+ }
263
+
264
+ return result;
265
+
122
266
  }
123
267
 
124
- public findOne(...args: any[]){
268
+ public update(params = {}, options = {}) {
269
+ let p = Object.assign(params, this._attributes)
270
+ return this.model().update(p, options)
271
+ }
272
+
273
+ public delete(params = {}, options = {}) {
274
+ let p = Object.assign(params, this._attributes)
275
+ return this.model().delete(p, options)
276
+ }
277
+
278
+ /**
279
+ *
280
+ * @param args
281
+ */
282
+ public findOne(...args: any[]) {
125
283
  return this._model.findOne(...arguments)
126
284
  }
127
285
 
128
- public delete(...args: any[]) {
129
- return this._model.delete(...arguments)
286
+ /**
287
+ *
288
+ * @param args
289
+ */
290
+ public findAll(...args: any[]) {
291
+ return this._model.findAll(...arguments)
130
292
  }
131
293
 
132
294
 
@@ -134,6 +296,11 @@ export class Model extends Component {
134
296
 
135
297
  }
136
298
 
299
+ /**
300
+ *
301
+ * @param data
302
+ * @param formName
303
+ */
137
304
  public load(data: any, formName: any = null) {
138
305
  let scope = formName === null ? this.formName() : formName;
139
306
  if (scope === '' && !Utils.isEmpty(data)) {
@@ -146,6 +313,18 @@ export class Model extends Component {
146
313
  return false;
147
314
  }
148
315
 
316
+ public bulkLoad(data: any, formName: any = null) {
317
+ let scope = formName === null ? this.formName() : formName;
318
+ if (scope === '' && !Utils.isEmpty(data)) {
319
+ this.setAttribute(data);
320
+ return true;
321
+ } else if (data[scope]) {
322
+ this.setAttribute(data[scope]);
323
+ return true;
324
+ }
325
+ return false;
326
+ }
327
+
149
328
  public setAttribute(values: any, safeOnly = true) {
150
329
  if (values instanceof Object) {
151
330
  let attributes = this.attributes();
@@ -162,4 +341,14 @@ export class Model extends Component {
162
341
  public attributes() {
163
342
  return {}
164
343
  }
344
+
345
+ /**
346
+ * relation return array
347
+ * [
348
+ *
349
+ * ]
350
+ */
351
+ public relations():Relation[]{
352
+ return []
353
+ }
165
354
  }
@@ -9,6 +9,6 @@ import {BaseError} from "./BaseError";
9
9
 
10
10
  export class NotFoundHttpException extends BaseError {
11
11
  constructor ( public message: string) {
12
- super(message);
12
+ super(message,404);
13
13
  }
14
14
  }
@@ -0,0 +1,28 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 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
+
11
+ import {Component} from "./Component";
12
+
13
+ const axios = require('axios')
14
+
15
+ export class RestClient extends Component {
16
+ public post(url: string, args: any[]) {
17
+ return axios.post(url, args)
18
+ }
19
+
20
+ public get(url: string, args: any[]) {
21
+ return axios.post(url, args)
22
+ }
23
+
24
+ public Rest(params: any) {
25
+ return axios(params)
26
+ }
27
+ }
28
+ export default new RestClient();
@@ -9,8 +9,9 @@ import {BaseError} from "./BaseError";
9
9
 
10
10
  export class UnauthorizedHttpException extends BaseError {
11
11
  constructor ( public message: string) {
12
- super(message);
12
+ super(message,401);
13
13
  }
14
+
14
15
  }
15
16
 
16
17
 
@@ -0,0 +1,14 @@
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
+
10
+ export class ValidationHttpException extends BaseError {
11
+ constructor ( public message: string) {
12
+ super(message,401);
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import {BaseError} from "../BaseError";
2
+
3
+ export class Exception extends BaseError {
4
+ public errorInfo = [];
5
+ private code: string;
6
+
7
+ constructor(message: string, errorInfo:any = [], code = '', previous = null) {
8
+ super(message);
9
+ this.errorInfo = errorInfo;
10
+ this.name = 'Database Exception' // good practice
11
+ this.code = code // error code for responding to client
12
+ Error.captureStackTrace(this)
13
+ }
14
+ }
package/base/index.ts CHANGED
@@ -11,4 +11,6 @@ export * from "./InvalidConfigException"
11
11
  export * from "./NotFoundHttpException"
12
12
  export * from "./UnauthorizedHttpException"
13
13
  export * from "./DataErrorDbException"
14
+ export * from "./ValidationHttpException"
14
15
  export * from "./Model"
16
+ export * from "./RestClient"