common-cents-api/src/merchants/merchant-data.service.ts
2026-02-08 16:23:44 -06:00

33 lines
No EOL
972 B
TypeScript

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<Merchant>;
public constructor(private dataSource: DataSource) {
this.merchants = this.dataSource.getRepository(Merchant);
}
public async getAll(): Promise<Merchant[]> {
return await this.merchants.find();
}
public async getById(id: string): Promise<Merchant | null> {
return await this.merchants.findOneBy({ id });
}
public async create(name: string): Promise<Merchant> {
return await this.merchants.save({ name });
}
public async update(merchant: UpdateMerchantDto): Promise<Merchant> {
return await this.merchants.save(merchant);
}
public async delete(id: string): Promise<void> {
await this.merchants.delete({ id });
}
}