-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationService.ts
More file actions
91 lines (83 loc) · 2.98 KB
/
ApplicationService.ts
File metadata and controls
91 lines (83 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { ApplicationService } from '../../../../dsl/architecture/onion/core/ApplicationService';
import { UsbDeviceInformationRepositoryInterface } from '../../../infrastructure/repositories/UsbDeviceInformationRepository';
import { VsCodeCommandByUsbDeviceKeyRepositoryInterface } from '../../../infrastructure/repositories/VsCodeCommandByUsbDeviceKeyRepository';
import {
Entity as UsbDevicesListEntity,
UsbDevicesListRepositoryInterface,
} from '../../../infrastructure/repositories/UsbDevicesListRepository';
import {
Interface as UsbDeviceBrokerRepositoryInterface,
UsbDeviceKeyPressEventData,
} from '../../../infrastructure/repositories/UsbDeviceEndpointBrokerRepository';
import {
VsCodeCommandsListEntities,
VsCodeCommandsListRepositoryInterface,
} from '../../../infrastructure/repositories/VsCodeCommandsList';
import { SelectVsCodeCommandDomainService } from './DomainService';
type Event = {
// selectUsbKeyDTO: Record<string, any>;
selectUsbKeyDTO: {
usbDeviceKeyPressDataEventList: UsbDeviceKeyPressEventData[];
vsCodeCommandsListEntities: VsCodeCommandsListEntities;
};
vscodeCommand: string;
};
type Entities = UsbDevicesListEntity;
export type DTO = {
vscodeCommand: string;
};
// keep this
type Repositories = {
UsbDeviceEndpointBrokerRepository: UsbDeviceBrokerRepositoryInterface;
UsbDeviceInformationRepository: UsbDeviceInformationRepositoryInterface;
UsbDevicesListRepository: UsbDevicesListRepositoryInterface;
VsCodeCommandByUsbDeviceKeyRepository: VsCodeCommandByUsbDeviceKeyRepositoryInterface;
VsCodeCommandsListRepository: VsCodeCommandsListRepositoryInterface;
};
export interface SelectVsCodeCommandApplicationServiceInterface
extends ApplicationService<
Event,
Entities,
Repositories,
SelectVsCodeCommandDomainService,
DTO
> {
aggregate: (event: Event) => Promise<DTO>;
}
export class SelectVsCodeCommandApplicationService
extends ApplicationService<
Event,
Entities,
Repositories,
SelectVsCodeCommandDomainService,
DTO
>
implements SelectVsCodeCommandApplicationServiceInterface
{
protected domainService: SelectVsCodeCommandDomainService;
protected repositories: Repositories;
constructor(dependencies: {
domainService: SelectVsCodeCommandDomainService;
repositories: Repositories;
}) {
super(dependencies);
const { repositories, domainService } = dependencies;
this.repositories = repositories;
this.domainService = domainService;
}
aggregate = async (event: Event) => {
await Promise.all([
event.selectUsbKeyDTO.usbDeviceKeyPressDataEventList.map(
(usbDeviceKeyPressEventData) =>
this.repositories.VsCodeCommandByUsbDeviceKeyRepository.update({
information: usbDeviceKeyPressEventData.usbDeviceInformation,
usbDeviceKeyPressed: usbDeviceKeyPressEventData.usbDeviceKeyPressed,
vscodeCommand: event.vscodeCommand,
}),
),
]);
return {
vscodeCommand: event.vscodeCommand,
};
};
}