Skip to content

Commit feb2c24

Browse files
authored
Merge pull request #59 from CodelyTV/part_three
Part three
2 parents d577fc1 + 48d3428 commit feb2c24

File tree

60 files changed

+4421
-3612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4421
-3612
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
node-version: [8.x, 10.x, 12.x]
11+
node-version: [12.x, 14.x]
1212
mongodb-version: [4.0, 4.2]
1313

1414
steps:

cucumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let common = [
2-
'tests/**/features/*.feature', // Specify our feature files
2+
'tests/**/features/**/*.feature', // Specify our feature files
33
'--require-module ts-node/register', // Load TypeScript module
44
'--require tests/**/features/step_definitions/*.steps.ts' // Load step definitions
55
].join(' ');

package-lock.json

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

package.json

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "typescript-ddd-skeleton",
33
"version": "1.0.0",
44
"description": "",
5+
"repository": {
6+
"url": "https://github.com/CodelyTV/typescript-ddd-skeleton"
7+
},
8+
"license": "",
59
"engines": {
610
"node": ">=10.15.0",
711
"npm": ">=6.7.0"
@@ -18,52 +22,52 @@
1822
"build:clean": "rm -r dist; exit 0"
1923
},
2024
"dependencies": {
21-
"@types/bson": "^4.0.0",
22-
"@types/compression": "^1.0.1",
23-
"@types/convict": "^4.2.1",
24-
"@types/errorhandler": "0.0.32",
25-
"@types/express": "^4.17.2",
25+
"@types/bson": "^4.0.2",
26+
"@types/compression": "^1.7.0",
27+
"@types/convict": "^5.2.1",
28+
"@types/errorhandler": "1.5.0",
29+
"@types/express": "^4.17.6",
2630
"@types/glob": "^7.1.1",
27-
"@types/helmet": "0.0.44",
28-
"@types/mongodb": "^3.3.15",
29-
"@types/node": "~13.1.1",
30-
"@types/uuid": "^3.4.6",
31+
"@types/helmet": "0.0.47",
32+
"@types/mongodb": "^3.5.18",
33+
"@types/node": "^14.0.3",
34+
"@types/uuid": "^8.0.0",
3135
"@types/uuid-validate": "0.0.1",
3236
"body-parser": "^1.19.0",
33-
"bson": "^4.0.2",
37+
"bson": "^4.0.4",
3438
"compression": "^1.7.4",
35-
"convict": "^5.1.0",
39+
"convict": "^6.0.0",
3640
"copy": "^0.3.2",
3741
"errorhandler": "^1.5.1",
3842
"express": "^4.17.1",
3943
"glob": "^7.1.6",
40-
"helmet": "^3.21.2",
44+
"helmet": "^3.22.0",
4145
"http-status": "^1.4.2",
4246
"mandrill-api": "^1.0.45",
43-
"mongodb": "^3.5.2",
44-
"node-dependency-injection": "^2.4.2",
45-
"ts-node": "^8.3.0",
46-
"typescript": "^3.7.2",
47-
"uuid": "^3.3.3",
47+
"mongodb": "^3.5.7",
48+
"node-dependency-injection": "^2.6.3",
49+
"ts-node": "^8.10.1",
50+
"typescript": "^3.9.2",
51+
"uuid": "^8.0.0",
4852
"uuid-validate": "0.0.3",
4953
"winston": "^3.2.1"
5054
},
5155
"devDependencies": {
52-
"@types/aws-lambda": "^8.10.31",
53-
"@types/cucumber": "^4.0.7",
54-
"@types/faker": "^4.1.5",
55-
"@types/jest": "^24.0.18",
56-
"@types/supertest": "^2.0.8",
56+
"@types/aws-lambda": "^8.10.51",
57+
"@types/cucumber": "^6.0.1",
58+
"@types/faker": "^4.1.12",
59+
"@types/jest": "^25.2.3",
60+
"@types/supertest": "^2.0.9",
5761
"cucumber": "^6.0.5",
5862
"faker": "^4.1.0",
59-
"husky": "^1.3.1",
60-
"jest": "^24.9.0",
61-
"lint-staged": "8.2.1",
62-
"prettier": "^1.16.4",
63+
"husky": "^4.2.5",
64+
"jest": "^26.0.1",
65+
"lint-staged": "10.2.4",
66+
"prettier": "^2.0.5",
6367
"supertest": "^4.0.2",
64-
"ts-jest": "^24.1.0",
65-
"ts-node-dev": "^1.0.0-pre.43",
66-
"tslint": "^5.20.1",
68+
"ts-jest": "^26.0.0",
69+
"ts-node-dev": "^1.0.0-pre.44",
70+
"tslint": "^6.1.2",
6771
"tslint-config-prettier": "~1.18.0",
6872
"tslint-eslint-rules": "^5.4.0"
6973
},

src/Contexts/Mooc/Courses/application/CourseCreator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ export class CourseCreator {
1616
}
1717

1818
async run(request: CreateCourseRequest): Promise<void> {
19-
const course = new Course(
19+
const course = Course.create(
2020
new CourseId(request.id),
2121
new CourseName(request.name),
2222
new CourseDuration(request.duration)
2323
);
2424

2525
await this.repository.save(course);
26-
2726
this.eventBus.publish(course.pullDomainEvents());
2827
}
2928
}

src/Contexts/Mooc/Courses/domain/Course.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export class Course extends AggregateRoot {
3030
return course;
3131
}
3232

33-
static fromPrimitives(plainData: any): Course {
33+
static fromPrimitives(plainData: { id: string; name: string; duration: string }): Course {
3434
return new Course(
3535
new CourseId(plainData.id),
3636
new CourseName(plainData.name),
3737
new CourseDuration(plainData.duration)
3838
);
3939
}
4040

41-
toPrimitives(): any {
41+
toPrimitives() {
4242
return {
4343
id: this.id.value,
4444
name: this.name.value,

src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export class CourseCreatedDomainEvent extends DomainEvent {
1313

1414
constructor({
1515
id,
16-
eventId,
17-
duration,
1816
name,
17+
duration,
18+
eventId,
1919
occurredOn
2020
}: {
2121
id: string;
@@ -37,12 +37,12 @@ export class CourseCreatedDomainEvent extends DomainEvent {
3737
};
3838
}
3939

40-
static fromPrimitive(
40+
static fromPrimitives(
4141
aggregateId: string,
4242
body: CreateCourseDomainEventBody,
4343
eventId: string,
4444
occurredOn: Date
45-
): CourseCreatedDomainEvent {
45+
): DomainEvent {
4646
return new CourseCreatedDomainEvent({
4747
id: aggregateId,
4848
duration: body.duration,
103 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { CoursesCounterRepository } from '../../domain/CoursesCounterRepository';
2+
import { CoursesCounterNotExist } from '../../domain/CoursesCounterNotExist';
3+
import { CoursesCounterResponse } from './CoursesCounterResponse';
4+
5+
export class CoursesCounterFinder {
6+
constructor(private repository: CoursesCounterRepository) {}
7+
8+
async run() {
9+
const counter = await this.repository.search();
10+
if (!counter) {
11+
throw new CoursesCounterNotExist();
12+
}
13+
14+
return new CoursesCounterResponse(counter.total.value);
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class CoursesCounterResponse {
2+
readonly total: number;
3+
4+
constructor(total: number) {
5+
this.total = total;
6+
}
7+
}

0 commit comments

Comments
 (0)