axe-api 1.0.0-rc2 → 1.0.0-rc3

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.
@@ -61,10 +61,12 @@ exports.default = (request, response) => __awaiter(void 0, void 0, void 0, funct
61
61
  }
62
62
  if (error.type === "ApiError") {
63
63
  const apiError = error;
64
- return axeResponse.json({ error: apiError.message }, apiError.status);
64
+ return axeResponse
65
+ .status(apiError.status)
66
+ .json({ error: apiError.message });
65
67
  }
66
68
  // TODO: We need an error handler.
67
- axeResponse.json({ error: error.toString() }, 500);
69
+ axeResponse.status(500).json({ error: error.toString() });
68
70
  break;
69
71
  }
70
72
  // If the response is not created, we should go to the next phase
@@ -86,7 +86,7 @@ export interface IGeneralHooks {
86
86
  }
87
87
  export interface IHandlerBaseMiddleware {
88
88
  handler: HandlerTypes[];
89
- middleware: (context: IRequestPack) => Promise<void>;
89
+ middleware: (context: IRequestPack) => Promise<void> | void;
90
90
  }
91
91
  export interface IMethodBaseConfig {
92
92
  [HttpMethods.POST]?: string[];
@@ -14,7 +14,9 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
14
14
  if (context.query) {
15
15
  context.item = yield context.query.first();
16
16
  if (!context.item) {
17
- context.res.json({ error: `The item is not found on ${context.model.name}.` }, Enums_1.StatusCodes.NOT_FOUND);
17
+ context.res
18
+ .status(Enums_1.StatusCodes.NOT_FOUND)
19
+ .json({ error: `The item is not found on ${context.model.name}.` });
18
20
  }
19
21
  }
20
22
  });
@@ -21,7 +21,11 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  .where(context.model.instance.primaryKey, value);
22
22
  // If there is a deletedAtColumn, it means that this table support soft-delete
23
23
  if (context.model.instance.deletedAtColumn === null) {
24
- return context.res.json({ error: "You can use force delete only soft-delete supported models." }, Enums_1.StatusCodes.NOT_FOUND);
24
+ return context.res
25
+ .status(Enums_1.StatusCodes.NOT_FOUND)
26
+ .json({
27
+ error: "You can use force delete only soft-delete supported models.",
28
+ });
25
29
  }
26
30
  // If there is a relation, we should bind it
27
31
  (0, Helpers_1.addForeignKeyQuery)(context.req, context.query, context.relation, context.parentModel);
@@ -14,7 +14,9 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
14
14
  if (context.query) {
15
15
  context.item = yield context.query.first();
16
16
  if (!context.item) {
17
- context.res.json({ error: `The item is not found on ${context.model.name}.` }, Enums_1.StatusCodes.NOT_FOUND);
17
+ context.res
18
+ .status(Enums_1.StatusCodes.NOT_FOUND)
19
+ .json({ error: `The item is not found on ${context.model.name}.` });
18
20
  }
19
21
  }
20
22
  });
@@ -27,7 +27,7 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  // Validate the data
28
28
  const validation = new validatorjs_1.default(context.formData, validationRules);
29
29
  if (validation.fails()) {
30
- return context.res.json(validation.errors, 400);
30
+ return context.res.status(400).json(validation.errors);
31
31
  }
32
32
  }
33
33
  // We should bind the timestamp values
@@ -17,7 +17,9 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  context.queryParser.applyWheres(context.query, ((_a = context.conditions) === null || _a === void 0 ? void 0 : _a.q) || []);
18
18
  context.item = yield context.query.first();
19
19
  if (!context.item) {
20
- context.res.json({ error: `The item is not found on ${context.model.name}.` }, Enums_1.StatusCodes.NOT_FOUND);
20
+ context.res
21
+ .status(Enums_1.StatusCodes.NOT_FOUND)
22
+ .json({ error: `The item is not found on ${context.model.name}.` });
21
23
  }
22
24
  }
23
25
  });
@@ -21,7 +21,9 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  .where(context.model.instance.primaryKey, value)
22
22
  .first();
23
23
  if (!context.item) {
24
- context.res.json({ error: `The item is not found on ${context.model.name}.` }, Enums_1.StatusCodes.NOT_FOUND);
24
+ context.res
25
+ .status(Enums_1.StatusCodes.NOT_FOUND)
26
+ .json({ error: `The item is not found on ${context.model.name}.` });
25
27
  }
26
28
  }
27
29
  });
@@ -27,7 +27,7 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  // Validate the data
28
28
  const validation = new validatorjs_1.default(context.formData, validationRules);
29
29
  if (validation.fails()) {
30
- context.res.json(validation.errors, 400);
30
+ context.res.status(400).json(validation.errors);
31
31
  return;
32
32
  }
33
33
  }
@@ -27,7 +27,7 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  // Validate the data
28
28
  const validation = new validatorjs_1.default(context.formData, validationRules);
29
29
  if (validation.fails()) {
30
- return context.res.json(validation.errors, 400);
30
+ return context.res.status(400).json(validation.errors);
31
31
  }
32
32
  }
33
33
  // We should bind the timestamp values
@@ -8,8 +8,9 @@ declare class AxeResponse {
8
8
  private language;
9
9
  constructor(response: ServerResponse, language: ILanguage);
10
10
  get original(): ServerResponse<import("http").IncomingMessage>;
11
- json(data: object, statusCode?: number): void;
12
- send(content: string, statusCode?: number): void;
11
+ status(statusCode: number): this;
12
+ json(data: object): void;
13
+ send(content: string): void;
13
14
  noContent(): void;
14
15
  isResponded(): boolean;
15
16
  statusCode(): number;
@@ -4,21 +4,24 @@ class AxeResponse {
4
4
  constructor(response, language) {
5
5
  this.responseStatus = false;
6
6
  this.response = response;
7
+ this.response.statusCode = 200;
7
8
  this.language = language;
8
9
  }
9
10
  get original() {
10
11
  return this.response;
11
12
  }
12
- json(data, statusCode = 200) {
13
+ status(statusCode) {
14
+ this.response.statusCode = statusCode;
15
+ return this;
16
+ }
17
+ json(data) {
13
18
  this.response.setHeader("Content-Type", "application/json");
14
19
  this.response.setHeader("Content-Language", this.language.language);
15
- this.response.statusCode = statusCode;
16
20
  this.response.write(JSON.stringify(data));
17
21
  this.response.end();
18
22
  this.responseStatus = true;
19
23
  }
20
- send(content, statusCode = 200) {
21
- this.response.statusCode = statusCode;
24
+ send(content) {
22
25
  this.response.write(content);
23
26
  this.response.end();
24
27
  this.responseStatus = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.0.0-rc2",
3
+ "version": "1.0.0-rc3",
4
4
  "description": "AXE API is a simple tool which has been created based on Express and Knex.js to create Rest APIs quickly.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",