chyz 1.0.12-rc.14

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.
Files changed (163) hide show
  1. package/BaseChyz.ts +316 -0
  2. package/Chyz.ts +11 -0
  3. package/Examples/Controllers/ApiController.ts +121 -0
  4. package/Examples/Controllers/PublicController.ts +44 -0
  5. package/Examples/Controllers/SiteController.ts +127 -0
  6. package/Examples/Models/Customer.ts +113 -0
  7. package/Examples/Models/Order.ts +48 -0
  8. package/Examples/Models/OrderItem.ts +26 -0
  9. package/Examples/Models/User.ts +80 -0
  10. package/Examples/index.ts +38 -0
  11. package/Examples/log/access.log +0 -0
  12. package/Examples/log/app.log +3264 -0
  13. package/Examples/log/errors.log +534 -0
  14. package/Examples/package.json +45 -0
  15. package/Examples/tsconfig.json +20 -0
  16. package/Examples/yarn.lock +2202 -0
  17. package/README.md +218 -0
  18. package/base/ActionFilter.ts +71 -0
  19. package/base/BaseError.ts +26 -0
  20. package/base/BaseObject.ts +19 -0
  21. package/base/Behavior.ts +6 -0
  22. package/base/Component.ts +66 -0
  23. package/base/Configurable.ts +10 -0
  24. package/base/Controller.ts +84 -0
  25. package/base/DataErrorDbException.ts +16 -0
  26. package/base/DbConnection.ts +51 -0
  27. package/base/ForbiddenHttpException.ts +15 -0
  28. package/base/InvalidConfigException.ts +16 -0
  29. package/base/Model.ts +254 -0
  30. package/base/NotFoundHttpException.ts +14 -0
  31. package/base/RestClient.ts +27 -0
  32. package/base/UnauthorizedHttpException.ts +16 -0
  33. package/base/ValidationHttpException.ts +14 -0
  34. package/base/db/Exception.ts +14 -0
  35. package/base/index.ts +16 -0
  36. package/decorator/Middleware.ts +9 -0
  37. package/decorator/controller.ts +22 -0
  38. package/decorator/enums/ControllerDecoratorParams.ts +5 -0
  39. package/decorator/get.ts +37 -0
  40. package/decorator/index.ts +3 -0
  41. package/decorator/post.ts +36 -0
  42. package/dist/BaseChyz.js +257 -0
  43. package/dist/BaseChyz.js.map +1 -0
  44. package/dist/Chyz.js +15 -0
  45. package/dist/Chyz.js.map +1 -0
  46. package/dist/base/ActionFilter.js +75 -0
  47. package/dist/base/ActionFilter.js.map +1 -0
  48. package/dist/base/BaseError.js +26 -0
  49. package/dist/base/BaseError.js.map +1 -0
  50. package/dist/base/BaseObject.js +20 -0
  51. package/dist/base/BaseObject.js.map +1 -0
  52. package/dist/base/Behavior.js +8 -0
  53. package/dist/base/Behavior.js.map +1 -0
  54. package/dist/base/Component.js +61 -0
  55. package/dist/base/Component.js.map +1 -0
  56. package/dist/base/Configurable.js +9 -0
  57. package/dist/base/Configurable.js.map +1 -0
  58. package/dist/base/Controller.js +75 -0
  59. package/dist/base/Controller.js.map +1 -0
  60. package/dist/base/DataErrorDbException.js +18 -0
  61. package/dist/base/DataErrorDbException.js.map +1 -0
  62. package/dist/base/DbConnection.js +53 -0
  63. package/dist/base/DbConnection.js.map +1 -0
  64. package/dist/base/ForbiddenHttpException.js +17 -0
  65. package/dist/base/ForbiddenHttpException.js.map +1 -0
  66. package/dist/base/InvalidConfigException.js +18 -0
  67. package/dist/base/InvalidConfigException.js.map +1 -0
  68. package/dist/base/Model.js +243 -0
  69. package/dist/base/Model.js.map +1 -0
  70. package/dist/base/NotFoundHttpException.js +18 -0
  71. package/dist/base/NotFoundHttpException.js.map +1 -0
  72. package/dist/base/RestClient.js +26 -0
  73. package/dist/base/RestClient.js.map +1 -0
  74. package/dist/base/UnauthorizedHttpException.js +18 -0
  75. package/dist/base/UnauthorizedHttpException.js.map +1 -0
  76. package/dist/base/ValidationHttpException.js +18 -0
  77. package/dist/base/ValidationHttpException.js.map +1 -0
  78. package/dist/base/db/Exception.js +16 -0
  79. package/dist/base/db/Exception.js.map +1 -0
  80. package/dist/base/index.js +29 -0
  81. package/dist/base/index.js.map +1 -0
  82. package/dist/decorator/Middleware.js +12 -0
  83. package/dist/decorator/Middleware.js.map +1 -0
  84. package/dist/decorator/controller.js +25 -0
  85. package/dist/decorator/controller.js.map +1 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.js +10 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js.map +1 -0
  88. package/dist/decorator/get.js +37 -0
  89. package/dist/decorator/get.js.map +1 -0
  90. package/dist/decorator/index.js +16 -0
  91. package/dist/decorator/index.js.map +1 -0
  92. package/dist/decorator/post.js +37 -0
  93. package/dist/decorator/post.js.map +1 -0
  94. package/dist/filters/AccessControl.js +76 -0
  95. package/dist/filters/AccessControl.js.map +1 -0
  96. package/dist/filters/AccessRule.js +79 -0
  97. package/dist/filters/AccessRule.js.map +1 -0
  98. package/dist/filters/auth/AuthInterface.js +3 -0
  99. package/dist/filters/auth/AuthInterface.js.map +1 -0
  100. package/dist/filters/auth/AuthMethod.js +71 -0
  101. package/dist/filters/auth/AuthMethod.js.map +1 -0
  102. package/dist/filters/auth/HttpBasicAuth.js +8 -0
  103. package/dist/filters/auth/HttpBasicAuth.js.map +1 -0
  104. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  105. package/dist/filters/auth/HttpBearerAuth.js.map +1 -0
  106. package/dist/filters/auth/HttpHeaderAuth.js +61 -0
  107. package/dist/filters/auth/HttpHeaderAuth.js.map +1 -0
  108. package/dist/filters/auth/JwtHttpBearerAuth.js +82 -0
  109. package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  110. package/dist/filters/auth/index.js +16 -0
  111. package/dist/filters/auth/index.js.map +1 -0
  112. package/dist/filters/index.js +15 -0
  113. package/dist/filters/index.js.map +1 -0
  114. package/dist/index.js +28 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/log/config/log4js.json +55 -0
  117. package/dist/model/RouteDefinition.js +9 -0
  118. package/dist/model/RouteDefinition.js.map +1 -0
  119. package/dist/requiments/Glob.js +11 -0
  120. package/dist/requiments/Glob.js.map +1 -0
  121. package/dist/requiments/ReflectUtil.js +25 -0
  122. package/dist/requiments/ReflectUtil.js.map +1 -0
  123. package/dist/requiments/Utils.js +40 -0
  124. package/dist/requiments/Utils.js.map +1 -0
  125. package/dist/validators/BooleanValidator.js +2 -0
  126. package/dist/validators/BooleanValidator.js.map +1 -0
  127. package/dist/validators/CompareValidator.js +2 -0
  128. package/dist/validators/CompareValidator.js.map +1 -0
  129. package/dist/validators/DateValidator.js +2 -0
  130. package/dist/validators/DateValidator.js.map +1 -0
  131. package/dist/validators/EmailValidator.js +2 -0
  132. package/dist/validators/EmailValidator.js.map +1 -0
  133. package/dist/validators/Validator.js +28 -0
  134. package/dist/validators/Validator.js.map +1 -0
  135. package/dist/web/IdentityInterface.js +9 -0
  136. package/dist/web/IdentityInterface.js.map +1 -0
  137. package/dist/web/User.js +83 -0
  138. package/dist/web/User.js.map +1 -0
  139. package/filters/AccessControl.ts +64 -0
  140. package/filters/AccessRule.ts +137 -0
  141. package/filters/auth/AuthInterface.ts +34 -0
  142. package/filters/auth/AuthMethod.ts +88 -0
  143. package/filters/auth/HttpBasicAuth.ts +7 -0
  144. package/filters/auth/HttpBearerAuth.ts +31 -0
  145. package/filters/auth/HttpHeaderAuth.ts +53 -0
  146. package/filters/auth/JwtHttpBearerAuth.ts +81 -0
  147. package/filters/auth/index.ts +3 -0
  148. package/filters/index.ts +2 -0
  149. package/index.ts +14 -0
  150. package/log/config/log4js.json +55 -0
  151. package/model/RouteDefinition.ts +18 -0
  152. package/package.json +52 -0
  153. package/requiments/Glob.ts +9 -0
  154. package/requiments/ReflectUtil.ts +26 -0
  155. package/requiments/Utils.ts +57 -0
  156. package/tsconfig.json +18 -0
  157. package/validators/BooleanValidator.ts +0 -0
  158. package/validators/CompareValidator.ts +0 -0
  159. package/validators/DateValidator.ts +0 -0
  160. package/validators/EmailValidator.ts +0 -0
  161. package/validators/Validator.ts +27 -0
  162. package/web/IdentityInterface.ts +62 -0
  163. package/web/User.ts +96 -0
