import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { MerchantLog } from './merchantlog.entity';
import { Repository } from 'typeorm';

@Injectable()
export class MerchantlogService {
  constructor(
    @InjectRepository(MerchantLog)
    private merchantLogRepo: Repository<MerchantLog>,
  ) {}

  async getAll(): Promise<any> {
    const data = await this.merchantLogRepo.find();
    return data;
  }

  async addLog(body: any): Promise<any> {
    const merchantLog = await this.merchantLogRepo.create(body);
    await this.merchantLogRepo.save(merchantLog);
    return { success: true, message: 'Merchant Log adding completed!' };
  }

  async getMerchantLogByMerchantId(idMerchant: number): Promise<any> {
    const data = await this.merchantLogRepo.findBy({
      Merchant_idMerchant: idMerchant,
    });
    return data;
  }
}
