-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './agnoc.server'; | ||
export * from './query-handlers/find-device.query-handler'; |
18 changes: 18 additions & 0 deletions
18
packages/core/src/query-handlers/find-device.query-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { DeviceRepository, FindDeviceQuery, FindDeviceQueryOutput, QueryHandler } from '@agnoc/domain'; | ||
|
||
export class FindDeviceQueryHandler implements QueryHandler { | ||
readonly forName = 'FindDeviceQuery'; | ||
|
||
constructor(private readonly deviceRepository: DeviceRepository) {} | ||
|
||
async handle(event: FindDeviceQuery): Promise<FindDeviceQueryOutput> { | ||
const device = await this.deviceRepository.findOneById(event.deviceId); | ||
|
||
if (!device) { | ||
throw new DomainException(`Unable to find a device with id ${event.deviceId.value}`); | ||
} | ||
|
||
return { device }; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...src/event-buses/command.event-bus.test.ts → ...vent-buses/command-query.task-bus.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { TaskBus } from '@agnoc/toolkit'; | ||
import type { Commands } from '../commands/commands'; | ||
import type { Queries } from '../queries/queries'; | ||
|
||
export type CommandsOrQueries = Commands & Queries; | ||
export type CommandOrQueryNames = keyof CommandsOrQueries; | ||
|
||
export class CommandQueryBus extends TaskBus<CommandsOrQueries> {} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Queries, QueryNames } from '../queries/queries'; | ||
import type { TaskHandler } from '@agnoc/toolkit'; | ||
|
||
export abstract class QueryHandler implements TaskHandler { | ||
abstract forName: QueryNames; | ||
abstract handle(event: Queries[this['forName']]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ID, Query } from '@agnoc/toolkit'; | ||
import { Device } from '../aggregate-roots/device.aggregate-root'; | ||
|
||
export interface FindDeviceQueryInput { | ||
deviceId: ID; | ||
} | ||
|
||
export interface FindDeviceQueryOutput { | ||
device: Device; | ||
} | ||
|
||
export class FindDeviceQuery extends Query<FindDeviceQueryInput, FindDeviceQueryOutput> { | ||
get deviceId(): ID { | ||
return this.props.deviceId; | ||
} | ||
|
||
protected validate(props: FindDeviceQueryInput): void { | ||
this.validateDefinedProp(props, 'deviceId'); | ||
this.validateInstanceProp(props, 'deviceId', ID); | ||
} | ||
|
||
override validateOutput(output: FindDeviceQueryOutput): void { | ||
this.validateDefinedProp(output, 'device'); | ||
this.validateInstanceProp(output, 'device', Device); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { FindDeviceQuery } from './find-device.query'; | ||
|
||
export type Queries = { | ||
FindDeviceQuery: FindDeviceQuery; | ||
}; | ||
|
||
export type QueryNames = keyof Queries; |