@orion-js/http 3.2.8 → 3.2.11

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.
@@ -20,9 +20,9 @@ function Route(options) {
20
20
  target.routes = target.routes || {};
21
21
  target.routes[propertyKey] = (0, route_1.default)({
22
22
  ...options,
23
- resolve: async (params, viewer) => {
23
+ resolve: async (req, res, viewer) => {
24
24
  const instance = (0, services_1.getInstance)(target.service);
25
- return await instance[propertyKey](params, viewer);
25
+ return await instance[propertyKey](req, res, viewer);
26
26
  }
27
27
  });
28
28
  };
@@ -8,33 +8,52 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const services_1 = require("@orion-js/services");
12
16
  const _1 = require(".");
17
+ const start_1 = require("../start");
18
+ const supertest_1 = __importDefault(require("supertest"));
19
+ const registerRoutes_1 = __importDefault(require("../routes/registerRoutes"));
13
20
  describe('Routes with service injections', () => {
14
21
  it('Should define a routes map using services', async () => {
22
+ let ServiceExample = class ServiceExample {
23
+ sayHi(name) {
24
+ return `hello ${name}`;
25
+ }
26
+ };
27
+ ServiceExample = __decorate([
28
+ (0, services_1.Service)()
29
+ ], ServiceExample);
15
30
  let RoutesService = class RoutesService {
16
- async route1() {
31
+ async route(req) {
17
32
  return {
18
33
  statusCode: 200,
19
- body: 'route1'
34
+ body: {
35
+ message: this.serviceExample.sayHi(req.body.name)
36
+ }
20
37
  };
21
38
  }
22
39
  };
23
40
  __decorate([
24
- (0, _1.Route)({ method: 'get', path: '/route1' }),
41
+ (0, services_1.Inject)(),
42
+ __metadata("design:type", ServiceExample)
43
+ ], RoutesService.prototype, "serviceExample", void 0);
44
+ __decorate([
45
+ (0, _1.Route)({ method: 'post', path: '/route-service-test', bodyParser: 'json' }),
25
46
  __metadata("design:type", Function),
26
- __metadata("design:paramtypes", []),
47
+ __metadata("design:paramtypes", [Object]),
27
48
  __metadata("design:returntype", Promise)
28
- ], RoutesService.prototype, "route1", null);
49
+ ], RoutesService.prototype, "route", null);
29
50
  RoutesService = __decorate([
30
51
  (0, _1.Routes)()
31
52
  ], RoutesService);
32
53
  const routes = (0, _1.getServiceRoutes)(RoutesService);
33
- expect(routes).toMatchObject({
34
- route1: {
35
- method: 'get',
36
- path: '/route1'
37
- }
38
- });
54
+ (0, registerRoutes_1.default)(routes);
55
+ const app = (0, start_1.getApp)();
56
+ const response = await (0, supertest_1.default)(app).post('/route-service-test').send({ name: 'nico' });
57
+ expect(response.body).toEqual({ message: `hello nico` });
39
58
  });
40
59
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/http",
3
- "version": "3.2.8",
3
+ "version": "3.2.11",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [
@@ -21,7 +21,7 @@
21
21
  "@orion-js/helpers": "^3.2.0",
22
22
  "@orion-js/resolvers": "^3.2.0",
23
23
  "@orion-js/schema": "^3.2.0",
24
- "@orion-js/services": "^3.2.0",
24
+ "@orion-js/services": "^3.2.10",
25
25
  "body-parser": "1.19.0",
26
26
  "express": "4.17.1",
27
27
  "reflect-metadata": "^0.1.13"
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "9380aba023b0b9b241184f6063db91eff8c005bf"
45
+ "gitHead": "682d72347e1d5d8d7a46e58fb481ad4fe8c63415"
46
46
  }