import { Injectable } from '@nestjs/common'; import { DataSource, Repository } from 'typeorm'; import { Merchant } from './entities/merchant.entity'; import { UpdateMerchantDto } from './dto/update-merchant.dto'; @Injectable() export class MerchantDataService { private merchants: Repository; public constructor(private dataSource: DataSource) { this.merchants = this.dataSource.getRepository(Merchant); } public async getAll(): Promise { return await this.merchants.find(); } public async getById(id: string): Promise { return await this.merchants.findOneBy({ id }); } public async create(name: string): Promise { return await this.merchants.save({ name }); } public async update(merchant: UpdateMerchantDto): Promise { return await this.merchants.save(merchant); } public async delete(id: string): Promise { await this.merchants.delete({ id }); } }