import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Translation } from './model/translation.entity';

@Injectable()
export class TranslateService {
  constructor(
    @InjectRepository(Translation)
    private translationsRepository: Repository<Translation>,
  ) {}

  async getTranslations(language: 'de' | 'en') {
    const db = await this.translationsRepository.findBy({
      language: language,
    });

    const result = {};
    for (const d of db) {
      result[d.key] = d.value;
    }
    return result;
  }
}
