Skip to content

Commit eb4cf5c

Browse files
committed
Refactor application entities. Do not start backoffice frontend subscriber
1 parent f95f01c commit eb4cf5c

File tree

21 files changed

+324
-244
lines changed

21 files changed

+324
-244
lines changed

package-lock.json

Lines changed: 200 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"npm": ">=6.7.0"
1212
},
1313
"scripts": {
14-
"dev": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules --inspect=0.0.0.0:9267 ./src/apps/mooc/backend/start.ts",
14+
"dev:mooc:backend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/mooc/backend/start.ts",
1515
"dev:backoffice:frontend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/backoffice/frontend/start.ts",
1616
"dev:backoffice:backend": "NODE_ENV=dev ts-node-dev --ignore-watch node_modules ./src/apps/backoffice/backend/start.ts",
1717
"test": "npm run test:unit && npm run test:features && npm run cypress:run",
@@ -31,23 +31,23 @@
3131
"cypress:run": "NODE_ENV=end2end ts-node tests/utils/cypress/run"
3232
},
3333
"dependencies": {
34-
"@types/amqplib": "^0.5.16",
34+
"@types/amqplib": "^0.5.17",
3535
"@types/bluebird": "^3.5.33",
3636
"@elastic/elasticsearch": "^7.10.0",
3737
"@types/bson": "^4.0.3",
3838
"@types/compression": "^1.7.0",
39-
"@types/convict": "^5.2.1",
39+
"@types/convict": "^5.2.2",
4040
"@types/errorhandler": "1.5.0",
41-
"@types/express": "^4.17.9",
41+
"@types/express": "^4.17.11",
4242
"@types/glob": "^7.1.3",
4343
"@types/helmet": "0.0.48",
44-
"@types/mongodb": "^3.5.34",
45-
"@types/node": "^14.14.10",
44+
"@types/mongodb": "^3.6.3",
45+
"@types/node": "^14.14.21",
4646
"@types/uuid": "^8.3.0",
4747
"@types/uuid-validate": "0.0.1",
4848
"amqp-ts": "^1.8.0",
4949
"body-parser": "^1.19.0",
50-
"bson": "^4.2.0",
50+
"bson": "^4.2.2",
5151
"compression": "^1.7.4",
5252
"connect-flash": "^0.1.1",
5353
"convict": "^6.0.0",
@@ -57,40 +57,40 @@
5757
"errorhandler": "^1.5.1",
5858
"express": "^4.17.1",
5959
"express-promise-router": "^4.0.1",
60-
"express-validator": "^6.7.0",
60+
"express-validator": "^6.9.2",
6161
"glob": "^7.1.6",
62-
"helmet": "^4.2.0",
62+
"helmet": "^4.3.1",
6363
"http-status": "^1.5.0",
6464
"mandrill-api": "^1.0.45",
6565
"mongodb": "^3.6.3",
6666
"node-dependency-injection": "^2.6.8",
6767
"nunjucks": "^3.2.2",
68-
"ts-node": "^9.0.0",
69-
"typescript": "^4.1.2",
70-
"uuid": "^8.3.1",
68+
"ts-node": "^9.1.1",
69+
"typescript": "^4.1.3",
70+
"uuid": "^8.3.2",
7171
"uuid-validate": "0.0.3",
7272
"winston": "^3.3.3"
7373
},
7474
"devDependencies": {
75-
"@types/aws-lambda": "^8.10.64",
75+
"@types/aws-lambda": "^8.10.70",
7676
"@types/connect-flash": "0.0.36",
7777
"@types/cookie-parser": "^1.4.2",
78-
"@types/cookie-session": "^2.0.41",
78+
"@types/cookie-session": "^2.0.42",
7979
"@types/cucumber": "^6.0.1",
80-
"@types/faker": "^5.1.4",
81-
"@types/jest": "^26.0.15",
80+
"@types/faker": "^5.1.5",
81+
"@types/jest": "^26.0.20",
8282
"@types/nunjucks": "^3.1.3",
8383
"@types/supertest": "^2.0.10",
8484
"cucumber": "^6.0.5",
85-
"cypress": "^6.0.0",
85+
"cypress": "^6.2.1",
8686
"faker": "^5.1.0",
87-
"husky": "^4.3.0",
87+
"husky": "^4.3.7",
8888
"jest": "^26.6.3",
89-
"lint-staged": "10.5.2",
90-
"prettier": "^2.2.0",
91-
"supertest": "^6.0.1",
89+
"lint-staged": "10.5.3",
90+
"prettier": "^2.2.1",
91+
"supertest": "^6.1.0",
9292
"ts-jest": "^26.4.4",
93-
"ts-node-dev": "^1.0.0",
93+
"ts-node-dev": "^1.1.1",
9494
"tslint": "^6.1.3",
9595
"tslint-config-prettier": "~1.18.0",
9696
"tslint-eslint-rules": "^5.4.0"

src/Contexts/Shared/infrastructure/EventBus/RabbitMq/RabbitMqEventBus.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default class RabbitMqEventbus implements EventBus {
3232
await this.queue.activateConsumer(
3333
async message => {
3434
const event = this.deserializer!.deserialize(message.content.toString());
35-
console.log(`========message ${event?.eventName} in ${this.queue.name}`);
3635
if (event) {
3736
const subscribers = this.subscribers.get(event.eventName);
3837
if (subscribers && subscribers.length) {

src/apps/backoffice/backend/BackofficeBackendApp.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { registerSubscribers } from './subscribers';
1+
import { Definition } from 'node-dependency-injection';
2+
import { DomainEvent } from '../../../Contexts/Shared/domain/DomainEvent';
3+
import { DomainEventSubscriber } from '../../../Contexts/Shared/domain/DomainEventSubscriber';
4+
import { EventBus } from '../../../Contexts/Shared/domain/EventBus';
5+
import { DomainEventMapping } from '../../../Contexts/Shared/infrastructure/EventBus/DomainEventMapping';
6+
import container from './dependency-injection';
27
import { Server } from './server';
38

49
export class BackofficeBackendApp {
@@ -7,7 +12,7 @@ export class BackofficeBackendApp {
712
async start() {
813
const port = process.env.PORT || '3000';
914
this.server = new Server(port);
10-
await registerSubscribers();
15+
await this.registerSubscribers();
1116
return this.server.listen();
1217
}
1318

@@ -21,4 +26,21 @@ export class BackofficeBackendApp {
2126
}
2227
return this.server.port;
2328
}
29+
30+
get httpServer() {
31+
return this.server?.httpServer;
32+
}
33+
34+
private async registerSubscribers() {
35+
const eventBus = container.get('Shared.EventBus') as EventBus;
36+
const subscriberDefinitions = container.findTaggedServiceIds('domainEventSubscriber') as Map<String, Definition>;
37+
const subscribers: Array<DomainEventSubscriber<DomainEvent>> = [];
38+
39+
subscriberDefinitions.forEach((value: any, key: any) => subscribers.push(container.get(key)));
40+
const domainEventMapping = new DomainEventMapping(subscribers);
41+
42+
eventBus.setDomainEventMapping(domainEventMapping);
43+
eventBus.addSubscribers(subscribers);
44+
await eventBus.start();
45+
}
2446
}

src/apps/backoffice/backend/dependency-injection/Shared/application.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,4 @@ services:
2121
class: ../../../../../Contexts/Shared/infrastructure/EventBus/RabbitMq/RabbitMqEventBus
2222
arguments: ['@Backoffice.courses.RabbitMqConfig', '@Shared.Logger']
2323

24-
Shared.EventBus.DomainEventMapping:
25-
class: ../../../../../Contexts/Shared/infrastructure/EventBus/DomainEventMapping
26-
arguments: ['!tagged domainEventSubscriber']
2724

28-
Shared.EventBus.DomainEventJsonDeserializer:
29-
class: ../../../../../Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer
30-
arguments: ['@Shared.EventBus.DomainEventMapping']

src/apps/backoffice/backend/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Server {
1212
private express: express.Express;
1313
readonly port: string;
1414
private logger: Logger;
15-
private httpServer?: http.Server;
15+
httpServer?: http.Server;
1616

1717
constructor(port: string) {
1818
this.port = port;

src/apps/backoffice/backend/subscribers.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/apps/backoffice/frontend/BackofficeFrontendApp.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { registerSubscribers } from './subscribers';
21
import { Server } from './server';
32
import { seed } from './seed';
43

@@ -8,7 +7,6 @@ export class BackofficeFrontendApp {
87
async start() {
98
const port = process.env.PORT || '8032';
109
this.server = new Server(port);
11-
await registerSubscribers();
1210
await seed();
1311
return this.server.listen();
1412
}

src/apps/backoffice/frontend/subscribers.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/apps/backoffice/frontend/templates/pages/courses/partials/list_courses.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ <h3 class="font-sans text-gray-800 text-center text-3xl mb-10">Cursos existentes
4141

4242
<script>
4343
function addCoursesList(url) {
44-
console.log(url);
4544

4645
const tableBody = document.getElementById("courses-list");
4746

4847
fetch(url)
4948
.then(function (response) {
50-
console.log(response)
5149
return response.json();
5250
})
5351
.then(function (courses) {

0 commit comments

Comments
 (0)