style: 统一全仓代码格式
This commit is contained in:
1 parent
d811478d0f
commit
8033cabff9
30 files changed
+1183
-187
No files matched your search
@@ -2,16 +2,36 @@ import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-br
|
||||
import { HTTP_STATUS } from "@personal-brand/types";
|
||||
|
||||
export interface MiniappRequestAdapter {
|
||||
request(options: { url: string; method: string; header: Record<string, string>; data?: string }): Promise<{ statusCode: number; data: unknown }>;
|
||||
request(options: {
|
||||
url: string;
|
||||
method: string;
|
||||
header: Record<string, string>;
|
||||
data?: string;
|
||||
}): Promise<{ statusCode: number; data: unknown }>;
|
||||
}
|
||||
|
||||
export function createMiniappClient(baseUrl: string, adapter: MiniappRequestAdapter, token?: string): ApiClient {
|
||||
export function createMiniappClient(
|
||||
baseUrl: string,
|
||||
adapter: MiniappRequestAdapter,
|
||||
token?: string,
|
||||
): ApiClient {
|
||||
const fetcher: FetchLike = async (url, init) => {
|
||||
const response = await adapter.request({ url, method: init?.method ?? "GET", header: init?.headers ?? {}, ...(init?.body ? { data: init.body } : {}) });
|
||||
return { status: response.statusCode, ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST, json: () => Promise.resolve(response.data) };
|
||||
const response = await adapter.request({
|
||||
url,
|
||||
method: init?.method ?? "GET",
|
||||
header: init?.headers ?? {},
|
||||
...(init?.body ? { data: init.body } : {}),
|
||||
});
|
||||
return {
|
||||
status: response.statusCode,
|
||||
ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST,
|
||||
json: () => Promise.resolve(response.data),
|
||||
};
|
||||
};
|
||||
return new ApiClient({ baseUrl, fetcher, ...(token ? { token } : {}) });
|
||||
}
|
||||
|
||||
export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise<void> { await client.createCustomerBooking(input); }
|
||||
export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise<void> {
|
||||
await client.createCustomerBooking(input);
|
||||
}
|
||||
export const miniappName = "personal-brand-miniapp";
|
||||
Reference in new issue
Block a user