feat: add client management module
This commit is contained in:
54
src/services/api/client.service.ts
Normal file
54
src/services/api/client.service.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import axiosClient from '../axios/axios';
|
||||
import type { Client, ClientListParams, ClientListResponse, ClientRequest } from '@/types';
|
||||
|
||||
const CLIENTS_ENDPOINT = 'api/clients';
|
||||
|
||||
function toClientPayload(payload: ClientRequest) {
|
||||
return {
|
||||
name: payload.name,
|
||||
email: payload.email,
|
||||
landline_number: payload.landline_number,
|
||||
address: payload.address,
|
||||
gst: payload.gst ?? null,
|
||||
pan: payload.pan ?? null,
|
||||
tan: payload.tan ?? null,
|
||||
contact_name: payload.contact_name,
|
||||
contact_phone_number: payload.contact_phone_number,
|
||||
contact_email: payload.contact_email,
|
||||
is_active: payload.is_active ?? true,
|
||||
};
|
||||
}
|
||||
|
||||
export const clientService = {
|
||||
getClients: async (params?: ClientListParams): Promise<ClientListResponse> => {
|
||||
const response = await axiosClient.get<ClientListResponse>(CLIENTS_ENDPOINT, {
|
||||
params: {
|
||||
skip: params?.skip ?? 0,
|
||||
limit: params?.limit ?? 10,
|
||||
search_term: params?.search_term,
|
||||
name: params?.name,
|
||||
email: params?.email,
|
||||
contact_name: params?.contact_name,
|
||||
is_active: params?.is_active,
|
||||
sort_by: params?.sort_by,
|
||||
sort_order: params?.sort_order,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
saveClient: async (payload: ClientRequest): Promise<Client> => {
|
||||
const requestPayload = toClientPayload(payload);
|
||||
const response = payload.id
|
||||
? await axiosClient.put<Client>(`${CLIENTS_ENDPOINT}/${payload.id}`, requestPayload)
|
||||
: await axiosClient.post<Client>(CLIENTS_ENDPOINT, requestPayload);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateClientStatus: async (id: number, isActive: boolean): Promise<Client> => {
|
||||
const response = await axiosClient.patch<Client>(`${CLIENTS_ENDPOINT}/${id}/status`, {
|
||||
is_active: isActive,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
@@ -9,3 +9,4 @@ export { projectDataService } from './project.service';
|
||||
export * from './permission.service';
|
||||
export * from './role.service';
|
||||
export * from './user.service';
|
||||
export * from './client.service';
|
||||
|
||||
Reference in New Issue
Block a user