added merchants resource

This commit is contained in:
Joe Arndt 2026-02-08 15:21:47 -06:00
parent d7ad5828af
commit b5ced781c9
17 changed files with 214 additions and 80 deletions

View file

@ -0,0 +1,33 @@
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 getAllMerchants(): Promise<Merchant[]> {
return this.merchants.find();
}
public async getMerchantById(id: string): Promise<Merchant | null> {
return await this.merchants.findOneBy({ id });
}
public async createMerchant(name: string): Promise<Merchant> {
return await this.merchants.save({ name });
}
public async updateMerchant(updateMerchant: UpdateMerchantDto): Promise<Merchant> {
return await this.merchants.save(updateMerchant);
}
public async deleteMerchant(id: string): Promise<void> {
await this.merchants.delete({ id });
}
}