chyz 1.0.13-rc.3 → 1.0.13-rc.7

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/dist/README.md DELETED
@@ -1,270 +0,0 @@
1
- Hızlı şekilde microservis hazırlama için geliştirmeye başladım<br>
2
-
3
- Temel olarak yii2 php framework'ten örnekler alındı<br>
4
-
5
- Temel olarak basit bir Controller geliştirildi, ayrıca authentication geliştirildi.<br>
6
-
7
- Klasör Yapısı<br>
8
- *---Controllers <br>
9
- *---Models<br>
10
- *---Log<br>
11
- *---Framework<br>
12
- index.ts<br>
13
-
14
- `##Başlangıç<br>
15
- yarn start
16
-
17
- ## index.ts alanlar düzenlenmeli.
18
-
19
- ```typescript
20
- require('dotenv-flow').config();
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";
26
-
27
- let config = {
28
- components: {
29
- db: {
30
- class: DbConnection,
31
- database: process.env.DBDATABASE,
32
- username: process.env.DBUSER,
33
- password: process.env.DBPASS,
34
- options: {
35
- host: process.env.DBHOST,
36
- dialect: 'postgres', /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
37
- // disable logging; default: console.log
38
- logging: false
39
- }
40
- },
41
- user: {
42
- 'class': WebUser,
43
- 'identityClass': User
44
- }
45
- }
46
- }
47
- Chyz.app(config).Start();
48
- ```
49
-
50
- ## Create Model
51
-
52
- Veritabanı işlemleri için model oluşturma, sequelize desteklidir.
53
-
54
- ```typescript
55
- import {Model, DataTypes} from "chyz/base/Model";
56
-
57
- export class CustomerCLass extends Model {
58
- public tableName() {
59
- return 'customer';
60
- }
61
-
62
- public attributes() {
63
- return {
64
- username: {
65
- type: DataTypes.STRING,
66
- allowNull: false,
67
- validate: {
68
- notEmpty: true,
69
- len: [4, 255],
70
- }
71
- },
72
- email: {
73
- type: DataTypes.STRING,
74
- validate: {
75
- isEmail: true
76
- }
77
- },
78
- firstname: {
79
- type: DataTypes.STRING,
80
- allowNull: false
81
- },
82
- lastname: {
83
- type: DataTypes.STRING,
84
- },
85
- }
86
- }
87
-
88
- }
89
- const Customer= new CustomerCLass();
90
- export { Customer };
91
-
92
- ```
93
- ````typescript
94
- export class ProductsClass extends Model {
95
- [x: string]: any;
96
-
97
- tableName() {
98
- return 'products';
99
- }
100
-
101
- attributes() {
102
- return {
103
- // Model attributes are defined here
104
- title: {
105
- type: DataTypes.STRING,
106
- allowNull: false
107
- },
108
- model_id: {
109
- type: DataTypes.INTEGER,
110
- allowNull: false
111
- },
112
- properties: {
113
- type: DataTypes.STRING,
114
- allowNull: false
115
- }
116
-
117
- }
118
- }
119
-
120
- relations(): Relation[] {
121
- return [
122
- {
123
- type: "hasOne",
124
- foreignKey: "id",
125
- sourceKey: "customer_id",
126
- model: Customer.model()
127
- }
128
- ]
129
- }
130
- }
131
-
132
- const Products = new ProductsClass()
133
- export {Products}
134
- ````
135
-
136
- ## Http POST ve GET verilerini model'e yükleme
137
-
138
- ````typescript
139
-
140
- /**
141
- * post data
142
- * {
143
- * "Customer":{
144
- * "firstname":"cihan",
145
- * "lastname":"ozturk"
146
- * ....
147
- * }
148
- * }
149
- * @type {Customer}
150
- */
151
- import {Customer} from "./Customer";
152
- //Customer Model Create
153
- let customer: Customer = Customer;
154
- customer.load(req.body, "Customer");//load customer data
155
- let cus: any = await customer.save();
156
-
157
-
158
- ````
159
- ## Transaction
160
- Transaction oluşturma
161
-
162
-
163
- ```typescript
164
- let transaction
165
- try {
166
- // get transaction
167
- transaction = await BaseChyz.getComponent("db").transaction();
168
- //Customer Model Create
169
- let customer: Customer = new Customer();
170
- customer.load(data, "Customer");//load customer data
171
- let cus: any = await customer.save({}, {transaction});
172
- if (!cus) {
173
- throw new ValidationHttpException(customer.errors);
174
- }
175
- } catch (e) {
176
- if (transaction) {
177
- await transaction.rollback();
178
- BaseChyz.warn("Rollback transaction")
179
- }
180
- ...
181
- }
182
- ```
183
-
184
- ## Yetkilendirme için kullanıcı modeli
185
-
186
- ```typescript
187
- /*
188
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
189
- * Author: Cihan Ozturk
190
- * E-mail: cihan@chy.com.tr
191
- * Github:https://github.com/cihan53/
192
- */
193
- import {IdentityInterface} from "chyz/web/IdentityInterface";
194
- // @ts-ignore
195
- import {DataTypes} from "chyz/base";
196
- import {Model} from "chyz/base";
197
- import BaseChyz from "chyz/BaseChyz";
198
-
199
- const bcrypt = require('bcrypt');
200
- const JsonWebToken = require("jsonwebtoken");
201
-
202
- export class User extends Model implements IdentityInterface {
203
- public tableName() {
204
- return 'users';
205
- }
206
- findIdentity(id: number) {
207
- throw new Error("Method not implemented.");
208
- }
209
-
210
- getId(): number {
211
- throw new Error("Method not implemented.");
212
- }
213
-
214
- getAuthKey(): string {
215
- throw new Error("Method not implemented.");
216
- }
217
-
218
- validateAuthKey(authKey: string): boolean {
219
- throw new Error("Method not implemented.");
220
- }
221
-
222
- public attributes() {
223
- return {
224
- // Model attributes are defined here
225
- username: {
226
- type: DataTypes.STRING,
227
- allowNull: false
228
- },
229
- password: {
230
- type: DataTypes.STRING,
231
- allowNull: false
232
- },
233
- user_role: {
234
- type: DataTypes.STRING,
235
- allowNull: false
236
- },
237
- salt_text: {
238
- type: DataTypes.STRING
239
- // allowNull defaults to true
240
- }
241
- }
242
- }
243
-
244
- async findIdentityByAccessToken(token, type) {
245
- let decoded = JsonWebToken.decode(token, {complete: true})
246
- let identity = await this.findOne({where: {id: parseInt(decoded.payload.user)}});
247
- if(identity){
248
- BaseChyz.debug("Find Identity By AccessToken: User Found", decoded.payload)
249
- try {
250
- JsonWebToken.verify(token, identity.salt_text);
251
- BaseChyz.debug("Find Identity By AccessToken: User Verify Success")
252
- return identity;
253
- } catch(err) {
254
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
255
- return null;
256
- }
257
- }
258
- BaseChyz.debug("Find Identity By AccessToken: User Verify Failed")
259
- return null;
260
- }
261
-
262
-
263
- }
264
-
265
-
266
-
267
-
268
-
269
-
270
- ```