feature/research-di #1

Merged
behnam merged 37 commits from feature/research-di into develop 2024-11-21 15:50:19 +00:00
3 changed files with 14 additions and 0 deletions
Showing only changes of commit b6a15e0579 - Show all commits

View File

@ -46,6 +46,11 @@ export default class CustomerDbRepo implements CustomerRepo {
}
}
async fetchCustomersAmount(): Promise<number> {
const data = await sql`SELECT COUNT(*) FROM customers`as postgres.RowList<unknown[]>;
return Number(data.count ?? '0');
}
private customersDto(dbCustomers: customerDbResponse[]): Customer[] {
return dbCustomers.map((customer) => this.customerDto(customer));

View File

@ -2,6 +2,7 @@ import Customer from "@/feature/customer/domain/entity/customer"
export default interface CustomerRepo {
fetchList(query: string): Promise<Customer[]>
fetchCustomersAmount(): Promise<number>
}
export const customerRepoKey = "customerRepoKey"

View File

@ -0,0 +1,8 @@
import serverDi from "@/feature/common/server-di";
import { customerKey } from "@/feature/customer/customer-key";
import CustomerRepo, { customerRepoKey } from "@/feature/customer/domain/i-repo/customer-repo";
export default function fetchCustomersAmountUsecase(): Promise<number> {
const repo = serverDi(customerKey).resolve<CustomerRepo>(customerRepoKey)
return repo.fetchCustomersAmount()
}