added merchants resource
This commit is contained in:
parent
d7ad5828af
commit
b5ced781c9
17 changed files with 214 additions and 80 deletions
33
src/merchants/merchant-data.service.ts
Normal file
33
src/merchants/merchant-data.service.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue