chyz 1.0.13-rc.18 → 1.0.13-rc.3
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 +15 -53
- package/Examples/Controllers/ApiController.ts +26 -35
- package/Examples/Controllers/KeyCloakController.ts +4 -4
- package/Examples/Controllers/SiteController.ts +9 -26
- package/Examples/Models/Categories.ts +3 -14
- package/Examples/Models/Customer.ts +2 -2
- package/Examples/Models/KeycloakUser.ts +0 -4
- package/Examples/Models/Order.ts +5 -5
- package/Examples/Models/OrderItem.ts +2 -2
- package/Examples/Models/ProductModels.ts +5 -4
- package/Examples/Models/ProductToCategories.ts +4 -15
- package/Examples/Models/Products.ts +8 -9
- package/Examples/Models/Stocks.ts +2 -2
- package/Examples/Models/User.ts +1 -8
- package/Examples/Models/UserPermission.ts +2 -2
- package/Examples/index.ts +0 -6
- package/Examples/log/app.log +0 -9456
- package/Examples/log/errors.log +0 -1904
- package/Examples/tsconfig.json +1 -2
- package/README.md +4 -2
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +1 -3
- package/base/Model.ts +51 -57
- package/base/RestClient.ts +4 -4
- package/base/index.ts +0 -2
- package/dist/BaseChyz.js +8 -46
- package/dist/BaseChyz.js.map +1 -1
- package/dist/README.md +270 -0
- package/dist/base/ActionFilter.js +1 -1
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +1 -5
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/Model.js +30 -37
- package/dist/base/Model.js.map +1 -1
- package/dist/base/RestClient.js +4 -4
- package/dist/base/RestClient.js.map +1 -1
- package/dist/base/index.js +0 -2
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +3 -15
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js +38 -99
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +0 -65
- package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/index.js +0 -1
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/package.json +6 -7
- package/dist/web/WebUser.js +0 -78
- package/dist/web/WebUser.js.map +1 -1
- package/filters/AccessControl.ts +6 -19
- package/filters/AccessRule.ts +16 -61
- package/filters/auth/HttpBasicAuth.ts +0 -68
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +0 -1
- package/package.json +7 -7
- package/web/IdentityInterface.ts +0 -6
- package/web/WebUser.ts +1 -88
- package/Examples/Controllers/BasicApiController.ts +0 -121
- package/Examples/Models/AuthAssignment.ts +0 -50
- package/Examples/Models/AuthItem.ts +0 -59
- package/Examples/Models/AuthItemChild.ts +0 -49
- package/Examples/Models/index.ts +0 -19
- package/base/InvalidArgumentException.ts +0 -16
- package/base/ModelManager.ts +0 -19
- package/dist/base/InvalidArgumentException.js +0 -18
- package/dist/base/InvalidArgumentException.js.map +0 -1
- package/dist/base/ModelManager.js +0 -9
- package/dist/base/ModelManager.js.map +0 -1
- package/dist/rbac/AuthAssignment.js +0 -45
- package/dist/rbac/AuthAssignment.js.map +0 -1
- package/dist/rbac/AuthItem.js +0 -52
- package/dist/rbac/AuthItem.js.map +0 -1
- package/dist/rbac/AuthItemChild.js +0 -44
- package/dist/rbac/AuthItemChild.js.map +0 -1
- package/dist/rbac/AuthManager.js +0 -359
- package/dist/rbac/AuthManager.js.map +0 -1
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthItem.ts +0 -57
- package/rbac/AuthItemChild.ts +0 -50
- package/rbac/AuthManager.ts +0 -398
package/BaseChyz.ts
CHANGED
|
@@ -3,13 +3,11 @@ 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";
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
const express = require("express");
|
|
10
9
|
const log4js = require("log4js");
|
|
11
10
|
const fs = require('fs');
|
|
12
|
-
const validate = require('validate.js');
|
|
13
11
|
|
|
14
12
|
var ip = require('ip');
|
|
15
13
|
var bodyParser = require('body-parser')
|
|
@@ -23,7 +21,6 @@ export default class BaseChyz {
|
|
|
23
21
|
private _port: number = 3001;
|
|
24
22
|
static db: any;
|
|
25
23
|
static routes: any;
|
|
26
|
-
private static _validate:any=validate;
|
|
27
24
|
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
28
25
|
private _controllerpath: string = "Controllers"
|
|
29
26
|
private static controllers: Array<Controller> = []
|
|
@@ -86,13 +83,6 @@ export default class BaseChyz {
|
|
|
86
83
|
this.controllerpath = this.config.controllerpath
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Model Register
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
this.loadModels();
|
|
95
|
-
|
|
96
86
|
/**
|
|
97
87
|
* Express Server
|
|
98
88
|
*/
|
|
@@ -124,14 +114,6 @@ export default class BaseChyz {
|
|
|
124
114
|
}
|
|
125
115
|
|
|
126
116
|
|
|
127
|
-
static get validate(): any {
|
|
128
|
-
return this._validate;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static set validate(value: any) {
|
|
132
|
-
this._validate = value;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
117
|
app(config: any = {}): BaseChyz {
|
|
136
118
|
|
|
137
119
|
/**
|
|
@@ -144,14 +126,9 @@ export default class BaseChyz {
|
|
|
144
126
|
if (components) {
|
|
145
127
|
for (const componentsKey in components) {
|
|
146
128
|
let comp = components[componentsKey];
|
|
147
|
-
BaseChyz.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
BaseChyz.components[componentsKey]?.init();
|
|
151
|
-
}catch (e) {
|
|
152
|
-
console.error(e)
|
|
153
|
-
}
|
|
154
|
-
|
|
129
|
+
BaseChyz.debug("Create Component ", componentsKey)
|
|
130
|
+
BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
|
|
131
|
+
BaseChyz.components[componentsKey]?.init();
|
|
155
132
|
}
|
|
156
133
|
}
|
|
157
134
|
|
|
@@ -160,13 +137,14 @@ export default class BaseChyz {
|
|
|
160
137
|
if (middlewares) {
|
|
161
138
|
for (const middlewareKey in middlewares) {
|
|
162
139
|
let middleware1 = middlewares[middlewareKey];
|
|
163
|
-
BaseChyz.
|
|
140
|
+
BaseChyz.debug("Create middlewares ", middlewareKey)
|
|
164
141
|
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
165
142
|
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
166
143
|
}
|
|
167
144
|
}
|
|
168
145
|
|
|
169
146
|
|
|
147
|
+
|
|
170
148
|
this.init();
|
|
171
149
|
|
|
172
150
|
return this;
|
|
@@ -251,30 +229,6 @@ export default class BaseChyz {
|
|
|
251
229
|
return BaseChyz.middlewares[key] ?? null
|
|
252
230
|
}
|
|
253
231
|
|
|
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
232
|
|
|
279
233
|
/**
|
|
280
234
|
* load contoller
|
|
@@ -334,8 +288,8 @@ export default class BaseChyz {
|
|
|
334
288
|
res.status(e.statusCode || 500)
|
|
335
289
|
// @ts-ignore
|
|
336
290
|
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
337
|
-
}
|
|
338
|
-
res.json(e)
|
|
291
|
+
}else{
|
|
292
|
+
res.json(e )
|
|
339
293
|
}
|
|
340
294
|
}
|
|
341
295
|
})
|
|
@@ -354,6 +308,7 @@ export default class BaseChyz {
|
|
|
354
308
|
BaseChyz.express.use(methodOverride());
|
|
355
309
|
|
|
356
310
|
|
|
311
|
+
|
|
357
312
|
// CORS
|
|
358
313
|
BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
359
314
|
// @ts-ignore
|
|
@@ -397,3 +352,10 @@ export default class BaseChyz {
|
|
|
397
352
|
|
|
398
353
|
|
|
399
354
|
}
|
|
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
|
|
10
|
+
import {Controller} from "../../base";
|
|
11
11
|
import BaseChyz from "../../BaseChyz";
|
|
12
12
|
// @ts-ignore
|
|
13
13
|
import {Request, Response} from "express";
|
|
@@ -18,9 +18,10 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
|
18
18
|
|
|
19
19
|
import {ValidationHttpException} from "../../base";
|
|
20
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
21
|
+
import {OrderClass, Order} from "../Models/Order";
|
|
22
|
+
import {CustomerClass, Customer} from "../Models/Customer";
|
|
23
|
+
import {Products} from "../Models/Products";
|
|
24
|
+
import {ProductModels} from "../Models/ProductModels";
|
|
24
25
|
|
|
25
26
|
@controller("/api")
|
|
26
27
|
class ApiController extends Controller {
|
|
@@ -36,18 +37,22 @@ class ApiController extends Controller {
|
|
|
36
37
|
"class": JwtHttpBearerAuth,
|
|
37
38
|
// "auth": this.myCheck
|
|
38
39
|
},
|
|
39
|
-
'access': {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
// 'access': {
|
|
41
|
+
// 'class': AccessControl,
|
|
42
|
+
// 'only': ['login', 'logout', 'signup'],
|
|
43
|
+
// 'rules': [
|
|
44
|
+
// {
|
|
45
|
+
// 'allow': true,
|
|
46
|
+
// 'actions': ['login', 'index'],
|
|
47
|
+
// 'roles': ['?'],
|
|
48
|
+
// },
|
|
49
|
+
// {
|
|
50
|
+
// 'allow': true,
|
|
51
|
+
// 'actions': ['logout', "logout2"],
|
|
52
|
+
// 'roles': ['@'],
|
|
53
|
+
// }
|
|
54
|
+
// ]
|
|
55
|
+
// }
|
|
51
56
|
}]
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -65,15 +70,17 @@ class ApiController extends Controller {
|
|
|
65
70
|
data.Customer["2fa"] = "true";
|
|
66
71
|
|
|
67
72
|
//Customer Model Create
|
|
68
|
-
let customer =
|
|
73
|
+
let customer: CustomerClass = Customer;
|
|
69
74
|
//Order Model Create
|
|
70
|
-
let order =
|
|
75
|
+
let order: OrderClass = Order;
|
|
71
76
|
|
|
72
77
|
|
|
73
78
|
let transaction
|
|
74
79
|
try {
|
|
75
80
|
// get transaction
|
|
76
81
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
82
|
+
|
|
83
|
+
|
|
77
84
|
customer.load(data, "Customer");//load customer data
|
|
78
85
|
let cus: any = await customer.save({}, {transaction});
|
|
79
86
|
|
|
@@ -110,23 +117,7 @@ class ApiController extends Controller {
|
|
|
110
117
|
|
|
111
118
|
@get("order/list")
|
|
112
119
|
async listOrder(req: Request, res: Response) {
|
|
113
|
-
|
|
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
|
-
});
|
|
120
|
+
let product = await Products.findAll({include: [ProductModels.model()]});
|
|
130
121
|
return res.json(product)
|
|
131
122
|
|
|
132
123
|
}
|
|
@@ -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} from "../Models/Order";
|
|
20
|
-
import {CustomerClass} from "../Models/Customer";
|
|
19
|
+
import {OrderClass, Order} from "../Models/Order";
|
|
20
|
+
import {CustomerClass, Customer} 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 = Customer;
|
|
50
50
|
//Order Model Create
|
|
51
|
-
let order: OrderClass =
|
|
51
|
+
let order: OrderClass = Order ;
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
let transaction
|
|
@@ -26,12 +26,11 @@ class SiteController extends Controller {
|
|
|
26
26
|
public myCheck(token) {
|
|
27
27
|
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
public behaviors(): any[] {
|
|
31
30
|
return [{
|
|
32
31
|
'authenticator': {
|
|
33
32
|
"class": JwtHttpBearerAuth,
|
|
34
|
-
"except":
|
|
33
|
+
"except":["index","login"]
|
|
35
34
|
// "auth": this.myCheck
|
|
36
35
|
}
|
|
37
36
|
}]
|
|
@@ -89,40 +88,25 @@ class SiteController extends Controller {
|
|
|
89
88
|
// @ts-ignore
|
|
90
89
|
let xForwardedFor = (req.headers['x-forwarded-for'] || '').replace(/:\d+$/, '');
|
|
91
90
|
let ip = xForwardedFor || req.socket.remoteAddress;
|
|
92
|
-
var source: string
|
|
91
|
+
var source: string = req.headers['user-agent'] || '';
|
|
93
92
|
if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
|
|
94
|
-
source = req.headers['x-ucbrowser-ua']
|
|
93
|
+
source = req.headers['x-ucbrowser-ua']+"";
|
|
95
94
|
}
|
|
96
95
|
token = await JsonWebToken.sign({
|
|
97
96
|
user: user.id,
|
|
98
97
|
ip: ip,
|
|
99
98
|
agent: source,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
],
|
|
104
|
-
permissions: [
|
|
105
|
-
"alprboxkoli",
|
|
106
|
-
"edisboxkoli",
|
|
107
|
-
"hubboxkoli",
|
|
108
|
-
"edisboxold",
|
|
109
|
-
"edisboxnew",
|
|
110
|
-
"hubboxold",
|
|
111
|
-
"hubboxnew",
|
|
112
|
-
"alprboxold",
|
|
113
|
-
"alprboxnew"
|
|
114
|
-
],
|
|
115
|
-
}, user.authkey, null);
|
|
116
|
-
|
|
117
|
-
BaseChyz.debug("Db user create access token", username, "expiresIn", "1h")
|
|
99
|
+
}, user.authkey, {expiresIn: '1h'});
|
|
100
|
+
|
|
101
|
+
BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
|
|
118
102
|
return res.json({token: token})
|
|
119
103
|
} else {
|
|
120
104
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
121
|
-
res.status(500).json(error.toJSON())
|
|
105
|
+
res.status(500).json( error.toJSON())
|
|
122
106
|
}
|
|
123
107
|
} else {
|
|
124
108
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
125
|
-
res.status(500).json(error.toJSON())
|
|
109
|
+
res.status(500).json( error.toJSON())
|
|
126
110
|
}
|
|
127
111
|
|
|
128
112
|
|
|
@@ -152,5 +136,4 @@ class SiteController extends Controller {
|
|
|
152
136
|
return res.send("Post Controller")
|
|
153
137
|
}
|
|
154
138
|
}
|
|
155
|
-
|
|
156
|
-
module.exports = SiteController
|
|
139
|
+
module.exports=SiteController
|
|
@@ -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
|
|
7
|
+
import {DataTypes, Model} from "../../base";
|
|
8
8
|
|
|
9
9
|
export class CategoriesClass extends Model {
|
|
10
10
|
[x: string]: any;
|
|
@@ -29,19 +29,8 @@ export class CategoriesClass extends Model {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
relations(): Relation[] {
|
|
33
|
-
return [
|
|
34
|
-
{
|
|
35
|
-
type: "belongsToMany",
|
|
36
|
-
foreignKey: "category_id",
|
|
37
|
-
sourceKey: "id",
|
|
38
|
-
model: ModelManager.Products.model(),
|
|
39
|
-
through: ModelManager.ProductToCategories.model()
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
32
|
|
|
44
33
|
}
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
const Categories = new CategoriesClass();
|
|
36
|
+
export {Categories};
|
package/Examples/Models/Order.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {DataTypes, Model, Relation} from "../../base";
|
|
2
|
-
import {
|
|
2
|
+
import {OrderItem} 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: OrderItem.model()
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const Order = new OrderClass()
|
|
60
|
+
export {Order};
|
|
61
|
+
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes,
|
|
7
|
+
import {DataTypes, Model, Relation} from "../../base";
|
|
8
|
+
import {Products} from "./Products";
|
|
8
9
|
|
|
9
10
|
export class ProductModelsClass extends Model {
|
|
10
11
|
[x: string]: any;
|
|
@@ -39,11 +40,11 @@ export class ProductModelsClass extends Model {
|
|
|
39
40
|
type: "hasOne",
|
|
40
41
|
foreignKey: "id",
|
|
41
42
|
sourceKey: "category_id",
|
|
42
|
-
model:
|
|
43
|
+
model: Products.model()
|
|
43
44
|
}
|
|
44
45
|
]
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const ProductModels = new ProductModelsClass();
|
|
50
|
+
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,
|
|
7
|
+
import {DataTypes, Model} 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
|
+
categories_id: {
|
|
25
25
|
type: DataTypes.INTEGER,
|
|
26
26
|
allowNull: false
|
|
27
27
|
}
|
|
@@ -29,18 +29,7 @@ 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
|
-
|
|
43
32
|
}
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
const ProductToCategories = new ProductToCategoriesClass()
|
|
35
|
+
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,
|
|
8
|
-
|
|
7
|
+
import {DataTypes, Model, Relation} from "../../base";
|
|
8
|
+
import {ProductModels} from "./ProductModels";
|
|
9
9
|
|
|
10
10
|
export class ProductsClass extends Model {
|
|
11
11
|
[x: string]: any;
|
|
@@ -36,15 +36,14 @@ export class ProductsClass extends Model {
|
|
|
36
36
|
relations(): Relation[] {
|
|
37
37
|
return [
|
|
38
38
|
{
|
|
39
|
-
type: "
|
|
40
|
-
foreignKey: "
|
|
41
|
-
sourceKey: "
|
|
42
|
-
model:
|
|
43
|
-
through: ModelManager.ProductToCategories.model()
|
|
39
|
+
type: "hasOne",
|
|
40
|
+
foreignKey: "id",
|
|
41
|
+
sourceKey: "model_id",
|
|
42
|
+
model: ProductModels.model()
|
|
44
43
|
}
|
|
45
44
|
]
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const Products = new ProductsClass()
|
|
49
|
+
export {Products}
|
package/Examples/Models/User.ts
CHANGED
|
@@ -28,11 +28,6 @@ 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
|
-
|
|
36
31
|
getAuthKey(): string {
|
|
37
32
|
throw new Error("Method not implemented.");
|
|
38
33
|
}
|
|
@@ -76,8 +71,8 @@ export class User extends Model implements IdentityInterface {
|
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
async findIdentityByAccessToken(token, type) {
|
|
79
|
-
|
|
80
74
|
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
75
|
+
|
|
81
76
|
if(!decoded.payload.user) {
|
|
82
77
|
return null;
|
|
83
78
|
}
|
|
@@ -102,6 +97,4 @@ export class User extends Model implements IdentityInterface {
|
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
|
|
107
100
|
}
|
package/Examples/index.ts
CHANGED
|
@@ -7,22 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
import {BaseChyz} from "../index";
|
|
10
|
-
|
|
11
10
|
require('dotenv-flow').config();
|
|
12
11
|
import Chyz from "../Chyz";
|
|
13
12
|
import {WebUser} from "../web/WebUser";
|
|
14
13
|
import {User} from "./Models/User";
|
|
15
14
|
import {DbConnection} from "../base";
|
|
16
|
-
import {AuthManager} from "../rbac/AuthManager";
|
|
17
|
-
|
|
18
15
|
|
|
19
16
|
let config = {
|
|
20
17
|
port: process.env.PORT,
|
|
21
18
|
controllerpath: "C:\\PROJELER\\github\\Chy-Nodejs-Framework\\Examples\\Controllers",
|
|
22
19
|
components: {
|
|
23
|
-
authManager: {
|
|
24
|
-
class: AuthManager,
|
|
25
|
-
},
|
|
26
20
|
db: {
|
|
27
21
|
class: DbConnection,
|
|
28
22
|
database: process.env.DBDATABASE,
|