INTO-CPS-Association/DTaaS

View on GitHub
servers/lib/src/files/files-service.factory.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { IFilesService } from './interfaces/files.service.interface.js';

@Injectable()
export default class FilesServiceFactory {
  static create(
    configService: ConfigService,
    fileServices: IFilesService[],
  ): IFilesService {
    const mode = configService.get<string>('MODE');
    const service = fileServices.find((s) => s.getMode() == mode);

    if (service == undefined) {
      throw new Error(`Invalid MODE: ${mode}`);
    }
    return service;
  }
}