Initial role user app
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { AnnouncementDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function POST(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return proxyBackendJson<AnnouncementDetail>(`/mobile/announcements/${encodeURIComponent(id)}/read`, {
|
||||
method: "POST"
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { AnnouncementDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return proxyBackendJson<AnnouncementDetail>(`/mobile/announcements/${encodeURIComponent(id)}`);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const search = new URL(request.url).search;
|
||||
return proxyBackendJson<unknown>(`/mobile/announcements${search}`);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { ShiftSummary } from "@/lib/types";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const search = new URL(request.url).search;
|
||||
return proxyBackendJson<ShiftSummary[]>(`/mobile/shifts${search}`);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { ShiftSummary } from "@/lib/types";
|
||||
|
||||
export async function GET() {
|
||||
return proxyBackendJson<ShiftSummary | null>("/mobile/shifts/today");
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { backendErrorResponse, BackendError, backendRequest } from "@/lib/backend";
|
||||
import type { ApiEnvelope, AuthUser, StoreEmployee } from "@/lib/types";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const user = await backendRequest<AuthUser>("/auth/me");
|
||||
|
||||
if (!user.storeId) {
|
||||
return Response.json({ success: true, data: [] } satisfies ApiEnvelope<StoreEmployee[]>);
|
||||
}
|
||||
|
||||
const search = new URLSearchParams({
|
||||
storeId: String(user.storeId),
|
||||
page: "1",
|
||||
pageSize: "100"
|
||||
});
|
||||
|
||||
try {
|
||||
const employees = await backendRequest<unknown>(`/employees?${search.toString()}`);
|
||||
return Response.json({ success: true, data: employees } satisfies ApiEnvelope<unknown>);
|
||||
} catch (error) {
|
||||
if (error instanceof BackendError && [403, 404].includes(error.status)) {
|
||||
return Response.json({ success: true, data: [] } satisfies ApiEnvelope<StoreEmployee[]>);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
return backendErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { backendErrorResponse, BackendError, backendRequest } from "@/lib/backend";
|
||||
import type { ApiEnvelope, AuthUser, StoreDetail } from "@/lib/types";
|
||||
|
||||
function fallbackStore(user: AuthUser): StoreDetail | null {
|
||||
if (!user.storeId) return null;
|
||||
|
||||
return {
|
||||
id: user.storeId,
|
||||
name: user.storeName ?? "当前门店",
|
||||
address: null,
|
||||
phone: null,
|
||||
status: undefined,
|
||||
employees: []
|
||||
};
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const user = await backendRequest<AuthUser>("/auth/me");
|
||||
|
||||
if (!user.storeId) {
|
||||
return Response.json({ success: true, data: null } satisfies ApiEnvelope<StoreDetail | null>);
|
||||
}
|
||||
|
||||
try {
|
||||
const store = await backendRequest<StoreDetail>(`/stores/${user.storeId}`);
|
||||
return Response.json({ success: true, data: store } satisfies ApiEnvelope<StoreDetail>);
|
||||
} catch (error) {
|
||||
if (error instanceof BackendError && [403, 404].includes(error.status)) {
|
||||
return Response.json({ success: true, data: fallbackStore(user) } satisfies ApiEnvelope<StoreDetail | null>);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
return backendErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { TaskDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function POST(request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const body = await request.text();
|
||||
|
||||
return proxyBackendJson<TaskDetail>(`/mobile/tasks/${encodeURIComponent(id)}/comment`, {
|
||||
method: "POST",
|
||||
body: body || undefined
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { TaskDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function POST(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return proxyBackendJson<TaskDetail>(`/mobile/tasks/${encodeURIComponent(id)}/complete`, {
|
||||
method: "POST"
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { TaskDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return proxyBackendJson<TaskDetail>(`/mobile/tasks/${encodeURIComponent(id)}`);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
import type { TaskDetail } from "@/lib/types";
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function POST(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return proxyBackendJson<TaskDetail>(`/mobile/tasks/${encodeURIComponent(id)}/start`, {
|
||||
method: "POST"
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { proxyBackendJson } from "@/lib/backend";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const search = new URL(request.url).search;
|
||||
return proxyBackendJson<unknown>(`/mobile/tasks${search}`);
|
||||
}
|
||||
Reference in New Issue
Block a user