chyz 1.0.12-rc.7 → 1.0.13-rc.10
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 +118 -18
- package/Chyz.ts +0 -3
- package/Examples/Controllers/ApiController.ts +96 -29
- package/Examples/Controllers/KeyCloakController.ts +100 -0
- package/Examples/Controllers/PublicController.ts +5 -7
- package/Examples/Controllers/SiteController.ts +82 -32
- package/Examples/Models/Categories.ts +47 -0
- package/Examples/Models/Customer.ts +115 -0
- package/Examples/Models/KeycloakUser.ts +66 -0
- package/Examples/Models/Order.ts +64 -0
- package/Examples/Models/OrderItem.ts +27 -0
- 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 +66 -35
- 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/app.log +6126 -1045
- package/Examples/log/errors.log +1503 -234
- package/Examples/package.json +46 -44
- package/Examples/tsconfig.json +3 -2
- package/README.md +116 -16
- package/base/ActionFilter.ts +2 -2
- package/base/BaseError.ts +2 -2
- package/base/DataErrorDbException.ts +1 -1
- package/base/DbConnection.ts +8 -2
- package/base/ForbiddenHttpException.ts +1 -1
- package/base/InvalidArgumentException.ts +16 -0
- package/base/InvalidConfigException.ts +1 -1
- package/base/Model.ts +206 -17
- package/base/ModelManager.ts +14 -0
- package/base/NotFoundHttpException.ts +1 -1
- package/base/RestClient.ts +28 -0
- package/base/UnauthorizedHttpException.ts +2 -1
- package/base/ValidationHttpException.ts +14 -0
- package/base/db/Exception.ts +14 -0
- package/base/index.ts +4 -0
- package/dist/BaseChyz.js +108 -23
- package/dist/BaseChyz.js.map +1 -1
- package/dist/Chyz.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/DbConnection.js +9 -2
- package/dist/base/DbConnection.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 +187 -15
- 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/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 +18 -0
- package/dist/base/ValidationHttpException.js.map +1 -0
- package/dist/base/db/Exception.js +16 -0
- package/dist/base/db/Exception.js.map +1 -0
- 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/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/index.js +28 -0
- package/dist/index.js.map +1 -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/HttpHeaderAuth.ts +2 -2
- package/filters/auth/JwtHttpBearerAuth.ts +4 -5
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/index.ts +14 -0
- package/package-lock.json +5259 -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 +388 -0
- package/web/{User.ts → WebUser.ts} +10 -6
- package/.idea/Chy-Nodejs-Framework.iml +0 -12
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/web/User.js.map +0 -1
package/BaseChyz.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
1
|
import 'reflect-metadata';
|
|
3
2
|
import {RouteDefinition} from "./model/RouteDefinition";
|
|
4
3
|
import {NextFunction, Request, Response} from "express";
|
|
5
4
|
import {Controller} from "./base/Controller";
|
|
6
5
|
import Utils from "./requiments/Utils";
|
|
6
|
+
import {ModelManager} from "./base";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
const express = require("express");
|
|
10
10
|
const log4js = require("log4js");
|
|
11
11
|
const fs = require('fs');
|
|
12
|
-
const
|
|
12
|
+
const validate = require('validate.js');
|
|
13
13
|
|
|
14
|
+
var ip = require('ip');
|
|
14
15
|
var bodyParser = require('body-parser')
|
|
15
16
|
var methodOverride = require('method-override')
|
|
16
17
|
|
|
@@ -22,10 +23,13 @@ export default class BaseChyz {
|
|
|
22
23
|
private _port: number = 3001;
|
|
23
24
|
static db: any;
|
|
24
25
|
static routes: any;
|
|
26
|
+
private static _validate:any=validate;
|
|
25
27
|
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
26
28
|
private _controllerpath: string = "Controllers"
|
|
27
29
|
private static controllers: Array<Controller> = []
|
|
28
30
|
public static components: any = {}
|
|
31
|
+
public static middlewares: any = {}
|
|
32
|
+
|
|
29
33
|
|
|
30
34
|
get logConfig(): any {
|
|
31
35
|
return this._logConfig;
|
|
@@ -62,7 +66,6 @@ export default class BaseChyz {
|
|
|
62
66
|
writable: true
|
|
63
67
|
})
|
|
64
68
|
|
|
65
|
-
|
|
66
69
|
Object.defineProperty(BaseChyz.express.request, 'identity', {
|
|
67
70
|
configurable: true,
|
|
68
71
|
enumerable: true,
|
|
@@ -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,25 +124,51 @@ export default class BaseChyz {
|
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
|
|
117
|
-
|
|
127
|
+
static get validate(): any {
|
|
128
|
+
return this._validate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static set validate(value: any) {
|
|
132
|
+
this._validate = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
app(config: any = {}): BaseChyz {
|
|
118
136
|
|
|
119
137
|
/**
|
|
120
138
|
* Config set
|
|
121
139
|
*/
|
|
122
140
|
this.config = config;
|
|
123
141
|
|
|
124
|
-
this.init();
|
|
125
142
|
|
|
126
143
|
let components = Utils.findKeyValue(config, "components")
|
|
127
144
|
if (components) {
|
|
128
145
|
for (const componentsKey in components) {
|
|
129
146
|
let comp = components[componentsKey];
|
|
130
|
-
BaseChyz.
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
|
|
155
|
+
}
|
|
156
|
+
}
|
|
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);
|
|
133
166
|
}
|
|
134
167
|
}
|
|
135
168
|
|
|
169
|
+
|
|
170
|
+
this.init();
|
|
171
|
+
|
|
136
172
|
return this;
|
|
137
173
|
}
|
|
138
174
|
|
|
@@ -141,23 +177,39 @@ export default class BaseChyz {
|
|
|
141
177
|
return log4js;
|
|
142
178
|
}
|
|
143
179
|
|
|
180
|
+
public getLogger() {
|
|
181
|
+
return this.logProvider().getLogger(this.constructor.name);
|
|
182
|
+
}
|
|
144
183
|
|
|
145
184
|
static logs(...args: any[]) {
|
|
146
185
|
return log4js.getLogger(this.name);
|
|
147
186
|
}
|
|
148
187
|
|
|
188
|
+
public static trace(...args: any[]) {
|
|
189
|
+
BaseChyz.logs().fatal(...arguments)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public static debug(...args: any[]) {
|
|
193
|
+
BaseChyz.logs().debug(...arguments)
|
|
194
|
+
}
|
|
195
|
+
|
|
149
196
|
public static info(...args: any[]) {
|
|
150
197
|
BaseChyz.logs().info(...arguments)
|
|
151
198
|
}
|
|
152
199
|
|
|
200
|
+
public static warn(...args: any[]) {
|
|
201
|
+
BaseChyz.logs().warn(...arguments)
|
|
202
|
+
}
|
|
203
|
+
|
|
153
204
|
public static error(...args: any[]) {
|
|
154
205
|
BaseChyz.logs().error(...arguments)
|
|
155
206
|
}
|
|
156
207
|
|
|
157
|
-
public static
|
|
158
|
-
BaseChyz.logs().
|
|
208
|
+
public static fatal(...args: any[]) {
|
|
209
|
+
BaseChyz.logs().fatal(...arguments)
|
|
159
210
|
}
|
|
160
211
|
|
|
212
|
+
|
|
161
213
|
public static warning(...args: any[]) {
|
|
162
214
|
BaseChyz.logs().warn(...arguments)
|
|
163
215
|
}
|
|
@@ -194,6 +246,36 @@ export default class BaseChyz {
|
|
|
194
246
|
return BaseChyz.components[key] ?? null
|
|
195
247
|
}
|
|
196
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
|
+
|
|
197
279
|
/**
|
|
198
280
|
* load contoller
|
|
199
281
|
*/
|
|
@@ -245,10 +327,16 @@ export default class BaseChyz {
|
|
|
245
327
|
await instance[route.methodName](req, res, next);
|
|
246
328
|
instance.afterAction(route, req, res);
|
|
247
329
|
} catch (e) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
}
|
|
252
340
|
}
|
|
253
341
|
})
|
|
254
342
|
|
|
@@ -263,8 +351,7 @@ export default class BaseChyz {
|
|
|
263
351
|
BaseChyz.express.use(bodyParser.json())
|
|
264
352
|
BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
|
|
265
353
|
BaseChyz.express.use(methodOverride());
|
|
266
|
-
BaseChyz.express.use(
|
|
267
|
-
BaseChyz.express.use(this.errorHandler)
|
|
354
|
+
BaseChyz.express.use(methodOverride());
|
|
268
355
|
|
|
269
356
|
|
|
270
357
|
// CORS
|
|
@@ -279,7 +366,20 @@ export default class BaseChyz {
|
|
|
279
366
|
next();
|
|
280
367
|
});
|
|
281
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
|
+
|
|
282
380
|
|
|
381
|
+
BaseChyz.express.use(this.errorResponder)
|
|
382
|
+
BaseChyz.express.use(this.errorHandler)
|
|
283
383
|
}
|
|
284
384
|
|
|
285
385
|
|
|
@@ -289,11 +389,11 @@ export default class BaseChyz {
|
|
|
289
389
|
BaseChyz.express.listen(this._port, () => {
|
|
290
390
|
BaseChyz.info("Express Server Start ")
|
|
291
391
|
BaseChyz.info(`Liten Port ${this._port}`)
|
|
392
|
+
BaseChyz.info(`http://localhost:${this._port}`)
|
|
393
|
+
BaseChyz.info(`http://${ip.address()}:${this._port}`)
|
|
292
394
|
})
|
|
293
395
|
return this;
|
|
294
396
|
}
|
|
295
397
|
|
|
296
398
|
|
|
297
399
|
}
|
|
298
|
-
|
|
299
|
-
|
package/Chyz.ts
CHANGED
|
@@ -1,19 +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
|
-
|
|
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";
|
|
20
|
+
import {ForbiddenHttpException} from "../../base";
|
|
21
|
+
|
|
22
|
+
|
|
17
23
|
|
|
18
24
|
@controller("/api")
|
|
19
25
|
class ApiController extends Controller {
|
|
@@ -29,22 +35,22 @@ class ApiController extends Controller {
|
|
|
29
35
|
"class": JwtHttpBearerAuth,
|
|
30
36
|
// "auth": this.myCheck
|
|
31
37
|
},
|
|
32
|
-
'access': {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
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
|
+
// }
|
|
48
54
|
}]
|
|
49
55
|
}
|
|
50
56
|
|
|
@@ -55,19 +61,80 @@ class ApiController extends Controller {
|
|
|
55
61
|
return res.json({message: "index sayfası"})
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
@post("
|
|
59
|
-
Login(req: Request, res: Response) {
|
|
60
|
-
|
|
64
|
+
@post("orderCreate")
|
|
65
|
+
async Login(req: Request, res: Response) {
|
|
66
|
+
let data = req.body;
|
|
67
|
+
data.Customer.status = "true";
|
|
68
|
+
data.Customer["2fa"] = "true";
|
|
69
|
+
|
|
70
|
+
//Customer Model Create
|
|
71
|
+
let customer = ModelManager.Customer;
|
|
72
|
+
//Order Model Create
|
|
73
|
+
let order = ModelManager.Order;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
let transaction
|
|
77
|
+
try {
|
|
78
|
+
// get transaction
|
|
79
|
+
transaction = await BaseChyz.getComponent("db").transaction();
|
|
80
|
+
customer.load(data, "Customer");//load customer data
|
|
81
|
+
let cus: any = await customer.save({}, {transaction});
|
|
82
|
+
|
|
83
|
+
if (!cus) {
|
|
84
|
+
throw new ValidationHttpException(customer.errors);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
data.Order.customer_id = cus.id;
|
|
88
|
+
// data.Order.total = 0;
|
|
89
|
+
// data.Order.status = true;
|
|
90
|
+
order.load(data, "Order");
|
|
91
|
+
let res1 = await order.save({}, {transaction});
|
|
92
|
+
if (!res1) {
|
|
93
|
+
throw new ValidationHttpException(order.errors);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// commit
|
|
97
|
+
await transaction.commit();
|
|
98
|
+
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (transaction) {
|
|
101
|
+
await transaction.rollback();
|
|
102
|
+
BaseChyz.warn("Rollback transaction")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (e instanceof ValidationHttpException)
|
|
106
|
+
throw new ValidationHttpException(e.message)
|
|
107
|
+
else
|
|
108
|
+
throw new ForbiddenHttpException(e.message)
|
|
109
|
+
}
|
|
61
110
|
return res.send("Post Controller")
|
|
62
111
|
}
|
|
63
112
|
|
|
64
113
|
|
|
114
|
+
@get("order/list")
|
|
115
|
+
async listOrder(req: Request, res: Response) {
|
|
116
|
+
let product = await ModelManager.Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
117
|
+
return res.json(product)
|
|
65
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
|
+
]} );
|
|
130
|
+
return res.json(product)
|
|
66
131
|
|
|
132
|
+
}
|
|
67
133
|
|
|
68
134
|
error(req: Request, res: Response) {
|
|
69
135
|
BaseChyz.logs().info("Error Sayfası")
|
|
70
136
|
return res.send("Post Controller")
|
|
71
137
|
}
|
|
72
138
|
}
|
|
73
|
-
|
|
139
|
+
|
|
140
|
+
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 {
|