refactor: 集中管理共享状态常量
This commit is contained in:
1 parent
868a4251ce
commit
3b05df6edf
3 files changed
+21
-2
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
"name": "@personal-brand/miniapp",
|
"name": "@personal-brand/miniapp",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": { "@personal-brand/api-client": "workspace:*" },
|
"dependencies": { "@personal-brand/api-client": "workspace:*", "@personal-brand/types": "workspace:*" },
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-brand/api-client";
|
import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-brand/api-client";
|
||||||
|
import { HTTP_STATUS } from "@personal-brand/types";
|
||||||
|
|
||||||
export interface MiniappRequestAdapter {
|
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 }>;
|
||||||
@@ -7,7 +8,7 @@ export interface MiniappRequestAdapter {
|
|||||||
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 fetcher: FetchLike = async (url, init) => {
|
||||||
const response = await adapter.request({ url, method: init?.method ?? "GET", header: init?.headers ?? {}, ...(init?.body ? { data: init.body } : {}) });
|
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 >= 200 && response.statusCode < 300, json: () => Promise.resolve(response.data) };
|
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 } : {}) });
|
return new ApiClient({ baseUrl, fetcher, ...(token ? { token } : {}) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,24 @@ export type ContactPreference = "wechat" | "phone" | "none";
|
|||||||
export type FulfillmentType = "pickup" | "delivery";
|
export type FulfillmentType = "pickup" | "delivery";
|
||||||
export type OrderStatus = BookingStatus;
|
export type OrderStatus = BookingStatus;
|
||||||
|
|
||||||
|
export const HTTP_STATUS = {
|
||||||
|
OK: 200,
|
||||||
|
CREATED: 201,
|
||||||
|
BAD_REQUEST: 400,
|
||||||
|
UNAUTHORIZED: 401,
|
||||||
|
FORBIDDEN: 403,
|
||||||
|
NOT_FOUND: 404,
|
||||||
|
INTERNAL_SERVER_ERROR: 500,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const BOOKING_STATUS = {
|
||||||
|
RECEIVED: "received",
|
||||||
|
CONTACTING: "contacting",
|
||||||
|
CONFIRMED: "confirmed",
|
||||||
|
COMPLETED: "completed",
|
||||||
|
CANCELLED: "cancelled",
|
||||||
|
} as const satisfies Record<Uppercase<BookingStatus>, BookingStatus>;
|
||||||
|
|
||||||
export interface PublicService {
|
export interface PublicService {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
Reference in new issue
Block a user