15 lines
607 B
TypeScript
15 lines
607 B
TypeScript
import { InjectionToken, OptionalFactoryDependency, Provider } from '@nestjs/common';
|
|
|
|
import { AbstractActionHandler } from '../abstract-action.handler';
|
|
import { Action } from '../action.enum';
|
|
import { ExistingActionHandlers } from './default-action-handler.constants';
|
|
|
|
export const ExistingActionHandlersProvider = (inject: Array<InjectionToken | OptionalFactoryDependency>): Provider => ({
|
|
provide: ExistingActionHandlers,
|
|
useFactory: (...args: AbstractActionHandler[]) => args.reduce((m, h) => {
|
|
m[h.action] = h;
|
|
return m;
|
|
}, {} as Record<Action, AbstractActionHandler>),
|
|
inject,
|
|
});
|