chyz 1.0.12-rc.9 → 1.0.13-rc.12
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 +103 -17
- package/Examples/Controllers/ApiController.ts +55 -33
- package/Examples/Controllers/BasicApiController.ts +121 -0
- package/Examples/Controllers/KeyCloakController.ts +100 -0
- package/Examples/Controllers/PublicController.ts +5 -7
- package/Examples/Controllers/SiteController.ts +42 -13
- package/Examples/Models/Categories.ts +47 -0
- package/Examples/Models/Customer.ts +10 -8
- package/Examples/Models/KeycloakUser.ts +70 -0
- package/Examples/Models/Order.ts +33 -17
- package/Examples/Models/OrderItem.ts +4 -3
- package/Examples/Models/ProductModels.ts +49 -0
- package/Examples/Models/ProductToCategories.ts +46 -0
- package/Examples/Models/Products.ts +50 -0
- package/Examples/Models/Stocks.ts +60 -0
- package/Examples/Models/User.ts +33 -6
- package/Examples/Models/UserPermission.ts +37 -0
- package/Examples/Models/index.ts +19 -0
- package/Examples/index-keycloack.ts +78 -0
- package/Examples/index.ts +16 -14
- package/Examples/keycloak.json +7 -0
- package/Examples/log/access.log +0 -0
- package/Examples/log/app.log +6858 -0
- package/Examples/log/errors.log +1611 -0
- package/Examples/package.json +46 -45
- package/Examples/tsconfig.json +2 -1
- package/Examples/yarn.lock +354 -7
- package/README.md +78 -28
- package/base/ActionFilter.ts +2 -2
- package/base/BaseError.ts +2 -2
- package/base/DataErrorDbException.ts +1 -1
- package/base/ForbiddenHttpException.ts +1 -1
- package/base/InvalidArgumentException.ts +16 -0
- package/base/InvalidConfigException.ts +1 -1
- package/base/Model.ts +158 -12
- package/base/ModelManager.ts +19 -0
- package/base/NotFoundHttpException.ts +1 -1
- package/base/RestClient.ts +28 -0
- package/base/UnauthorizedHttpException.ts +2 -1
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +4 -0
- package/dist/BaseChyz.js +86 -11
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +2 -2
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +2 -2
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/DataErrorDbException.js +1 -1
- package/dist/base/DataErrorDbException.js.map +1 -1
- package/dist/base/ForbiddenHttpException.js +1 -1
- package/dist/base/ForbiddenHttpException.js.map +1 -1
- package/dist/base/InvalidArgumentException.js +18 -0
- package/dist/base/InvalidArgumentException.js.map +1 -0
- package/dist/base/InvalidConfigException.js +1 -1
- package/dist/base/InvalidConfigException.js.map +1 -1
- package/dist/base/Model.js +127 -5
- 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/NotFoundHttpException.js +1 -1
- package/dist/base/NotFoundHttpException.js.map +1 -1
- package/dist/base/RestClient.js +27 -0
- package/dist/base/RestClient.js.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +1 -1
- package/dist/base/UnauthorizedHttpException.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/ValidationHttpException.js.map +1 -1
- package/dist/base/index.js +4 -0
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +2 -2
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/AuthMethod.js +2 -2
- package/dist/filters/auth/AuthMethod.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/HttpHeaderAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
- package/dist/filters/auth/index.js +1 -0
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/log/config/log4js.json +55 -0
- package/dist/package.json +57 -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/dist/web/{User.js → WebUser.js} +12 -7
- package/dist/web/WebUser.js.map +1 -0
- package/filters/AccessControl.ts +3 -3
- package/filters/AccessRule.ts +2 -2
- package/filters/auth/AuthMethod.ts +4 -4
- package/filters/auth/HttpBasicAuth.ts +68 -0
- package/filters/auth/HttpHeaderAuth.ts +2 -2
- package/filters/auth/JwtHttpBearerAuth.ts +4 -5
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/filters/auth/index.ts +1 -0
- package/index.ts +14 -0
- package/log/config/log4js.json +55 -0
- package/package.json +57 -52
- 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/web/{User.ts → WebUser.ts} +10 -6
- package/dist/web/User.js.map +0 -1
package/BaseChyz.ts
CHANGED
|
@@ -3,13 +3,15 @@ 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');
|
|
11
|
-
const
|
|
12
|
+
const validate = require('validate.js');
|
|
12
13
|
|
|
14
|
+
var ip = require('ip');
|
|
13
15
|
var bodyParser = require('body-parser')
|
|
14
16
|
var methodOverride = require('method-override')
|
|
15
17
|
|
|
@@ -21,10 +23,13 @@ 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> = []
|
|
27
30
|
public static components: any = {}
|
|
31
|
+
public static middlewares: any = {}
|
|
32
|
+
|
|
28
33
|
|
|
29
34
|
get logConfig(): any {
|
|
30
35
|
return this._logConfig;
|
|
@@ -61,7 +66,6 @@ export default class BaseChyz {
|
|
|
61
66
|
writable: true
|
|
62
67
|
})
|
|
63
68
|
|
|
64
|
-
|
|
65
69
|
Object.defineProperty(BaseChyz.express.request, 'identity', {
|
|
66
70
|
configurable: true,
|
|
67
71
|
enumerable: true,
|
|
@@ -82,6 +86,13 @@ export default class BaseChyz {
|
|
|
82
86
|
this.controllerpath = this.config.controllerpath
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Model Register
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
this.loadModels();
|
|
95
|
+
|
|
85
96
|
/**
|
|
86
97
|
* Express Server
|
|
87
98
|
*/
|
|
@@ -113,6 +124,14 @@ export default class BaseChyz {
|
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
|
|
127
|
+
static get validate(): any {
|
|
128
|
+
return this._validate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static set validate(value: any) {
|
|
132
|
+
this._validate = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
116
135
|
app(config: any = {}): BaseChyz {
|
|
117
136
|
|
|
118
137
|
/**
|
|
@@ -120,18 +139,36 @@ export default class BaseChyz {
|
|
|
120
139
|
*/
|
|
121
140
|
this.config = config;
|
|
122
141
|
|
|
123
|
-
this.init();
|
|
124
142
|
|
|
125
143
|
let components = Utils.findKeyValue(config, "components")
|
|
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
|
|
|
158
|
+
|
|
159
|
+
let middlewares = Utils.findKeyValue(config, "middlewares")
|
|
160
|
+
if (middlewares) {
|
|
161
|
+
for (const middlewareKey in middlewares) {
|
|
162
|
+
let middleware1 = middlewares[middlewareKey];
|
|
163
|
+
BaseChyz.logs().debug("Create middlewares ", middlewareKey)
|
|
164
|
+
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
165
|
+
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
this.init();
|
|
171
|
+
|
|
135
172
|
return this;
|
|
136
173
|
}
|
|
137
174
|
|
|
@@ -140,7 +177,7 @@ export default class BaseChyz {
|
|
|
140
177
|
return log4js;
|
|
141
178
|
}
|
|
142
179
|
|
|
143
|
-
public getLogger(){
|
|
180
|
+
public getLogger() {
|
|
144
181
|
return this.logProvider().getLogger(this.constructor.name);
|
|
145
182
|
}
|
|
146
183
|
|
|
@@ -151,12 +188,15 @@ export default class BaseChyz {
|
|
|
151
188
|
public static trace(...args: any[]) {
|
|
152
189
|
BaseChyz.logs().fatal(...arguments)
|
|
153
190
|
}
|
|
191
|
+
|
|
154
192
|
public static debug(...args: any[]) {
|
|
155
193
|
BaseChyz.logs().debug(...arguments)
|
|
156
194
|
}
|
|
195
|
+
|
|
157
196
|
public static info(...args: any[]) {
|
|
158
197
|
BaseChyz.logs().info(...arguments)
|
|
159
198
|
}
|
|
199
|
+
|
|
160
200
|
public static warn(...args: any[]) {
|
|
161
201
|
BaseChyz.logs().warn(...arguments)
|
|
162
202
|
}
|
|
@@ -170,8 +210,6 @@ export default class BaseChyz {
|
|
|
170
210
|
}
|
|
171
211
|
|
|
172
212
|
|
|
173
|
-
|
|
174
|
-
|
|
175
213
|
public static warning(...args: any[]) {
|
|
176
214
|
BaseChyz.logs().warn(...arguments)
|
|
177
215
|
}
|
|
@@ -208,6 +246,36 @@ export default class BaseChyz {
|
|
|
208
246
|
return BaseChyz.components[key] ?? null
|
|
209
247
|
}
|
|
210
248
|
|
|
249
|
+
|
|
250
|
+
public static getMiddlewares(key: any) {
|
|
251
|
+
return BaseChyz.middlewares[key] ?? null
|
|
252
|
+
}
|
|
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
|
+
}
|
|
278
|
+
|
|
211
279
|
/**
|
|
212
280
|
* load contoller
|
|
213
281
|
*/
|
|
@@ -259,10 +327,16 @@ export default class BaseChyz {
|
|
|
259
327
|
await instance[route.methodName](req, res, next);
|
|
260
328
|
instance.afterAction(route, req, res);
|
|
261
329
|
} catch (e) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
}
|
|
266
340
|
}
|
|
267
341
|
})
|
|
268
342
|
|
|
@@ -277,8 +351,7 @@ export default class BaseChyz {
|
|
|
277
351
|
BaseChyz.express.use(bodyParser.json())
|
|
278
352
|
BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
|
|
279
353
|
BaseChyz.express.use(methodOverride());
|
|
280
|
-
BaseChyz.express.use(
|
|
281
|
-
BaseChyz.express.use(this.errorHandler)
|
|
354
|
+
BaseChyz.express.use(methodOverride());
|
|
282
355
|
|
|
283
356
|
|
|
284
357
|
// CORS
|
|
@@ -293,7 +366,20 @@ export default class BaseChyz {
|
|
|
293
366
|
next();
|
|
294
367
|
});
|
|
295
368
|
|
|
369
|
+
//Middlewares
|
|
370
|
+
for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
|
|
371
|
+
if (!Utils.isFunction(middleware1)) {
|
|
372
|
+
let keycloak = BaseChyz.middlewares[middleware1].keycloak;
|
|
373
|
+
BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
|
|
374
|
+
} else {
|
|
375
|
+
BaseChyz.express.use(BaseChyz.middlewares[middleware1]);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
296
380
|
|
|
381
|
+
BaseChyz.express.use(this.errorResponder)
|
|
382
|
+
BaseChyz.express.use(this.errorHandler)
|
|
297
383
|
}
|
|
298
384
|
|
|
299
385
|
|
|
@@ -303,11 +389,11 @@ export default class BaseChyz {
|
|
|
303
389
|
BaseChyz.express.listen(this._port, () => {
|
|
304
390
|
BaseChyz.info("Express Server Start ")
|
|
305
391
|
BaseChyz.info(`Liten Port ${this._port}`)
|
|
392
|
+
BaseChyz.info(`http://localhost:${this._port}`)
|
|
393
|
+
BaseChyz.info(`http://${ip.address()}:${this._port}`)
|
|
306
394
|
})
|
|
307
395
|
return this;
|
|
308
396
|
}
|
|
309
397
|
|
|
310
398
|
|
|
311
399
|
}
|
|
312
|
-
|
|
313
|
-
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
3
4
|
* Author: Cihan Ozturk
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
import {Controller} from "../../base
|
|
10
|
+
import {Controller, ModelManager} from "../../base";
|
|
9
11
|
import BaseChyz from "../../BaseChyz";
|
|
10
12
|
// @ts-ignore
|
|
11
13
|
import {Request, Response} from "express";
|
|
12
|
-
import {get} from "../../decorator
|
|
13
|
-
import {post} from "../../decorator
|
|
14
|
-
import {controller} from "../../decorator
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
import {Customer} from "../Models/Customer";
|
|
19
|
-
import {ValidationHttpException} from "../../base/ValidationHttpException";
|
|
20
|
-
import {ValidationError} from "sequelize";
|
|
14
|
+
import {get} from "../../decorator";
|
|
15
|
+
import {post} from "../../decorator";
|
|
16
|
+
import {controller} from "../../decorator";
|
|
17
|
+
import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
18
|
+
|
|
19
|
+
import {ValidationHttpException} from "../../base";
|
|
21
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
+
import {ProductsClass} from "../Models/Products";
|
|
22
|
+
|
|
22
23
|
|
|
23
24
|
@controller("/api")
|
|
24
25
|
class ApiController extends Controller {
|
|
@@ -34,22 +35,22 @@ class ApiController extends Controller {
|
|
|
34
35
|
"class": JwtHttpBearerAuth,
|
|
35
36
|
// "auth": this.myCheck
|
|
36
37
|
},
|
|
37
|
-
'access': {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
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
|
+
// }
|
|
53
54
|
}]
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -67,17 +68,15 @@ class ApiController extends Controller {
|
|
|
67
68
|
data.Customer["2fa"] = "true";
|
|
68
69
|
|
|
69
70
|
//Customer Model Create
|
|
70
|
-
let customer
|
|
71
|
+
let customer = ModelManager.Customer.save();
|
|
71
72
|
//Order Model Create
|
|
72
|
-
let order
|
|
73
|
+
let order = ModelManager.Order;
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
let transaction
|
|
76
77
|
try {
|
|
77
78
|
// get transaction
|
|
78
79
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
79
|
-
|
|
80
|
-
|
|
81
80
|
customer.load(data, "Customer");//load customer data
|
|
82
81
|
let cus: any = await customer.save({}, {transaction});
|
|
83
82
|
|
|
@@ -112,6 +111,29 @@ class ApiController extends Controller {
|
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
|
|
114
|
+
@get("order/list")
|
|
115
|
+
async listOrder(req: Request, res: Response) {
|
|
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
|
+
});
|
|
133
|
+
return res.json(product)
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
115
137
|
error(req: Request, res: Response) {
|
|
116
138
|
BaseChyz.logs().info("Error Sayfası")
|
|
117
139
|
return res.send("Post Controller")
|
|
@@ -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
|
|
@@ -0,0 +1,100 @@
|
|
|
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} from "../../base/Controller";
|
|
11
|
+
import BaseChyz from "../../BaseChyz";
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import {Request, Response} from "express";
|
|
14
|
+
import {get,post,controller} from "../../decorator";
|
|
15
|
+
|
|
16
|
+
import {ValidationHttpException,ForbiddenHttpException} from "../../base";
|
|
17
|
+
import {KeyCloakHttpBearerAuth} from "../../filters/auth/KeyCloakHttpBearerAuth";
|
|
18
|
+
|
|
19
|
+
import {OrderClass} from "../Models/Order";
|
|
20
|
+
import {CustomerClass} from "../Models/Customer";
|
|
21
|
+
|
|
22
|
+
@controller("/oauth2.0")
|
|
23
|
+
class ApiController extends Controller {
|
|
24
|
+
|
|
25
|
+
public behaviors(): any[] {
|
|
26
|
+
|
|
27
|
+
return [{
|
|
28
|
+
'authenticator': {
|
|
29
|
+
"class": KeyCloakHttpBearerAuth,
|
|
30
|
+
// "auth": this.myCheck
|
|
31
|
+
}
|
|
32
|
+
}]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@get("/")
|
|
36
|
+
Index(req: Request, res: Response) {
|
|
37
|
+
|
|
38
|
+
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
39
|
+
return res.json({message: "index sayfası"})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@post("orderCreate")
|
|
43
|
+
async Login(req: Request, res: Response) {
|
|
44
|
+
let data = req.body;
|
|
45
|
+
data.Customer.status = "true";
|
|
46
|
+
data.Customer["2fa"] = "true";
|
|
47
|
+
|
|
48
|
+
//Customer Model Create
|
|
49
|
+
let customer: CustomerClass = new CustomerClass();
|
|
50
|
+
//Order Model Create
|
|
51
|
+
let order: OrderClass = new OrderClass() ;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
let transaction
|
|
55
|
+
try {
|
|
56
|
+
// get transaction
|
|
57
|
+
transaction = await BaseChyz.getComponent("db").transaction();
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
customer.load(data, "Customer");//load customer data
|
|
61
|
+
let cus: any = await customer.save({}, {transaction});
|
|
62
|
+
|
|
63
|
+
if (!cus) {
|
|
64
|
+
throw new ValidationHttpException(customer.errors);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
data.Order.customer_id = cus.id;
|
|
68
|
+
// data.Order.total = 0;
|
|
69
|
+
// data.Order.status = true;
|
|
70
|
+
order.load(data, "Order");
|
|
71
|
+
let res1 = await order.save({}, {transaction});
|
|
72
|
+
if (!res1) {
|
|
73
|
+
throw new ValidationHttpException(order.errors);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// commit
|
|
77
|
+
await transaction.commit();
|
|
78
|
+
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (transaction) {
|
|
81
|
+
await transaction.rollback();
|
|
82
|
+
BaseChyz.warn("Rollback transaction")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (e instanceof ValidationHttpException)
|
|
86
|
+
throw new ValidationHttpException(e.message)
|
|
87
|
+
else
|
|
88
|
+
throw new ForbiddenHttpException(e.message)
|
|
89
|
+
}
|
|
90
|
+
return res.send("Post Controller")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
error(req: Request, res: Response) {
|
|
95
|
+
BaseChyz.logs().info("Error Sayfası")
|
|
96
|
+
return res.send("Post Controller")
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = ApiController
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
3
4
|
* Author: Cihan Ozturk
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
import {Controller} from "../../base/Controller";
|
|
@@ -10,11 +12,7 @@ import BaseChyz from "../../BaseChyz";
|
|
|
10
12
|
// @ts-ignore
|
|
11
13
|
import {Request, Response} from "express";
|
|
12
14
|
import {get} from "../../decorator/get";
|
|
13
|
-
import {post} from "../../decorator/post";
|
|
14
15
|
import {controller} from "../../decorator/controller";
|
|
15
|
-
import {AccessControl} from "../../filters/AccessControl";
|
|
16
|
-
import {JwtHttpBearerAuth} from "../../filters/auth/JwtHttpBearerAuth";
|
|
17
|
-
import Utils from "../../requiments/Utils";
|
|
18
16
|
|
|
19
17
|
@controller("/public")
|
|
20
18
|
class PublicController extends Controller {
|