45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { fetchWithAuth } from "./client";
|
|
|
|
function buildQuery(params: Record<string, string | number | boolean | undefined>): string {
|
|
const qs = Object.entries(params)
|
|
.filter(([, v]) => v !== undefined)
|
|
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
.join("&");
|
|
return qs ? `?${qs}` : "";
|
|
}
|
|
|
|
export const suggestionsApi = {
|
|
/** 获取建议列表 */
|
|
getSuggestions: (
|
|
token: string,
|
|
brandId: string,
|
|
params?: Record<string, string | number>
|
|
) =>
|
|
fetchWithAuth(
|
|
`/api/v1/brands/${brandId}/suggestions${buildQuery(params || {})}`,
|
|
{},
|
|
token
|
|
),
|
|
|
|
/** 重新生成建议 */
|
|
regenerateSuggestions: (token: string, brandId: string) =>
|
|
fetchWithAuth(
|
|
`/api/v1/brands/${brandId}/suggestions/regenerate`,
|
|
{ method: "POST" },
|
|
token
|
|
),
|
|
|
|
/** 更新建议状态 */
|
|
updateSuggestionStatus: (
|
|
token: string,
|
|
brandId: string,
|
|
suggestionId: string,
|
|
status: string
|
|
) =>
|
|
fetchWithAuth(
|
|
`/api/v1/brands/${brandId}/suggestions/${suggestionId}/status`,
|
|
{ method: "PUT", body: JSON.stringify({ status }) },
|
|
token
|
|
),
|
|
};
|