Skip to content

Commit

Permalink
feat: Add category aggregate, category repository, list and create us…
Browse files Browse the repository at this point in the history
…e case
  • Loading branch information
argentinaluiz committed Mar 10, 2022
1 parent 1c3cec2 commit 77d3bd4
Show file tree
Hide file tree
Showing 42 changed files with 1,658 additions and 256 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/node": "^17.0.18",
"@types/uuid": "^8.3.4",
"jest": "^27.5.1",
"regenerator-runtime": "^0.13.9",
"sucrase": "^3.20.3",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
Expand Down
21 changes: 21 additions & 0 deletions src/@core/@seedwork/application/dto/pagination-output.dto.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { SearchResult } from "../../domain/repository/repository-contracts";
import { PaginationOutputDto } from "./pagination-output.dto";

describe("PaginationOuputDto Unit Tests", () => {
it("should convert SearchResult to PaginationOutputDto", () => {
const searchResult = new SearchResult({
items: [],
total: 10,
current_page: 2,
per_page: 2,
});

const dto = PaginationOutputDto.fromRepoSearchResult(searchResult);
expect(dto).toStrictEqual({
total: 10,
current_page: 2,
per_page: 2,
last_page: 5,
});
});
});
19 changes: 19 additions & 0 deletions src/@core/@seedwork/application/dto/pagination-output.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SearchResult } from "../../domain/repository/repository-contracts";

export class PaginationOutputDto {
total: number;
current_page: number;
last_page: number;
per_page: number;

static fromRepoSearchResult(
result: SearchResult
): PaginationOutputDto {
return {
total: result.total,
current_page: result.current_page,
per_page: result.per_page,
last_page: result.last_page,
};
}
}
7 changes: 0 additions & 7 deletions src/@core/@seedwork/application/dto/pagination.output.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/@core/@seedwork/domain/entity/__tests__/entity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Entity from "../entity";
import { validate as uuidValidate } from "uuid";
import UniqueEntityId from "../unique-entity-id";
import UniqueEntityId from "../../value-objects/unique-entity-id";

class StubEntity extends Entity<{ prop1: string; prop2: number }> {}

Expand Down
8 changes: 4 additions & 4 deletions src/@core/@seedwork/domain/entity/entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import UniqueEntityId from "./unique-entity-id";
import UniqueEntityId from "../value-objects/unique-entity-id";

export default abstract class Entity<Props = any> {
protected readonly _id: UniqueEntityId;
Expand All @@ -11,10 +11,10 @@ export default abstract class Entity<Props = any> {
return this._id.value;
}

toJSON() {
toJSON(): Required<{ id: string } & Props> {
return {
id: this._id.value,
...this.props,
};
} as Required<{id: string} & Props>;
}
}
}
7 changes: 7 additions & 0 deletions src/@core/@seedwork/domain/errors/invalid-uuid.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default class InvalidUuidError extends Error {
constructor() {
super('ID must be a valid UUID');
this.name = 'InvalidUuidError';
}
}

6 changes: 6 additions & 0 deletions src/@core/@seedwork/domain/mapper-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Entity from "./entity/entity";

export default interface Mapper<E extends Entity, P> {
toEntity(persistence: P): E;
toPersistence(t: E): P;
}
13 changes: 0 additions & 13 deletions src/@core/@seedwork/domain/repository-interface.ts

This file was deleted.

Loading

0 comments on commit 77d3bd4

Please sign in to comment.