mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
refactor: clean up
This commit is contained in:
@@ -89,40 +89,6 @@ export const api = {
|
||||
logout: endpoint<void, void>("auth", "logout", authService.logout),
|
||||
},
|
||||
|
||||
customers: {
|
||||
list: endpoint<void, Customer[]>(
|
||||
"customers",
|
||||
"list",
|
||||
customersService.list,
|
||||
),
|
||||
|
||||
get: endpoint<{ id: string }, Customer>("customers", "get", ({ id }) =>
|
||||
customersService.getById(id),
|
||||
),
|
||||
|
||||
create: endpoint<CreateCustomerDto, Customer>(
|
||||
"customers",
|
||||
"create",
|
||||
customersService.create,
|
||||
),
|
||||
|
||||
update: endpoint<{ id: string; dto: UpdateCustomerDto }, Customer>(
|
||||
"customers",
|
||||
"update",
|
||||
({ id, dto }) => customersService.update(id, dto),
|
||||
),
|
||||
|
||||
remove: endpoint<{ id: string }, void>("customers", "remove", ({ id }) =>
|
||||
customersService.remove(id),
|
||||
),
|
||||
|
||||
getByUserId: endpoint<{ id: string }, Customer | null>(
|
||||
"customers",
|
||||
"getByUserId",
|
||||
({ id }) => customersService.getByUserId(id),
|
||||
),
|
||||
},
|
||||
|
||||
companies: {
|
||||
getInfo: endpoint<void, CompanyInfoResponse | null>(
|
||||
"companies",
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { client } from "@/utils/api";
|
||||
import { unwrap } from "@/utils/endpoint";
|
||||
import { URL_CONSTANTS } from "@/constants/URLS";
|
||||
import type { ApiResponse } from "@/types/apiResponse";
|
||||
import type {
|
||||
CreateCustomerDto,
|
||||
Customer,
|
||||
UpdateCustomerDto,
|
||||
} from "@/types/customers";
|
||||
import { isAxiosError } from "axios";
|
||||
|
||||
const BASE = URL_CONSTANTS.CUSTOMERS_API.BASE;
|
||||
|
||||
export const customersService = {
|
||||
list: async (): Promise<Customer[]> => {
|
||||
const response = await client.get<ApiResponse<Customer[]>>(BASE);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getById: async (id: string): Promise<Customer> => {
|
||||
const response = await client.get<ApiResponse<Customer>>(
|
||||
URL_CONSTANTS.CUSTOMERS_API.BY_ID(id),
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getByUserId: async (userId: string): Promise<Customer | null> => {
|
||||
try {
|
||||
const response = await client.get<ApiResponse<Customer>>(
|
||||
URL_CONSTANTS.CUSTOMERS_API.BY_USER_ID(userId),
|
||||
);
|
||||
return unwrap(response.data);
|
||||
} catch (e) {
|
||||
if (isAxiosError(e) && e.response?.status === 404) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
|
||||
create: async (payload: CreateCustomerDto): Promise<Customer> => {
|
||||
const response = await client.post<ApiResponse<Customer>>(BASE, payload);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
update: async (id: string, payload: UpdateCustomerDto): Promise<Customer> => {
|
||||
const response = await client.patch<ApiResponse<Customer>>(
|
||||
URL_CONSTANTS.CUSTOMERS_API.BY_ID(id),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
remove: async (id: string): Promise<void> => {
|
||||
await client.delete(URL_CONSTANTS.CUSTOMERS_API.BY_ID(id));
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user