framework-do-dede 6.0.1 → 6.0.2
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.
- package/README.md +12 -6
- package/dist/protocols/repository.d.ts +4 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -491,11 +491,10 @@ Quando um erro e lancado, o handler padroniza a resposta. Erros de dominio (`App
|
|
|
491
491
|
Interfaces tipadas para padrao de repositorio:
|
|
492
492
|
|
|
493
493
|
- `Optional<T>` (helper inspirado em micronaut/spring)
|
|
494
|
-
- `
|
|
495
|
-
- `
|
|
496
|
-
- `RepositoryUpdate<T extends RepositoryModel>`
|
|
494
|
+
- `RepositoryCreate<T extends Entity>`
|
|
495
|
+
- `RepositoryUpdate<T extends Entity>`
|
|
497
496
|
- `RepositoryRemove`
|
|
498
|
-
- `RepositoryRestore<T extends
|
|
497
|
+
- `RepositoryRestore<T extends Entity>`
|
|
499
498
|
- `RepositoryRemoveBy<T>`
|
|
500
499
|
- `RepositoryRestoreBy<T>`
|
|
501
500
|
- `RepositoryExistsBy<T>`
|
|
@@ -508,7 +507,7 @@ Interfaces tipadas para padrao de repositorio:
|
|
|
508
507
|
import { Optional } from './src';
|
|
509
508
|
|
|
510
509
|
class UserRepository {
|
|
511
|
-
async restore(id: string): Promise<Optional<
|
|
510
|
+
async restore(id: string): Promise<Optional<User>> {
|
|
512
511
|
const result = await this.orm
|
|
513
512
|
.select()
|
|
514
513
|
.from(userTable)
|
|
@@ -516,12 +515,19 @@ class UserRepository {
|
|
|
516
515
|
|
|
517
516
|
const row = result[0] ?? null;
|
|
518
517
|
const model = row ? new UserModel().fromModel(row) : null;
|
|
519
|
-
|
|
518
|
+
const entity = model ? model.toEntity() : null;
|
|
519
|
+
return Optional.ofNullable(entity);
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
|
|
523
523
|
const user = await repo.restore('1').orElseThrow('Usuario nao encontrado');
|
|
524
524
|
const userByEmail = await repo.restoreByEmail('a@b.com').orElseNull();
|
|
525
|
+
const userOrThrow = await repo.restoreByEmail('a@b.com').orElseThrow(
|
|
526
|
+
() => new Unauthorized('Usuario ou senha invalida')
|
|
527
|
+
);
|
|
528
|
+
const userOrThrow2 = await repo.restoreByEmail('a@b.com').orElseThrow(
|
|
529
|
+
new Unauthorized('Usuario ou senha invalida')
|
|
530
|
+
);
|
|
525
531
|
```
|
|
526
532
|
|
|
527
533
|
## Exemplos
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Optional } from "../domain";
|
|
2
|
-
|
|
3
|
-
export interface RepositoryCreate<T extends RepositoryModel> {
|
|
1
|
+
import { Entity, Optional } from "../domain";
|
|
2
|
+
export interface RepositoryCreate<T extends Entity> {
|
|
4
3
|
create(input: T): Promise<void>;
|
|
5
4
|
}
|
|
6
|
-
export interface RepositoryUpdate<T extends
|
|
5
|
+
export interface RepositoryUpdate<T extends Entity> {
|
|
7
6
|
update(input: T): Promise<void>;
|
|
8
7
|
}
|
|
9
8
|
export interface RepositoryRemove {
|
|
10
9
|
remove(id: string | number): Promise<void>;
|
|
11
10
|
}
|
|
12
|
-
export interface RepositoryRestore<T extends
|
|
11
|
+
export interface RepositoryRestore<T extends Entity> {
|
|
13
12
|
restore(id: string | number): Promise<Optional<T>>;
|
|
14
13
|
}
|
|
15
14
|
export type RepositoryRemoveBy<T> = {
|