first commit
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
import { http } from "@/utils/http";
|
||||
|
||||
const API_PREFIX = "/api";
|
||||
|
||||
export type EmployeeStatus = "ACTIVE" | "INACTIVE";
|
||||
export type StoreStatus = "ACTIVE" | "INACTIVE";
|
||||
|
||||
export interface RoleSummary {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Employee {
|
||||
id: number;
|
||||
storeId: number;
|
||||
storeName: string;
|
||||
name: string;
|
||||
phone: string;
|
||||
status: EmployeeStatus;
|
||||
remark: string | null;
|
||||
roles: RoleSummary[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface StoreOption {
|
||||
id: number;
|
||||
name: string;
|
||||
address: string | null;
|
||||
phone: string | null;
|
||||
}
|
||||
|
||||
export interface RoleOption {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
}
|
||||
|
||||
export interface Store extends StoreOption {
|
||||
status: StoreStatus;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Role extends RoleOption {
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface EmployeeListParams {
|
||||
storeId?: number;
|
||||
status?: EmployeeStatus;
|
||||
keyword?: string;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
export interface StoreListParams {
|
||||
includeInactive?: boolean;
|
||||
}
|
||||
|
||||
export interface StorePayload {
|
||||
name: string;
|
||||
address?: string | null;
|
||||
phone?: string | null;
|
||||
status: StoreStatus;
|
||||
}
|
||||
|
||||
export interface RolePayload {
|
||||
code: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface EmployeePayload {
|
||||
storeId: number;
|
||||
name: string;
|
||||
phone: string;
|
||||
status: EmployeeStatus;
|
||||
remark?: string | null;
|
||||
roleIds: number[];
|
||||
}
|
||||
|
||||
export interface ApiResult<T> {
|
||||
success: boolean;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export interface Pagination {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export interface PaginatedData<T> {
|
||||
items: T[];
|
||||
pagination: Pagination;
|
||||
}
|
||||
|
||||
export const listStores = (params?: StoreListParams) => {
|
||||
return http.request<ApiResult<Store[]>>("get", `${API_PREFIX}/stores`, {
|
||||
params
|
||||
});
|
||||
};
|
||||
|
||||
export const listRoles = () => {
|
||||
return http.request<ApiResult<Role[]>>("get", `${API_PREFIX}/roles`);
|
||||
};
|
||||
|
||||
export const getStore = (id: number) => {
|
||||
return http.request<ApiResult<Store>>("get", `${API_PREFIX}/stores/${id}`);
|
||||
};
|
||||
|
||||
export const createStore = (data: StorePayload) => {
|
||||
return http.request<ApiResult<Store>>("post", `${API_PREFIX}/stores`, {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const updateStore = (id: number, data: Partial<StorePayload>) => {
|
||||
return http.request<ApiResult<Store>>("patch", `${API_PREFIX}/stores/${id}`, {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteStore = (id: number) => {
|
||||
return http.request<void>("delete", `${API_PREFIX}/stores/${id}`);
|
||||
};
|
||||
|
||||
export const getRole = (id: number) => {
|
||||
return http.request<ApiResult<Role>>("get", `${API_PREFIX}/roles/${id}`);
|
||||
};
|
||||
|
||||
export const createRole = (data: RolePayload) => {
|
||||
return http.request<ApiResult<Role>>("post", `${API_PREFIX}/roles`, {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const updateRole = (id: number, data: Partial<RolePayload>) => {
|
||||
return http.request<ApiResult<Role>>("patch", `${API_PREFIX}/roles/${id}`, {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteRole = (id: number) => {
|
||||
return http.request<void>("delete", `${API_PREFIX}/roles/${id}`);
|
||||
};
|
||||
|
||||
export const listEmployees = (params: EmployeeListParams) => {
|
||||
return http.request<ApiResult<PaginatedData<Employee>>>(
|
||||
"get",
|
||||
`${API_PREFIX}/employees`,
|
||||
{ params }
|
||||
);
|
||||
};
|
||||
|
||||
export const getEmployee = (id: number) => {
|
||||
return http.request<ApiResult<Employee>>(
|
||||
"get",
|
||||
`${API_PREFIX}/employees/${id}`
|
||||
);
|
||||
};
|
||||
|
||||
export const createEmployee = (data: EmployeePayload) => {
|
||||
return http.request<ApiResult<Employee>>("post", `${API_PREFIX}/employees`, {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const updateEmployee = (id: number, data: Partial<EmployeePayload>) => {
|
||||
return http.request<ApiResult<Employee>>(
|
||||
"patch",
|
||||
`${API_PREFIX}/employees/${id}`,
|
||||
{ data }
|
||||
);
|
||||
};
|
||||
|
||||
export const updateEmployeeStatus = (id: number, status: EmployeeStatus) => {
|
||||
return http.request<ApiResult<Employee>>(
|
||||
"patch",
|
||||
`${API_PREFIX}/employees/${id}/status`,
|
||||
{ data: { status } }
|
||||
);
|
||||
};
|
||||
|
||||
export const deleteEmployee = (id: number) => {
|
||||
return http.request<void>("delete", `${API_PREFIX}/employees/${id}`);
|
||||
};
|
||||
Reference in New Issue
Block a user