package/base/Model.ts ADDED
@@ -0,0 +1,254 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import BaseChyz from "../BaseChyz";
9
+ import Utils from "../requiments/Utils";
10
+ import {Component} from "./Component";
11
+ import {InvalidConfigException} from "./InvalidConfigException";
12
+ import Sequelize, {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
13
+ import {Exception} from "./db/Exception";
14
+
15
+ export {DataTypes,NOW} from "sequelize";
16
+
17
+ /**
18
+ * ValidateMe.init({
19
+ bar: {
20
+ type: Sequelize.STRING,
21
+ validate: {
22
+ is: ["^[a-z]+$",'i'], // will only allow letters
23
+ is: /^[a-z]+$/i, // same as the previous example using real RegExp
24
+ not: ["[a-z]",'i'], // will not allow letters
25
+ isEmail: true, // checks for email format (foo@bar.com)
26
+ isUrl: true, // checks for url format (http://foo.com)
27
+ isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
28
+ isIPv4: true, // checks for IPv4 (129.89.23.1)
29
+ isIPv6: true, // checks for IPv6 format
30
+ isAlpha: true, // will only allow letters
31
+ isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
32
+ isNumeric: true, // will only allow numbers
33
+ isInt: true, // checks for valid integers
34
+ isFloat: true, // checks for valid floating point numbers
35
+ isDecimal: true, // checks for any numbers
36
+ isLowercase: true, // checks for lowercase
37
+ isUppercase: true, // checks for uppercase
38
+ notNull: true, // won't allow null
39
+ isNull: true, // only allows null
40
+ notEmpty: true, // don't allow empty strings
41
+ equals: 'specific value', // only allow a specific value
42
+ contains: 'foo', // force specific substrings
43
+ notIn: [['foo', 'bar']], // check the value is not one of these
44
+ isIn: [['foo', 'bar']], // check the value is one of these
45
+ notContains: 'bar', // don't allow specific substrings
46
+ len: [2,10], // only allow values with length between 2 and 10
47
+ isUUID: 4, // only allow uuids
48
+ isDate: true, // only allow date strings
49
+ isAfter: "2011-11-05", // only allow date strings after a specific date
50
+ isBefore: "2011-11-05", // only allow date strings before a specific date
51
+ max: 23, // only allow values <= 23
52
+ min: 23, // only allow values >= 23
53
+ isCreditCard: true, // check for valid credit card numbers
54
+
55
+ // Examples of custom validators:
56
+ isEven(value) {
57
+ if (parseInt(value) % 2 !== 0) {
58
+ throw new Error('Only even values are allowed!');
59
+ }
60
+ }
61
+ isGreaterThanOtherField(value) {
62
+ if (parseInt(value) <= parseInt(this.otherField)) {
63
+ throw new Error('Bar must be greater than otherField.');
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }, { sequelize });
69
+ */
70
+
71
+ export class Model extends Component {
72
+ private sequelize: any
73
+ private _tableName: string;
74
+ private _model: any;
75
+ private _attributes: any = {};
76
+ private _errors: any = {}
77
+
78
+ constructor() {
79
+ super();
80
+ this._tableName = this.constructor.name;
81
+ this.sequelize = BaseChyz.getComponent("db").db;
82
+
83
+ if (!Utils.isEmpty(this.attributes())) {
84
+
85
+ this._model = this.sequelize.define(this.constructor.name, this.attributes(), {
86
+ tableName: this.tableName(),
87
+ timestamps: false
88
+ });
89
+
90
+ } else {
91
+ throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
92
+ }
93
+
94
+ this.init();
95
+
96
+ }
97
+
98
+
99
+ get errors(): any {
100
+ return this._errors;
101
+ }
102
+
103
+ set errors(value: any) {
104
+ this._errors = value;
105
+ }
106
+
107
+ public init() {
108
+ BaseChyz.debug("Model init....", this.constructor.name)
109
+ }
110
+
111
+ public tableName() {
112
+ return this._tableName;
113
+ }
114
+
115
+ public formName() {
116
+ return this.constructor.name;
117
+ }
118
+
119
+ public rules() {
120
+ return []
121
+ }
122
+
123
+ public model() {
124
+ return this._model;
125
+ }
126
+
127
+ public async save(params = {}, options = {}) {
128
+ // now instantiate an object
129
+ let p = Object.assign(params, this._attributes)
130
+ let result: any;
131
+ try {
132
+ result = await this.model().create(p, options)
133
+ } catch (e) {
134
+ BaseChyz.debug(`Model[${this.constructor.name}].create`,e)
135
+ if (e instanceof ValidationError) {
136
+ let validationErrorItems = e.errors;
137
+ validationErrorItems.forEach(({message, path}) => {
138
+ // @ts-ignore
139
+ this._errors[path] = message
140
+ })
141
+
142
+ return false;
143
+ } else if (e instanceof DatabaseError) {
144
+
145
+ } else if (e instanceof TimeoutError) {
146
+
147
+ } else if (e instanceof UniqueConstraintError) {
148
+
149
+ } else if (e instanceof ForeignKeyConstraintError) {
150
+
151
+ } else if (e instanceof ExclusionConstraintError) {
152
+
153
+ }
154
+ throw new Exception(e.message,this.errors,e.code);
155
+ }
156
+
157
+ return result;
158
+
159
+ }
160
+ public async bulkCreate(params = {}, options = {}) {
161
+ // now instantiate an object
162
+ let p = Object.assign(params, this._attributes)
163
+ let result: any;
164
+ try {
165
+ result = await this.model().bulkCreate(p, options)
166
+ } catch (e) {
167
+ BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`,e)
168
+ if (e instanceof ValidationError) {
169
+ let validationErrorItems = e.errors;
170
+ validationErrorItems.forEach(({message, path}) => {
171
+ // @ts-ignore
172
+ this._errors[path] = message
173
+ })
174
+
175
+ return false;
176
+ } else if (e instanceof DatabaseError) {
177
+
178
+ } else if (e instanceof TimeoutError) {
179
+
180
+ } else if (e instanceof UniqueConstraintError) {
181
+
182
+ } else if (e instanceof ForeignKeyConstraintError) {
183
+
184
+ } else if (e instanceof ExclusionConstraintError) {
185
+
186
+ }
187
+ throw new Exception(e.message,this.errors,e.code);
188
+ }
189
+
190
+ return result;
191
+
192
+ }
193
+
194
+ public update(params = {}, options = {}) {
195
+ let p = Object.assign(params, this._attributes)
196
+ return this.model().update(p, options)
197
+ }
198
+
199
+ public delete(params = {}, options = {}) {
200
+ let p = Object.assign(params, this._attributes)
201
+ return this.model().delete(p, options)
202
+ }
203
+
204
+
205
+ public findOne(...args: any[]) {
206
+ return this._model.findOne(...arguments)
207
+ }
208
+
209
+
210
+ public validate() {
211
+
212
+ }
213
+
214
+ public load(data: any, formName: any = null) {
215
+ let scope = formName === null ? this.formName() : formName;
216
+ if (scope === '' && !Utils.isEmpty(data)) {
217
+ this.setAttribute(data);
218
+ return true;
219
+ } else if (data[scope]) {
220
+ this.setAttribute(data[scope]);
221
+ return true;
222
+ }
223
+ return false;
224
+ }
225
+
226
+ public bulkLoad(data: any, formName: any = null) {
227
+ let scope = formName === null ? this.formName() : formName;
228
+ if (scope === '' && !Utils.isEmpty(data)) {
229
+ this.setAttribute(data);
230
+ return true;
231
+ } else if (data[scope]) {
232
+ this.setAttribute(data[scope]);
233
+ return true;
234
+ }
235
+ return false;
236
+ }
237
+
238
+ public setAttribute(values: any, safeOnly = true) {
239
+ if (values instanceof Object) {
240
+ let attributes = this.attributes();
241
+ for (const valueKey in values) {
242
+ if (Object.keys(attributes).indexOf(valueKey) != -1) {
243
+ // @ts-ignore
244
+ BaseChyz.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey])
245
+ this._attributes[valueKey] = values[valueKey];
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ public attributes() {
252
+ return {}
253
+ }
254
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+
10
+ export class NotFoundHttpException extends BaseError {
11
+ constructor ( public message: string) {
12
+ super(message);
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 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
+
11
+ import {Component} from "./Component";
12
+
13
+ const axios = require('axios')
14
+
15
+ export class RestClient extends Component {
16
+ public post(url: string, args: any[]) {
17
+ return axios.post(url, args)
18
+ }
19
+
20
+ public get(url: string, args: any[]) {
21
+ return axios.post(url, args)
22
+ }
23
+
24
+ public Rest(params: any) {
25
+ return axios(params)
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+
10
+ export class UnauthorizedHttpException extends BaseError {
11
+ constructor ( public message: string) {
12
+ super(message);
13
+ }
14
+ }
15
+
16
+
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ import {BaseError} from "./BaseError";
9
+
10
+ export class ValidationHttpException extends BaseError {
11
+ constructor ( public message: string) {
12
+ super(message);
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import {BaseError} from "../BaseError";
2
+
3
+ export class Exception extends BaseError {
4
+ public errorInfo = [];
5
+ private code: string;
6
+
7
+ constructor(message: string, errorInfo:any = [], code = '', previous = null) {
8
+ super(message);
9
+ this.errorInfo = errorInfo;
10
+ this.name = 'Database Exception' // good practice
11
+ this.code = code // error code for responding to client
12
+ Error.captureStackTrace(this)
13
+ }
14
+ }
package/base/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ export * from "./ActionFilter"
2
+ export * from "./BaseObject"
3
+ export * from "./BaseError"
4
+ export * from "./Behavior"
5
+ export * from "./Component"
6
+ export * from "./Configurable"
7
+ export * from "./Controller"
8
+ export * from "./DbConnection"
9
+ export * from "./ForbiddenHttpException"
10
+ export * from "./InvalidConfigException"
11
+ export * from "./NotFoundHttpException"
12
+ export * from "./UnauthorizedHttpException"
13
+ export * from "./DataErrorDbException"
14
+ export * from "./ValidationHttpException"
15
+ export * from "./Model"
16
+ export * from "./RestClient"
@@ -0,0 +1,9 @@
1
+ import "reflect-metadata";
2
+ import { ControllerDecoratorParams } from "./enums/ControllerDecoratorParams";
3
+ import { RequestHandler } from "express";
4
+
5
+ export function Middleware(middlewares: RequestHandler[]): Function {
6
+ return function(target: any, propertyKey: string): void {
7
+ Reflect.defineMetadata(ControllerDecoratorParams.Middleware, middlewares, target, propertyKey);
8
+ }
9
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+
8
+ // @ts-ignore
9
+ import "reflect-metadata";
10
+ export const controller = (prefix: string = ''): ClassDecorator => {
11
+ return (target: any) => {
12
+ // @ts-ignore
13
+ Reflect.defineMetadata('prefix', prefix, target);
14
+
15
+ // Since routes are set by our methods this should almost never be true (except the controller has no methods)
16
+ // @ts-ignore
17
+ if (! Reflect.hasMetadata('routes', target)) {
18
+ // @ts-ignore
19
+ Reflect.defineMetadata('routes', [], target);
20
+ }
21
+ };
22
+ };
@@ -0,0 +1,5 @@
1
+ export enum ControllerDecoratorParams {
2
+ Path = 'path',
3
+ Method = 'method',
4
+ Middleware = 'middleware'
5
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+ import "reflect-metadata";
9
+ import {RouteDefinition} from '../model/RouteDefinition';
10
+
11
+ export const get = (path: string): MethodDecorator => {
12
+ // `target` equals our class, `propertyKey` equals our decorated method name
13
+ // @ts-ignore
14
+ return (target, propertyKey: string): void => {
15
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
16
+ // To prevent any further validation simply set it to an empty array here.
17
+ // @ts-ignore
18
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
19
+ // @ts-ignore
20
+ Reflect.defineMetadata('routes', [], target.constructor);
21
+ }
22
+
23
+ // Get the routes stored so far, extend it by the new route and re-set the metadata.
24
+ // @ts-ignore
25
+ const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
26
+
27
+ routes.push({
28
+ id:"",
29
+ requestMethod: 'get',
30
+ path,
31
+ methodName: propertyKey
32
+ });
33
+
34
+ // @ts-ignore
35
+ Reflect.defineMetadata('routes', routes, target.constructor);
36
+ };
37
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./controller"
2
+ export * from "./get"
3
+ export * from "./post"
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
+ * Author: Cihan Ozturk
4
+ * E-mail: cihan@chy.com.tr
5
+ * Github:https://github.com/cihan53/
6
+ */
7
+ // @ts-ignore
8
+ import "reflect-metadata";
9
+ import {RouteDefinition} from '../model/RouteDefinition';
10
+
11
+ export const post = (path: string): MethodDecorator => {
12
+ // `target` equals our class, `propertyKey` equals our decorated method name
13
+ // @ts-ignore
14
+ return (target, propertyKey: string): void => {
15
+ // In case this is the first route to be registered the `routes` metadata is likely to be undefined at this point.
16
+ // To prevent any further validation simply set it to an empty array here.
17
+ // @ts-ignore
18
+ if (!Reflect.hasMetadata('routes', target.constructor)) {
19
+ // @ts-ignore
20
+ Reflect.defineMetadata('routes', [], target.constructor);
21
+ }
22
+
23
+ // Get the routes stored so far, extend it by the new route and re-set the metadata.
24
+ // @ts-ignore
25
+ const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
26
+
27
+ routes.push({
28
+ id:"",
29
+ requestMethod: 'post',
30
+ path,
31
+ methodName: propertyKey
32
+ });
33
+ // @ts-ignore
34
+ Reflect.defineMetadata('routes', routes, target.constructor);
35
+ };
36
+ };