@@ -38,10 +38,11 @@ export interface CreateCustomerData {
3838}
3939
4040export interface CreateCustomerResponse {
41- data : Customer ;
41+ data : CreateCustomerData ;
4242 _server_messages ?: string ;
4343}
4444
45+
4546export async function getCustomerGroups ( ) {
4647 const groups = await db . getDocList ( DOCTYPES . CUSTOMER_GROUP , {
4748 fields : [ 'name' ] ,
@@ -66,16 +67,31 @@ export async function getCustomerTerritories() {
6667 return territories ;
6768}
6869
69- export async function addCustomer ( customerData : CreateCustomerData ) : Promise < CreateCustomerResponse > {
70+ export async function addCustomer (
71+ customerData : CreateCustomerData
72+ ) : Promise < CreateCustomerResponse > {
7073 try {
71- const response = await db . createDoc ( DOCTYPES . CUSTOMER , customerData ) ;
72- return { data : response as Customer } ;
74+ const response = await call . post ( 'ury.ury_pos.api.create_customer' , customerData ) ;
75+ const msg = response . message ;
76+ if ( ! msg || msg . status !== "success" ) {
77+ throw new Error ( "Failed to create Customer,API Response error" ) ;
78+ }
79+ return {
80+ data : {
81+ customer_name : msg . customer_name ,
82+ mobile_number : msg . mobile_number ,
83+ customer_group : msg . customer_group ,
84+ territory : msg . territory
85+ }
86+ } ;
87+
7388 } catch ( error ) {
7489 console . error ( 'Error creating customer:' , error ) ;
7590 throw error ;
7691 }
7792}
7893
94+
7995export async function searchCustomers ( search : string , limit = 5 ) {
8096 if ( ! search . trim ( ) ) return [ ] ;
8197 try {
0 commit comments