feature/research-di #1
@ -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));
|
||||
|
@ -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"
|
@ -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()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user