Commit f34520c1 authored by Hidde-Jan Jongsma's avatar Hidde-Jan Jongsma

Add GetConnector pipe

parent 54cf0ef9
......@@ -3,10 +3,11 @@ import { Module } from '@nestjs/common';
import { JolocomModule } from './jolocom/jolocom.module';
import { IrmaModule } from './irma/irma.module';
import { ConnectorsService } from './connectors.service';
import { GetConnectorPipe } from './get-connector.pipe';
@Module({
imports: [JolocomModule, IrmaModule],
providers: [ConnectorsService],
exports: [ConnectorsService],
providers: [ConnectorsService, GetConnectorPipe],
exports: [ConnectorsService, GetConnectorPipe],
})
export class ConnectorsModule {}
import {
PipeTransform,
Injectable,
ArgumentMetadata,
Inject,
} from '@nestjs/common';
import { ConnectorsService } from './connectors.service';
@Injectable()
export class GetConnectorPipe implements PipeTransform {
constructor(
@Inject(ConnectorsService) private connectorsService: ConnectorsService,
) {}
transform(connectorName: string, metatdata: ArgumentMetadata) {
const connector = this.connectorsService.getConnector(connectorName);
if (!connector) {
throw new Error(`No connector for "${connectorName}"`);
}
return connector;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment