import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { SiteInfoEntity } from './entities/site-info.entity';

@Injectable()
export class SiteInfoService {
  constructor(
    @InjectRepository(SiteInfoEntity)
    private siteInfoRepository: Repository<SiteInfoEntity>,
  ) {}

  /**
   * -------------------------------------------------------
   */
  async getInfo(attributes = null) {
    const options: any = { where: { id: 1 } };
    if (attributes) {
      options.select = attributes;
    }
    return await this.siteInfoRepository.findOne(options);
  }

  /**
   * -------------------------------------------------------
   * PUT /siteInfos
   */
  async update(dto: any) {
    return await this.siteInfoRepository
      .createQueryBuilder()
      .update()
      .set({ ...dto, updatedAt: new Date() })
      .where({ id: 1 })
      .execute();
  }
}
