chyz 1.0.13-rc.1 → 1.0.13-rc.13
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 +61 -17
- package/Examples/Controllers/ApiController.ts +22 -10
- package/Examples/Controllers/BasicApiController.ts +121 -0
- package/Examples/Controllers/KeyCloakController.ts +4 -4
- package/Examples/Controllers/SiteController.ts +26 -9
- package/Examples/Models/Categories.ts +14 -3
- package/Examples/Models/Customer.ts +2 -2
- package/Examples/Models/KeycloakUser.ts +4 -0
- 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/User.ts +8 -1
- 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 +5987 -0
- package/Examples/log/errors.log +1531 -0
- package/Examples/tsconfig.json +2 -1
- package/README.md +9 -14
- package/base/BaseError.ts +3 -1
- package/base/InvalidArgumentException.ts +16 -0
- package/base/Model.ts +50 -49
- package/base/ModelManager.ts +19 -0
- package/base/index.ts +2 -0
- package/dist/BaseChyz.js +56 -12
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/BaseError.js +5 -1
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/InvalidArgumentException.js +18 -0
- package/dist/base/InvalidArgumentException.js.map +1 -0
- package/dist/base/Model.js +32 -28
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +9 -0
- package/dist/base/ModelManager.js.map +1 -0
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +65 -0
- 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 +1 -0
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +56 -0
- package/dist/rbac/AuthAssignment.js +45 -0
- package/dist/rbac/AuthAssignment.js.map +1 -0
- package/dist/rbac/AuthItem.js +52 -0
- package/dist/rbac/AuthItem.js.map +1 -0
- package/dist/rbac/AuthItemChild.js +44 -0
- package/dist/rbac/AuthItemChild.js.map +1 -0
- package/dist/rbac/AuthManager.js +351 -0
- package/dist/rbac/AuthManager.js.map +1 -0
- package/filters/auth/HttpBasicAuth.ts +68 -0
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +1 -0
- package/index.ts +2 -2
- package/package.json +6 -5
- package/rbac/AuthAssignment.ts +50 -0
- package/rbac/AuthItem.ts +57 -0
- package/rbac/AuthItemChild.ts +50 -0
- package/rbac/AuthManager.ts +390 -0
- package/web/IdentityInterface.ts +6 -0
package/BaseChyz.ts
CHANGED
|
@@ -3,11 +3,13 @@ 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");
|
|
9
10
|
const log4js = require("log4js");
|
|
10
11
|
const fs = require('fs');
|
|
12
|
+
const validate = require('validate.js');
|
|
11
13
|
|
|
12
14
|
var ip = require('ip');
|
|
13
15
|
var bodyParser = require('body-parser')
|
|
@@ -21,6 +23,7 @@ export default class BaseChyz {
|
|
|
21
23
|
private _port: number = 3001;
|
|
22
24
|
static db: any;
|
|
23
25
|
static routes: any;
|
|
26
|
+
private static _validate:any=validate;
|
|
24
27
|
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
25
28
|
private _controllerpath: string = "Controllers"
|
|
26
29
|
private static controllers: Array<Controller> = []
|
|
@@ -83,6 +86,13 @@ export default class BaseChyz {
|
|
|
83
86
|
this.controllerpath = this.config.controllerpath
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Model Register
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
this.loadModels();
|
|
95
|
+
|
|
86
96
|
/**
|
|
87
97
|
* Express Server
|
|
88
98
|
*/
|
|
@@ -114,6 +124,14 @@ export default class BaseChyz {
|
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
|
|
127
|
+
static get validate(): any {
|
|
128
|
+
return this._validate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static set validate(value: any) {
|
|
132
|
+
this._validate = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
app(config: any = {}): BaseChyz {
|
|
118
136
|
|
|
119
137
|
/**
|
|
@@ -126,9 +144,14 @@ export default class BaseChyz {
|
|
|
126
144
|
if (components) {
|
|
127
145
|
for (const componentsKey in components) {
|
|
128
146
|
let comp = components[componentsKey];
|
|
129
|
-
BaseChyz.
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
|
|
132
155
|
}
|
|
133
156
|
}
|
|
134
157
|
|
|
@@ -137,14 +160,13 @@ export default class BaseChyz {
|
|
|
137
160
|
if (middlewares) {
|
|
138
161
|
for (const middlewareKey in middlewares) {
|
|
139
162
|
let middleware1 = middlewares[middlewareKey];
|
|
140
|
-
BaseChyz.debug("Create middlewares ", middlewareKey)
|
|
163
|
+
BaseChyz.logs().debug("Create middlewares ", middlewareKey)
|
|
141
164
|
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
142
165
|
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
143
166
|
}
|
|
144
167
|
}
|
|
145
168
|
|
|
146
169
|
|
|
147
|
-
|
|
148
170
|
this.init();
|
|
149
171
|
|
|
150
172
|
return this;
|
|
@@ -229,6 +251,30 @@ export default class BaseChyz {
|
|
|
229
251
|
return BaseChyz.middlewares[key] ?? null
|
|
230
252
|
}
|
|
231
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
|
+
}
|
|
232
278
|
|
|
233
279
|
/**
|
|
234
280
|
* load contoller
|
|
@@ -281,10 +327,16 @@ export default class BaseChyz {
|
|
|
281
327
|
await instance[route.methodName](req, res, next);
|
|
282
328
|
instance.afterAction(route, req, res);
|
|
283
329
|
} catch (e) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
+
}
|
|
288
340
|
}
|
|
289
341
|
})
|
|
290
342
|
|
|
@@ -302,7 +354,6 @@ export default class BaseChyz {
|
|
|
302
354
|
BaseChyz.express.use(methodOverride());
|
|
303
355
|
|
|
304
356
|
|
|
305
|
-
|
|
306
357
|
// CORS
|
|
307
358
|
BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
308
359
|
// @ts-ignore
|
|
@@ -346,10 +397,3 @@ export default class BaseChyz {
|
|
|
346
397
|
|
|
347
398
|
|
|
348
399
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
process.on('uncaughtException', err => {
|
|
352
|
-
BaseChyz.error('There was an uncaught error', err)
|
|
353
|
-
process.exit(1) //mandatory (as per the Node.js docs)
|
|
354
|
-
})
|
|
355
|
-
|
|
@@ -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
|
-
import {
|
|
22
|
-
|
|
23
|
-
import {Products} from "../Models/Products";
|
|
24
|
-
import {ProductModels} from "../Models/ProductModels";
|
|
21
|
+
import {ProductsClass} from "../Models/Products";
|
|
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.save();
|
|
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,23 @@ class ApiController extends Controller {
|
|
|
117
113
|
|
|
118
114
|
@get("order/list")
|
|
119
115
|
async listOrder(req: Request, res: Response) {
|
|
120
|
-
|
|
116
|
+
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
117
|
+
let product = await Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
118
|
+
return res.json(product)
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@get("categories")
|
|
123
|
+
async Categories(req: Request, res: Response) {
|
|
124
|
+
let product = await ModelManager.Categories.findAll({
|
|
125
|
+
include: [
|
|
126
|
+
{
|
|
127
|
+
model: ModelManager.Products.model(),
|
|
128
|
+
// as: 'product',
|
|
129
|
+
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
});
|
|
121
133
|
return res.json(product)
|
|
122
134
|
|
|
123
135
|
}
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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,40 @@ 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
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
platform: "admin",
|
|
101
|
+
role: [
|
|
102
|
+
"admin"
|
|
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")
|
|
102
118
|
return res.json({token: token})
|
|
103
119
|
} else {
|
|
104
120
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
105
|
-
res.status(500).json(
|
|
121
|
+
res.status(500).json(error.toJSON())
|
|
106
122
|
}
|
|
107
123
|
} else {
|
|
108
124
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
109
|
-
res.status(500).json(
|
|
125
|
+
res.status(500).json(error.toJSON())
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
|
|
@@ -136,4 +152,5 @@ class SiteController extends Controller {
|
|
|
136
152
|
return res.send("Post Controller")
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
|
-
|
|
155
|
+
|
|
156
|
+
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} from "../../base";
|
|
7
|
+
import {DataTypes, Model, ModelManager, Relation} from "../../base";
|
|
8
8
|
|
|
9
9
|
export class CategoriesClass extends Model {
|
|
10
10
|
[x: string]: any;
|
|
@@ -29,8 +29,19 @@ 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
|
+
}
|
|
32
43
|
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
const Categories = new CategoriesClass();
|
|
36
|
-
export {Categories};
|
|
46
|
+
// const Categories = new CategoriesClass();
|
|
47
|
+
// 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}
|
package/Examples/Models/User.ts
CHANGED
|
@@ -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
|
}
|