110 lines
2.5 KiB
TypeScript
110 lines
2.5 KiB
TypeScript
import { axios, type LoginResponse, type Page, type PageResult, type Role } from "timi-web";
|
|
import type { ManagedUser } from "@/types/ManagedUser";
|
|
import { withCurrentStoreId, withCurrentStorePage } from "@/utils/store";
|
|
|
|
const BASE_URI = "/gao/user";
|
|
|
|
type ListOptions = {
|
|
allStores?: boolean;
|
|
storeId?: string;
|
|
};
|
|
|
|
export type InviteRequest = {
|
|
storeId?: string;
|
|
roleId: string;
|
|
};
|
|
|
|
export type InviteResult = {
|
|
code: string;
|
|
expireAt: number;
|
|
};
|
|
|
|
export type InviteValidateResult = {
|
|
valid: boolean;
|
|
expireAt: number;
|
|
};
|
|
|
|
export type InviteRegisterData = {
|
|
code: string;
|
|
phoneNo: string;
|
|
name: string;
|
|
password: string;
|
|
};
|
|
|
|
export type InviteRegisterRequest = {
|
|
detailId: string;
|
|
captcha: string;
|
|
data: InviteRegisterData;
|
|
};
|
|
|
|
async function list(page: Page<ManagedUser>, options?: ListOptions): Promise<PageResult<ManagedUser>> {
|
|
if (options?.allStores) {
|
|
return await axios.post(`${BASE_URI}/list`, page);
|
|
}
|
|
|
|
if (options?.storeId) {
|
|
return await axios.post(`${BASE_URI}/list`, {
|
|
...page,
|
|
equalsExample: {
|
|
...(page.equalsExample || {}),
|
|
storeId: options.storeId
|
|
}
|
|
});
|
|
}
|
|
|
|
return await axios.post(`${BASE_URI}/list`, withCurrentStorePage(page));
|
|
}
|
|
|
|
async function detail(id: string): Promise<ManagedUser> {
|
|
return await axios.post(`${BASE_URI}/detail`, undefined, {
|
|
params: { id }
|
|
});
|
|
}
|
|
|
|
async function create(user: ManagedUser): Promise<ManagedUser> {
|
|
return await axios.post(`${BASE_URI}/create`, withCurrentStoreId(user));
|
|
}
|
|
|
|
async function update(user: ManagedUser): Promise<ManagedUser> {
|
|
return await axios.post(`${BASE_URI}/update`, withCurrentStoreId(user));
|
|
}
|
|
|
|
async function transferStore(user: ManagedUser): Promise<ManagedUser> {
|
|
return await axios.post(`${BASE_URI}/transfer/store`, user);
|
|
}
|
|
|
|
async function remove(id: string): Promise<void> {
|
|
return await axios.post(`${BASE_URI}/delete`, undefined, {
|
|
params: { id }
|
|
});
|
|
}
|
|
|
|
async function roleList(): Promise<Role[]> {
|
|
return await axios.post(`${BASE_URI}/role/list`);
|
|
}
|
|
|
|
async function invite(request: InviteRequest): Promise<InviteResult> {
|
|
return await axios.post(`${BASE_URI}/invite`, request);
|
|
}
|
|
|
|
async function validateInvite(code: string): Promise<InviteValidateResult> {
|
|
return await axios.post(`${BASE_URI}/invite/validate`, { code });
|
|
}
|
|
|
|
async function registerByInvite(request: InviteRegisterRequest): Promise<LoginResponse> {
|
|
return await axios.post(`${BASE_URI}/invite/register`, request);
|
|
}
|
|
|
|
export default {
|
|
list,
|
|
detail,
|
|
create,
|
|
update,
|
|
transferStore,
|
|
remove,
|
|
roleList,
|
|
invite,
|
|
validateInvite,
|
|
registerByInvite
|
|
};
|