forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer-service.ts
More file actions
69 lines (62 loc) · 1.64 KB
/
Copy pathcustomer-service.ts
File metadata and controls
69 lines (62 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { apiClient } from "./api-client";
export interface Customer {
id: string;
merchantId: string;
name: string;
email: string | null;
notes: string | null;
createdAt: string;
updatedAt: string;
}
export interface CreateCustomerPayload {
name: string;
email?: string;
notes?: string;
}
export const CustomerService = {
/**
* Search customers for autocomplete/typeahead.
*/
async search(query: string, limit = 10): Promise<Customer[]> {
const params = new URLSearchParams({ q: query, limit: String(limit) });
const response = await apiClient.get<Customer[]>(
`/customers/search?${params}`,
);
return response.data;
},
/**
* Fetch all customers with optional search.
*/
async list(search?: string, limit = 50): Promise<Customer[]> {
const params = new URLSearchParams({ limit: String(limit) });
if (search?.trim()) params.set("search", search.trim());
const response = await apiClient.get<Customer[]>(`/customers?${params}`);
return response.data;
},
/**
* Create a new customer profile.
*/
async create(payload: CreateCustomerPayload): Promise<Customer> {
const response = await apiClient.post<Customer>("/customers", payload);
return response.data;
},
/**
* Update an existing customer.
*/
async update(
id: string,
payload: Partial<CreateCustomerPayload>,
): Promise<Customer> {
const response = await apiClient.patch<Customer>(
`/customers/${id}`,
payload,
);
return response.data;
},
/**
* Delete a customer.
*/
async remove(id: string): Promise<void> {
await apiClient.delete(`/customers/${id}`);
},
};