chyz 1.0.13-rc.20 → 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 +8 -18
- 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 +16 -267
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +1 -3
- package/base/Model.ts +51 -69
- package/base/RestClient.ts +4 -4
- package/base/ValidationHttpException.ts +1 -1
- 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 -44
- 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/ValidationHttpException.js +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 -6
- 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 -6
- package/web/IdentityInterface.ts +0 -6
- package/web/WebUser.ts +1 -88
- package/Doc/Moel kullanma.md +0 -13
- 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/Examples/tsconfig.json
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
"target": "ES6",
|
|
4
4
|
"experimentalDecorators": true,
|
|
5
5
|
"emitDecoratorMetadata": true,
|
|
6
|
-
// "isolatedModules": true,
|
|
7
6
|
"removeComments": true,
|
|
8
|
-
|
|
7
|
+
"esModuleInterop": true,
|
|
9
8
|
"allowSyntheticDefaultImports": true,
|
|
10
9
|
"moduleResolution": "node"
|
|
11
10
|
},
|
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Klasör Yapısı<br>
|
|
|
8
8
|
*---Controllers <br>
|
|
9
9
|
*---Models<br>
|
|
10
10
|
*---Log<br>
|
|
11
|
+
*---Framework<br>
|
|
11
12
|
index.ts<br>
|
|
12
13
|
|
|
13
14
|
`##Başlangıç<br>
|
|
@@ -16,23 +17,15 @@ yarn start
|
|
|
16
17
|
## index.ts alanlar düzenlenmeli.
|
|
17
18
|
|
|
18
19
|
```typescript
|
|
19
|
-
|
|
20
|
-
import {BaseChyz} from "../index";
|
|
21
|
-
|
|
22
20
|
require('dotenv-flow').config();
|
|
23
|
-
import Chyz ,{ DbConnection, BaseChyz} from "chyz/dist/";
|
|
24
|
-
import {AuthManager} from "chyz/dist/rbac/AuthManager"
|
|
25
|
-
import {WebUser} from "chyz/dist/web/WebUser";
|
|
26
|
-
import {User as Identity} from "./Models/User";
|
|
27
21
|
|
|
22
|
+
import BaseChyz from "chyz/dist/BaseChyz";
|
|
23
|
+
import Chyz, {DbConnection} from "chyz/dist";
|
|
24
|
+
import {WebUser} from "../web/WebUser";
|
|
25
|
+
import {User} from "./Models/User";
|
|
28
26
|
|
|
29
27
|
let config = {
|
|
30
|
-
port: process.env.PORT || 8870,
|
|
31
|
-
controllerpath: "Examples\\Controllers",
|
|
32
28
|
components: {
|
|
33
|
-
authManager: {
|
|
34
|
-
class: AuthManager,
|
|
35
|
-
},
|
|
36
29
|
db: {
|
|
37
30
|
class: DbConnection,
|
|
38
31
|
database: process.env.DBDATABASE,
|
|
@@ -42,7 +35,7 @@ let config = {
|
|
|
42
35
|
host: process.env.DBHOST,
|
|
43
36
|
dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
|
|
44
37
|
// disable logging; default: console.log
|
|
45
|
-
logging:
|
|
38
|
+
logging: false
|
|
46
39
|
}
|
|
47
40
|
},
|
|
48
41
|
user: {
|
|
@@ -50,168 +43,14 @@ let config = {
|
|
|
50
43
|
'identityClass': User
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
}
|
|
55
47
|
Chyz.app(config).Start();
|
|
56
48
|
```
|
|
57
49
|
|
|
58
|
-
##Controller
|
|
59
|
-
Basit şekilde kontroller oluşturulabilir.
|
|
60
|
-
```typescript
|
|
61
|
-
/*
|
|
62
|
-
*
|
|
63
|
-
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
64
|
-
* Author: Cihan Ozturk
|
|
65
|
-
* E-mail: cihan@chy.com.tr
|
|
66
|
-
* Github:https://github.com/cihan53/
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
import {AccessControl, BaseChyz, JwtHttpBearerAuth, ModelManager, Request, Response,} from "chyz/dist";
|
|
71
|
-
import {ForbiddenHttpException, Model, NotFoundHttpException, ValidationHttpException} from "chyz/dist/base";
|
|
72
|
-
|
|
73
|
-
import Utils from 'chyz/dist/requiments/Utils';
|
|
74
|
-
import {controller, get, post} from "chyz/dist/decorator";
|
|
75
|
-
import {Controller} from "chyz/dist/base/Controller";
|
|
76
|
-
import * as Util from "util";
|
|
77
|
-
import {uid} from "uid";
|
|
78
|
-
|
|
79
|
-
import {User} from "../Models/User";
|
|
80
|
-
import {AuthManager} from "../Lib/AuthManager";
|
|
81
|
-
import {CategoriesClass} from "../Models/Categories";
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const keygen = require('ssh-keygen');
|
|
85
|
-
const os = require('os');
|
|
86
|
-
const bcrypt = require('bcrypt');
|
|
87
|
-
const JsonWebToken = require("jsonwebtoken");
|
|
88
|
-
const {Op} = require("sequelize");
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@controller("/api")
|
|
92
|
-
class ApiController extends Controller {
|
|
93
|
-
|
|
94
|
-
public myCheck(token) {
|
|
95
|
-
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public behaviors(): any[] {
|
|
99
|
-
|
|
100
|
-
return [{
|
|
101
|
-
'authenticator': {
|
|
102
|
-
"class": JwtHttpBearerAuth,
|
|
103
|
-
// "auth": this.myCheck
|
|
104
|
-
},
|
|
105
|
-
'access': {
|
|
106
|
-
'class': AccessControl,
|
|
107
|
-
'only': ['order/list' ],
|
|
108
|
-
'rules': [
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
'allow': true,
|
|
112
|
-
'actions': ['order/list' ],
|
|
113
|
-
'roles': ['editor'],
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
}]
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@get("/")
|
|
121
|
-
Index(req: Request, res: Response) {
|
|
122
|
-
|
|
123
|
-
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
124
|
-
return res.json({message: "index sayfası"})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@post("orderCreate")
|
|
128
|
-
async Login(req: Request, res: Response) {
|
|
129
|
-
let data = req.body;
|
|
130
|
-
data.Customer.status = "true";
|
|
131
|
-
|
|
132
|
-
//Customer Model Create
|
|
133
|
-
let customer = ModelManager.Customer.save();
|
|
134
|
-
//Order Model Create
|
|
135
|
-
let order = ModelManager.Order;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let transaction
|
|
139
|
-
try {
|
|
140
|
-
// get transaction
|
|
141
|
-
transaction = await BaseChyz.getComponent("db").transaction();
|
|
142
|
-
customer.load(data, "Customer");//load customer data
|
|
143
|
-
let cus: any = await customer.save({}, {transaction});
|
|
144
|
-
|
|
145
|
-
if (!cus) {
|
|
146
|
-
throw new ValidationHttpException(customer.errors);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
data.Order.customer_id = cus.id;
|
|
150
|
-
|
|
151
|
-
order.load(data, "Order");
|
|
152
|
-
let res1 = await order.save({}, {transaction});
|
|
153
|
-
if (!res1) {
|
|
154
|
-
throw new ValidationHttpException(order.errors);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// commit
|
|
158
|
-
await transaction.commit();
|
|
159
|
-
|
|
160
|
-
} catch (e) {
|
|
161
|
-
if (transaction) {
|
|
162
|
-
await transaction.rollback();
|
|
163
|
-
BaseChyz.warn("Rollback transaction")
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (e instanceof ValidationHttpException)
|
|
167
|
-
throw new ValidationHttpException(e.message)
|
|
168
|
-
else
|
|
169
|
-
throw new ForbiddenHttpException(e.message)
|
|
170
|
-
}
|
|
171
|
-
return res.send("Post Controller")
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
@get("order/list")
|
|
176
|
-
async listOrder(req: Request, res: Response) {
|
|
177
|
-
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
178
|
-
let product = await Products.findAll( );
|
|
179
|
-
return res.json(product)
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@get("categories")
|
|
184
|
-
async Categories(req: Request, res: Response) {
|
|
185
|
-
let product = await ModelManager.Categories.findAll({
|
|
186
|
-
include: [
|
|
187
|
-
{
|
|
188
|
-
model: ModelManager.Products.model(),
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
});
|
|
192
|
-
return res.json(product)
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
error(req: Request, res: Response) {
|
|
197
|
-
BaseChyz.logs().info("Error Sayfası")
|
|
198
|
-
return res.send("Post Controller")
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
module.exports = ApiController
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
|
|
207
50
|
## Create Model
|
|
208
51
|
|
|
209
52
|
Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
|
|
210
53
|
|
|
211
|
-
Model adı "**Class**" şeklinde bitmeli.
|
|
212
|
-
|
|
213
|
-
Örnek = "ModelName**Class**"
|
|
214
|
-
|
|
215
54
|
```typescript
|
|
216
55
|
import {Model, DataTypes} from "chyz/base/Model";
|
|
217
56
|
|
|
@@ -247,11 +86,11 @@ export class CustomerCLass extends Model {
|
|
|
247
86
|
}
|
|
248
87
|
|
|
249
88
|
}
|
|
250
|
-
|
|
89
|
+
const Customer= new CustomerCLass();
|
|
90
|
+
export { Customer };
|
|
251
91
|
|
|
252
92
|
```
|
|
253
93
|
````typescript
|
|
254
|
-
|
|
255
94
|
export class ProductsClass extends Model {
|
|
256
95
|
[x: string]: any;
|
|
257
96
|
|
|
@@ -290,49 +129,8 @@ export class ProductsClass extends Model {
|
|
|
290
129
|
}
|
|
291
130
|
}
|
|
292
131
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
export class CategoriesClass extends Model {
|
|
297
|
-
[x: string]: any;
|
|
298
|
-
|
|
299
|
-
alias() {
|
|
300
|
-
return "c"
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
tableName() {
|
|
304
|
-
return 'categories';
|
|
305
|
-
}
|
|
306
|
-
attributes() {
|
|
307
|
-
return {
|
|
308
|
-
// Model attributes are defined here
|
|
309
|
-
title: {
|
|
310
|
-
type: DataTypes.STRING,
|
|
311
|
-
allowNull: false
|
|
312
|
-
},
|
|
313
|
-
properties: {
|
|
314
|
-
type: DataTypes.STRING,
|
|
315
|
-
allowNull: false
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
relations(): Relation[] {
|
|
321
|
-
return [
|
|
322
|
-
{
|
|
323
|
-
type: "belongsToMany",
|
|
324
|
-
foreignKey: "category_id",
|
|
325
|
-
sourceKey: "id",
|
|
326
|
-
as: 'product',
|
|
327
|
-
model: ModelManager.Products.model(),
|
|
328
|
-
through: ModelManager.ProductToCategories.model()
|
|
329
|
-
}
|
|
330
|
-
]
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
132
|
+
const Products = new ProductsClass()
|
|
133
|
+
export {Products}
|
|
336
134
|
````
|
|
337
135
|
|
|
338
136
|
## Http POST ve GET verilerini model'e yükleme
|
|
@@ -350,11 +148,9 @@ export class CategoriesClass extends Model {
|
|
|
350
148
|
* }
|
|
351
149
|
* @type {Customer}
|
|
352
150
|
*/
|
|
353
|
-
import { ModelManager} from "chyz/dist";
|
|
354
151
|
import {Customer} from "./Customer";
|
|
355
|
-
|
|
356
152
|
//Customer Model Create
|
|
357
|
-
let customer: Customer =
|
|
153
|
+
let customer: Customer = Customer;
|
|
358
154
|
customer.load(req.body, "Customer");//load customer data
|
|
359
155
|
let cus: any = await customer.save();
|
|
360
156
|
|
|
@@ -370,7 +166,7 @@ Transaction oluşturma
|
|
|
370
166
|
// get transaction
|
|
371
167
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
372
168
|
//Customer Model Create
|
|
373
|
-
let customer: Customer =
|
|
169
|
+
let customer: Customer = new Customer();
|
|
374
170
|
customer.load(data, "Customer");//load customer data
|
|
375
171
|
let cus: any = await customer.save({}, {transaction});
|
|
376
172
|
if (!cus) {
|
|
@@ -379,9 +175,9 @@ Transaction oluşturma
|
|
|
379
175
|
} catch (e) {
|
|
380
176
|
if (transaction) {
|
|
381
177
|
await transaction.rollback();
|
|
382
|
-
BaseChyz.warn("Rollback transaction")
|
|
178
|
+
BaseChyz.warn("Rollback transaction")
|
|
383
179
|
}
|
|
384
|
-
|
|
180
|
+
...
|
|
385
181
|
}
|
|
386
182
|
```
|
|
387
183
|
|
|
@@ -423,44 +219,6 @@ export class User extends Model implements IdentityInterface {
|
|
|
423
219
|
throw new Error("Method not implemented.");
|
|
424
220
|
}
|
|
425
221
|
|
|
426
|
-
/**
|
|
427
|
-
* Returns auth manager associated with the user component.
|
|
428
|
-
*
|
|
429
|
-
* By default this is the `authManager` application component.
|
|
430
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
431
|
-
*/
|
|
432
|
-
protected getAuthManager() {
|
|
433
|
-
return BaseChyz.getComponent("authManager");
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Returns the access checker used for checking access.
|
|
438
|
-
* @return CheckAccessInterface
|
|
439
|
-
*/
|
|
440
|
-
protected getAccessChecker() {
|
|
441
|
-
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
*
|
|
446
|
-
* @param permissionName
|
|
447
|
-
* @param params
|
|
448
|
-
* @param allowCaching
|
|
449
|
-
*/
|
|
450
|
-
public async can(permissionName, params: any[] = [], allowCaching: boolean = true) {
|
|
451
|
-
let accessChecker;
|
|
452
|
-
if ((accessChecker = this.getAccessChecker()) === null) {
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
let access = await accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
457
|
-
this._access[permissionName] = access;
|
|
458
|
-
if (allowCaching && Utils.isEmpty(params)) {
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
return access;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
222
|
public attributes() {
|
|
465
223
|
return {
|
|
466
224
|
// Model attributes are defined here
|
|
@@ -484,25 +242,16 @@ export class User extends Model implements IdentityInterface {
|
|
|
484
242
|
}
|
|
485
243
|
|
|
486
244
|
async findIdentityByAccessToken(token, type) {
|
|
487
|
-
|
|
488
|
-
|
|
489
245
|
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
490
|
-
if (!decoded.payload.user) {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
246
|
let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
|
|
494
247
|
if(identity){
|
|
495
248
|
BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
|
|
496
249
|
try {
|
|
497
250
|
JsonWebToken.verify(token, identity.salt_text);
|
|
498
|
-
this.setIdentity(identity);
|
|
499
251
|
BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
|
|
500
|
-
return
|
|
252
|
+
return identity;
|
|
501
253
|
} catch(err) {
|
|
502
|
-
|
|
503
|
-
BaseChyz.debug("Find Identity By AccessToken: Token Expired")
|
|
504
|
-
else
|
|
505
|
-
BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
|
|
254
|
+
BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
|
|
506
255
|
return null;
|
|
507
256
|
}
|
|
508
257
|
}
|
package/base/ActionFilter.ts
CHANGED
package/base/BaseError.ts
CHANGED
|
@@ -5,14 +5,12 @@
|
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import Utils from "../requiments/Utils";
|
|
9
|
-
|
|
10
8
|
export class BaseError extends Error {
|
|
11
9
|
private statusCode: number;
|
|
12
10
|
|
|
13
11
|
constructor(message: string,statusCode=500) {
|
|
14
12
|
super(message);
|
|
15
|
-
this.message=
|
|
13
|
+
this.message=message;
|
|
16
14
|
this.name = this.constructor.name // good practice
|
|
17
15
|
this.statusCode = statusCode // error code for responding to client
|
|
18
16
|
Error.captureStackTrace(this)
|
package/base/Model.ts
CHANGED
|
@@ -14,15 +14,15 @@ import {Exception} from "./db/Exception";
|
|
|
14
14
|
|
|
15
15
|
export {DataTypes, NOW} from "sequelize";
|
|
16
16
|
|
|
17
|
-
export interface Relation
|
|
18
|
-
type:
|
|
19
|
-
allowNull?:
|
|
20
|
-
sourceKey
|
|
21
|
-
model:
|
|
22
|
-
foreignKey:
|
|
23
|
-
name?:
|
|
24
|
-
through?:
|
|
25
|
-
as?:
|
|
17
|
+
export interface Relation{
|
|
18
|
+
type: "hasOne" | "hasMany" | "belongsToMany" | "belongsTo",
|
|
19
|
+
allowNull?:boolean,
|
|
20
|
+
sourceKey:string,
|
|
21
|
+
model:SModel,
|
|
22
|
+
foreignKey:string,
|
|
23
|
+
name?:string,
|
|
24
|
+
through?:string,
|
|
25
|
+
as?:string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -80,8 +80,7 @@ export interface Relation {
|
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
82
|
export class Model extends Component {
|
|
83
|
-
_sequelize: any;
|
|
84
|
-
_register: any;
|
|
83
|
+
_sequelize: any ;
|
|
85
84
|
private _tableName: string;
|
|
86
85
|
private _model: any;
|
|
87
86
|
private _attributes: any = {};
|
|
@@ -90,7 +89,7 @@ export class Model extends Component {
|
|
|
90
89
|
|
|
91
90
|
constructor(sequelize?: IDBDatabase) {
|
|
92
91
|
super();
|
|
93
|
-
this._tableName = this.
|
|
92
|
+
this._tableName = this.constructor.name;
|
|
94
93
|
// this._sequelize = BaseChyz.getComponent("db").db;
|
|
95
94
|
if (sequelize != null)
|
|
96
95
|
this._sequelize = sequelize;
|
|
@@ -98,19 +97,50 @@ export class Model extends Component {
|
|
|
98
97
|
this._sequelize = BaseChyz.getComponent("db").db;
|
|
99
98
|
|
|
100
99
|
if (!Utils.isEmpty(this.attributes())) {
|
|
101
|
-
|
|
102
|
-
this._model = this._sequelize.define(this._tableName, this.attributes(), {
|
|
100
|
+
this._model = this._sequelize.define(this.constructor.name, this.attributes(), {
|
|
103
101
|
tableName: this.tableName(),
|
|
104
|
-
timestamps: false
|
|
105
|
-
createdAt: false,
|
|
106
|
-
updateAt: false
|
|
102
|
+
timestamps: false
|
|
107
103
|
});
|
|
108
104
|
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* init buraya
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
for (const relation of this.relations()) {
|
|
112
|
+
let m = relation.model;
|
|
113
|
+
|
|
114
|
+
if(relation.type=="hasOne" ){
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
delete relation.model
|
|
117
|
+
this.model().hasOne(m, relation );
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if(relation.type=="hasMany" ){
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
delete relation.model;
|
|
123
|
+
this.model().hasMany(m, relation );
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if(relation.type=="belongsTo" ){
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
delete relation.model;
|
|
129
|
+
this.model().belongsTo(m, relation );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if(relation.type=="belongsToMany" ){
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
delete relation.model;
|
|
135
|
+
this.model().belongsToMany(m, relation );
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
109
139
|
} else {
|
|
110
140
|
throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
|
|
111
141
|
}
|
|
112
142
|
|
|
113
|
-
|
|
143
|
+
this.init();
|
|
114
144
|
|
|
115
145
|
}
|
|
116
146
|
|
|
@@ -121,7 +151,8 @@ export class Model extends Component {
|
|
|
121
151
|
* You may override this method if you want to use a different database connection.
|
|
122
152
|
* @return Connection the database connection used by this AR class.
|
|
123
153
|
*/
|
|
124
|
-
public static getDb()
|
|
154
|
+
public static getDb()
|
|
155
|
+
{
|
|
125
156
|
return BaseChyz.getComponent("db").db
|
|
126
157
|
}
|
|
127
158
|
|
|
@@ -147,45 +178,9 @@ export class Model extends Component {
|
|
|
147
178
|
|
|
148
179
|
public init() {
|
|
149
180
|
BaseChyz.debug("Model init....", this.constructor.name)
|
|
150
|
-
/**
|
|
151
|
-
* init buraya
|
|
152
|
-
*/
|
|
153
|
-
BaseChyz.debug("Relation init....", this.constructor.name)
|
|
154
|
-
for (const relation of this.relations()) {
|
|
155
|
-
let m = relation.model;
|
|
156
|
-
|
|
157
|
-
if (relation.type == "hasOne") {
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
delete relation.model
|
|
160
|
-
this.model().hasOne(m, relation);
|
|
161
|
-
}
|
|
162
|
-
//
|
|
163
|
-
if (relation.type == "hasMany") {
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
delete relation.model;
|
|
166
|
-
this.model().hasMany(m, relation);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (relation.type == "belongsTo") {
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
delete relation.model;
|
|
172
|
-
this.model().belongsTo(m, relation);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (relation.type == "belongsToMany") {
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
delete relation.model;
|
|
178
|
-
this.model().belongsToMany(m, relation);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
|
|
185
|
-
public alias() {
|
|
186
|
-
return this.constructor.name;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
184
|
public tableName() {
|
|
190
185
|
return this._tableName;
|
|
191
186
|
}
|
|
@@ -296,15 +291,6 @@ export class Model extends Component {
|
|
|
296
291
|
return this._model.findAll(...arguments)
|
|
297
292
|
}
|
|
298
293
|
|
|
299
|
-
/**
|
|
300
|
-
* return {count : number , rows: any}
|
|
301
|
-
* @param args
|
|
302
|
-
*/
|
|
303
|
-
public findAndCountAll(...args: any[]) {
|
|
304
|
-
return this._model.findAndCountAll(...arguments)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
294
|
|
|
309
295
|
public validate() {
|
|
310
296
|
|
|
@@ -362,11 +348,7 @@ export class Model extends Component {
|
|
|
362
348
|
*
|
|
363
349
|
* ]
|
|
364
350
|
*/
|
|
365
|
-
public relations():
|
|
351
|
+
public relations():Relation[]{
|
|
366
352
|
return []
|
|
367
353
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
354
|
}
|
package/base/RestClient.ts
CHANGED
|
@@ -13,12 +13,12 @@ import {Component} from "./Component";
|
|
|
13
13
|
const axios = require('axios')
|
|
14
14
|
|
|
15
15
|
export class RestClient extends Component {
|
|
16
|
-
public post(url: string, args: any[]
|
|
17
|
-
return axios.post(url, args
|
|
16
|
+
public post(url: string, args: any[]) {
|
|
17
|
+
return axios.post(url, args)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public get(url: string, args: any[]
|
|
21
|
-
return axios.post(url, args
|
|
20
|
+
public get(url: string, args: any[]) {
|
|
21
|
+
return axios.post(url, args)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
public Rest(params: any) {
|
package/base/index.ts
CHANGED
|
@@ -8,11 +8,9 @@ export * from "./Controller"
|
|
|
8
8
|
export * from "./DbConnection"
|
|
9
9
|
export * from "./ForbiddenHttpException"
|
|
10
10
|
export * from "./InvalidConfigException"
|
|
11
|
-
export * from "./InvalidArgumentException"
|
|
12
11
|
export * from "./NotFoundHttpException"
|
|
13
12
|
export * from "./UnauthorizedHttpException"
|
|
14
13
|
export * from "./DataErrorDbException"
|
|
15
14
|
export * from "./ValidationHttpException"
|
|
16
15
|
export * from "./Model"
|
|
17
16
|
export * from "./RestClient"
|
|
18
|
-
export * from "./ModelManager"
|