chyz 1.0.13-rc.2 → 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.
- package/BaseChyz.ts +34 -11
- package/Examples/Controllers/ApiController.ts +19 -10
- package/Examples/Controllers/KeyCloakController.ts +4 -4
- package/Examples/Models/Categories.ts +15 -3
- package/Examples/Models/Customer.ts +2 -2
- package/Examples/Models/Order.ts +5 -5
- package/Examples/Models/OrderItem.ts +2 -2
- package/Examples/Models/ProductModels.ts +4 -5
- package/Examples/Models/ProductToCategories.ts +15 -4
- package/Examples/Models/Products.ts +9 -8
- package/Examples/Models/Stocks.ts +2 -2
- package/Examples/Models/UserPermission.ts +2 -2
- package/Examples/Models/index.ts +19 -0
- package/Examples/index.ts +1 -0
- package/Examples/log/app.log +5134 -0
- package/Examples/log/errors.log +1446 -0
- package/Examples/tsconfig.json +2 -1
- package/base/Model.ts +37 -33
- package/base/ModelManager.ts +14 -0
- package/base/index.ts +1 -0
- package/dist/BaseChyz.js +29 -4
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/Model.js +32 -28
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +17 -0
- package/dist/base/ModelManager.js.map +1 -0
- package/dist/base/index.js +1 -0
- package/dist/base/index.js.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/index.ts +2 -2
- package/package-lock.json +5259 -0
- package/package.json +5 -4
- package/Examples/yarn.lock +0 -2549
package/BaseChyz.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {RouteDefinition} from "./model/RouteDefinition";
|
|
|
3
3
|
import {NextFunction, Request, Response} from "express";
|
|
4
4
|
import {Controller} from "./base/Controller";
|
|
5
5
|
import Utils from "./requiments/Utils";
|
|
6
|
+
import {ModelManager} from "./base";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
const express = require("express");
|
|
@@ -83,6 +84,13 @@ export default class BaseChyz {
|
|
|
83
84
|
this.controllerpath = this.config.controllerpath
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Model Register
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
this.loadModels();
|
|
93
|
+
|
|
86
94
|
/**
|
|
87
95
|
* Express Server
|
|
88
96
|
*/
|
|
@@ -144,7 +152,6 @@ export default class BaseChyz {
|
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
|
|
147
|
-
|
|
148
155
|
this.init();
|
|
149
156
|
|
|
150
157
|
return this;
|
|
@@ -229,6 +236,30 @@ export default class BaseChyz {
|
|
|
229
236
|
return BaseChyz.middlewares[key] ?? null
|
|
230
237
|
}
|
|
231
238
|
|
|
239
|
+
/**
|
|
240
|
+
* load model
|
|
241
|
+
*/
|
|
242
|
+
async loadModels() {
|
|
243
|
+
let models: any = {}
|
|
244
|
+
let path = `${this._controllerpath}/../Models`;
|
|
245
|
+
fs.readdirSync(path).forEach((file: string) => {
|
|
246
|
+
if (file !== "index.ts") {
|
|
247
|
+
let model = require(`${path}/${file}`);
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
let className = file.split(".")[0] + "Class";
|
|
250
|
+
if (model[className])
|
|
251
|
+
models[className.replace("Class","")] = new model[className];
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
ModelManager._register(models);
|
|
256
|
+
|
|
257
|
+
for (const key of Object.keys(ModelManager)) {
|
|
258
|
+
if(key!="_register"){
|
|
259
|
+
ModelManager[key].init();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
232
263
|
|
|
233
264
|
/**
|
|
234
265
|
* load contoller
|
|
@@ -288,8 +319,8 @@ export default class BaseChyz {
|
|
|
288
319
|
res.status(e.statusCode || 500)
|
|
289
320
|
// @ts-ignore
|
|
290
321
|
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
291
|
-
}else{
|
|
292
|
-
res.json(e
|
|
322
|
+
} else {
|
|
323
|
+
res.json(e)
|
|
293
324
|
}
|
|
294
325
|
}
|
|
295
326
|
})
|
|
@@ -308,7 +339,6 @@ export default class BaseChyz {
|
|
|
308
339
|
BaseChyz.express.use(methodOverride());
|
|
309
340
|
|
|
310
341
|
|
|
311
|
-
|
|
312
342
|
// CORS
|
|
313
343
|
BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
314
344
|
// @ts-ignore
|
|
@@ -352,10 +382,3 @@ export default class BaseChyz {
|
|
|
352
382
|
|
|
353
383
|
|
|
354
384
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
process.on('uncaughtException', err => {
|
|
358
|
-
BaseChyz.error('There was an uncaught error', err)
|
|
359
|
-
process.exit(1) //mandatory (as per the Node.js docs)
|
|
360
|
-
})
|
|
361
|
-
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {Controller} from "../../base";
|
|
10
|
+
import {Controller, ModelManager} from "../../base";
|
|
11
11
|
import BaseChyz from "../../BaseChyz";
|
|
12
12
|
// @ts-ignore
|
|
13
13
|
import {Request, Response} from "express";
|
|
@@ -18,10 +18,8 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
|
18
18
|
|
|
19
19
|
import {ValidationHttpException} from "../../base";
|
|
20
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import {Products} from "../Models/Products";
|
|
24
|
-
import {ProductModels} from "../Models/ProductModels";
|
|
21
|
+
|
|
22
|
+
|
|
25
23
|
|
|
26
24
|
@controller("/api")
|
|
27
25
|
class ApiController extends Controller {
|
|
@@ -70,17 +68,15 @@ class ApiController extends Controller {
|
|
|
70
68
|
data.Customer["2fa"] = "true";
|
|
71
69
|
|
|
72
70
|
//Customer Model Create
|
|
73
|
-
let customer
|
|
71
|
+
let customer = ModelManager.Customer;
|
|
74
72
|
//Order Model Create
|
|
75
|
-
let order
|
|
73
|
+
let order = ModelManager.Order;
|
|
76
74
|
|
|
77
75
|
|
|
78
76
|
let transaction
|
|
79
77
|
try {
|
|
80
78
|
// get transaction
|
|
81
79
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
82
|
-
|
|
83
|
-
|
|
84
80
|
customer.load(data, "Customer");//load customer data
|
|
85
81
|
let cus: any = await customer.save({}, {transaction});
|
|
86
82
|
|
|
@@ -117,7 +113,20 @@ class ApiController extends Controller {
|
|
|
117
113
|
|
|
118
114
|
@get("order/list")
|
|
119
115
|
async listOrder(req: Request, res: Response) {
|
|
120
|
-
let product = await Products.findAll({include: [ProductModels.model()]});
|
|
116
|
+
let product = await ModelManager.Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
117
|
+
return res.json(product)
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@get("categories")
|
|
122
|
+
async Categories(req: Request, res: Response) {
|
|
123
|
+
let product = await ModelManager.Categories.findAll( {include:[
|
|
124
|
+
{
|
|
125
|
+
model: ModelManager.Products.model(),
|
|
126
|
+
// as: 'product',
|
|
127
|
+
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
128
|
+
}
|
|
129
|
+
]} );
|
|
121
130
|
return res.json(product)
|
|
122
131
|
|
|
123
132
|
}
|
|
@@ -16,8 +16,8 @@ import {get,post,controller} from "../../decorator";
|
|
|
16
16
|
import {ValidationHttpException,ForbiddenHttpException} from "../../base";
|
|
17
17
|
import {KeyCloakHttpBearerAuth} from "../../filters/auth/KeyCloakHttpBearerAuth";
|
|
18
18
|
|
|
19
|
-
import {OrderClass
|
|
20
|
-
import {CustomerClass
|
|
19
|
+
import {OrderClass} from "../Models/Order";
|
|
20
|
+
import {CustomerClass} from "../Models/Customer";
|
|
21
21
|
|
|
22
22
|
@controller("/oauth2.0")
|
|
23
23
|
class ApiController extends Controller {
|
|
@@ -46,9 +46,9 @@ class ApiController extends Controller {
|
|
|
46
46
|
data.Customer["2fa"] = "true";
|
|
47
47
|
|
|
48
48
|
//Customer Model Create
|
|
49
|
-
let customer: CustomerClass =
|
|
49
|
+
let customer: CustomerClass = new CustomerClass();
|
|
50
50
|
//Order Model Create
|
|
51
|
-
let order: OrderClass =
|
|
51
|
+
let order: OrderClass = new OrderClass() ;
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
let transaction
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes, Model} from "../../base";
|
|
7
|
+
import {DataTypes, ModelManager, Model, Relation} from "../../base";
|
|
8
|
+
import {ProductToCategoriesClass} from "./ProductToCategories";
|
|
8
9
|
|
|
9
10
|
export class CategoriesClass extends Model {
|
|
10
11
|
[x: string]: any;
|
|
@@ -29,8 +30,19 @@ export class CategoriesClass extends Model {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
relations(): Relation[] {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
type: "belongsToMany",
|
|
37
|
+
foreignKey: "category_id",
|
|
38
|
+
sourceKey: "id",
|
|
39
|
+
model: ModelManager.Products.model(),
|
|
40
|
+
through: ModelManager.ProductToCategories.model()
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
32
44
|
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
const Categories = new CategoriesClass();
|
|
36
|
-
export {Categories};
|
|
47
|
+
// const Categories = new CategoriesClass();
|
|
48
|
+
// export {Categories};
|
package/Examples/Models/Order.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {DataTypes, Model, Relation} from "../../base";
|
|
2
|
-
import {
|
|
2
|
+
import {OrderItemClass} from "./OrderItem";
|
|
3
3
|
|
|
4
4
|
export class OrderClass extends Model {
|
|
5
5
|
[x: string]: any;
|
|
@@ -50,15 +50,15 @@ export class OrderClass extends Model {
|
|
|
50
50
|
type: "hasOne",
|
|
51
51
|
sourceKey: "order_id",
|
|
52
52
|
foreignKey: "id",
|
|
53
|
-
model:
|
|
53
|
+
model: (new OrderItemClass()).model()
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const Order = new OrderClass()
|
|
60
|
-
export {Order};
|
|
61
|
-
|
|
59
|
+
// const Order = new OrderClass()
|
|
60
|
+
// export {Order};
|
|
61
|
+
//
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes, Model, Relation} from "../../base";
|
|
8
|
-
import {Products} from "./Products";
|
|
7
|
+
import {DataTypes, ModelManager, Model, Relation} from "../../base";
|
|
9
8
|
|
|
10
9
|
export class ProductModelsClass extends Model {
|
|
11
10
|
[x: string]: any;
|
|
@@ -40,11 +39,11 @@ export class ProductModelsClass extends Model {
|
|
|
40
39
|
type: "hasOne",
|
|
41
40
|
foreignKey: "id",
|
|
42
41
|
sourceKey: "category_id",
|
|
43
|
-
model: Products.model()
|
|
42
|
+
model: ModelManager.Products.model()
|
|
44
43
|
}
|
|
45
44
|
]
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
const ProductModels = new ProductModelsClass();
|
|
50
|
-
export {ProductModels}
|
|
48
|
+
// const ProductModels = new ProductModelsClass();
|
|
49
|
+
// export {ProductModels}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes, Model} from "../../base";
|
|
7
|
+
import {DataTypes, ModelManager, Model, Relation} from "../../base";
|
|
8
8
|
|
|
9
9
|
export class ProductToCategoriesClass extends Model {
|
|
10
10
|
[x: string]: any;
|
|
@@ -21,7 +21,7 @@ export class ProductToCategoriesClass extends Model {
|
|
|
21
21
|
type: DataTypes.INTEGER,
|
|
22
22
|
allowNull: false
|
|
23
23
|
},
|
|
24
|
-
|
|
24
|
+
category_id: {
|
|
25
25
|
type: DataTypes.INTEGER,
|
|
26
26
|
allowNull: false
|
|
27
27
|
}
|
|
@@ -29,7 +29,18 @@ export class ProductToCategoriesClass extends Model {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// relations(): Relation[] {
|
|
33
|
+
// return [
|
|
34
|
+
// {
|
|
35
|
+
// type: "hasMany",
|
|
36
|
+
// foreignKey: "category_id",
|
|
37
|
+
// sourceKey: "id",
|
|
38
|
+
// model: ModelManager.Categories.model(),
|
|
39
|
+
// }
|
|
40
|
+
// ]
|
|
41
|
+
// }
|
|
42
|
+
|
|
32
43
|
}
|
|
33
44
|
|
|
34
|
-
const ProductToCategories = new ProductToCategoriesClass()
|
|
35
|
-
export {ProductToCategories}
|
|
45
|
+
// const ProductToCategories = new ProductToCategoriesClass()
|
|
46
|
+
// export {ProductToCategories}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes, Model, Relation} from "../../base";
|
|
8
|
-
|
|
7
|
+
import {DataTypes, ModelManager, Model, Relation} from "../../base";
|
|
8
|
+
|
|
9
9
|
|
|
10
10
|
export class ProductsClass extends Model {
|
|
11
11
|
[x: string]: any;
|
|
@@ -36,14 +36,15 @@ export class ProductsClass extends Model {
|
|
|
36
36
|
relations(): Relation[] {
|
|
37
37
|
return [
|
|
38
38
|
{
|
|
39
|
-
type: "
|
|
40
|
-
foreignKey: "
|
|
41
|
-
sourceKey: "
|
|
42
|
-
model:
|
|
39
|
+
type: "belongsToMany",
|
|
40
|
+
foreignKey: "product_id",
|
|
41
|
+
sourceKey: "id",
|
|
42
|
+
model: ModelManager.Categories.model(),
|
|
43
|
+
through: ModelManager.ProductToCategories.model()
|
|
43
44
|
}
|
|
44
45
|
]
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
const Products = new ProductsClass()
|
|
49
|
-
export {Products}
|
|
49
|
+
// const Products = new ProductsClass()
|
|
50
|
+
// export {Products}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import {ModelManager} from "../../base";
|
|
10
|
+
// import {Order, OrderClass} from "./Order";
|
|
11
|
+
// import {Customer, CustomerClass} from "./Customer";
|
|
12
|
+
// import {Products} from "./Products";
|
|
13
|
+
// import {ProductModels} from "./ProductModels";
|
|
14
|
+
// import {Categories} from "./Categories";
|
|
15
|
+
// import {ProductToCategories} from "./ProductToCategories";
|
|
16
|
+
//
|
|
17
|
+
// Dependencies._register({Order, Customer,CustomerClass,OrderClass, Products, ProductModels, Categories, ProductToCategories});
|
|
18
|
+
//
|
|
19
|
+
// console.log("denmemem")
|
package/Examples/index.ts
CHANGED