feat: add employee workspace operations admin
This commit is contained in:
+726
-4
@@ -7,6 +7,7 @@ import { http } from "@/utils/http";
|
||||
* 响应结构和状态枚举。后端统一挂在 `/api` 前缀下,由 Vite 代理转发。
|
||||
*/
|
||||
const API_PREFIX = "/api";
|
||||
const EMPLOYEE_OPTION_PAGE_SIZE = 100;
|
||||
|
||||
/** 后端员工与门店共用的启停状态枚举。 */
|
||||
export type EmployeeStatus = "ACTIVE" | "INACTIVE";
|
||||
@@ -130,6 +131,10 @@ export interface EmployeeListParams extends PageParams {
|
||||
keyword?: string;
|
||||
}
|
||||
|
||||
export type EmployeeOptionParams = Partial<
|
||||
Pick<EmployeeListParams, "storeId" | "status" | "keyword">
|
||||
>;
|
||||
|
||||
export interface StoreListParams extends PageParams {
|
||||
includeInactive?: boolean;
|
||||
status?: StoreStatus;
|
||||
@@ -168,6 +173,153 @@ export interface EmployeePasswordPayload {
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
export interface EmployeePasswordResetPayload {
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface EmployeePasswordResetResult {
|
||||
employeeId: number;
|
||||
temporaryPassword: string;
|
||||
}
|
||||
|
||||
export type AnnouncementImportance = "NORMAL" | "IMPORTANT" | "URGENT";
|
||||
export type AnnouncementStatus = "DRAFT" | "PUBLISHED" | "ARCHIVED";
|
||||
export type AnnouncementTargetScope =
|
||||
| "ALL_STORES"
|
||||
| "STORES"
|
||||
| "ROLES"
|
||||
| "EMPLOYEES";
|
||||
|
||||
export interface Announcement {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
importance: AnnouncementImportance;
|
||||
targetScope: AnnouncementTargetScope;
|
||||
targetStoreIds: number[];
|
||||
targetRoleIds: number[];
|
||||
targetEmployeeIds: number[];
|
||||
status: AnnouncementStatus;
|
||||
publisherName: string | null;
|
||||
publishedAt: string | null;
|
||||
readCount: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface AnnouncementListParams extends PageParams {
|
||||
status?: AnnouncementStatus;
|
||||
importance?: AnnouncementImportance;
|
||||
keyword?: string;
|
||||
}
|
||||
|
||||
export interface AnnouncementPayload {
|
||||
title: string;
|
||||
content: string;
|
||||
importance: AnnouncementImportance;
|
||||
targetScope: AnnouncementTargetScope;
|
||||
targetStoreIds: number[];
|
||||
targetRoleIds: number[];
|
||||
targetEmployeeIds: number[];
|
||||
}
|
||||
|
||||
export type TaskStatus = "PENDING" | "IN_PROGRESS" | "COMPLETED" | "CANCELLED";
|
||||
export type TaskPriority = "LOW" | "NORMAL" | "HIGH" | "URGENT";
|
||||
|
||||
export interface TaskEvent {
|
||||
id: number;
|
||||
action: string;
|
||||
remark: string | null;
|
||||
operatorName: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
storeId: number;
|
||||
storeName: string;
|
||||
assigneeIds: number[];
|
||||
assigneeNames: string[];
|
||||
status: TaskStatus;
|
||||
priority: TaskPriority;
|
||||
deadlineAt: string | null;
|
||||
creatorName: string | null;
|
||||
events?: TaskEvent[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface TaskListParams extends PageParams {
|
||||
storeId?: number;
|
||||
employeeId?: number;
|
||||
status?: TaskStatus;
|
||||
priority?: TaskPriority;
|
||||
keyword?: string;
|
||||
}
|
||||
|
||||
export interface TaskPayload {
|
||||
title: string;
|
||||
description?: string | null;
|
||||
storeId: number;
|
||||
assigneeIds: number[];
|
||||
priority: TaskPriority;
|
||||
deadlineAt?: string | null;
|
||||
}
|
||||
|
||||
export type ShiftStatus = "SCHEDULED" | "CANCELLED" | "COMPLETED";
|
||||
|
||||
export interface Shift {
|
||||
id: number;
|
||||
storeId: number;
|
||||
storeName: string;
|
||||
employeeId: number;
|
||||
employeeName: string;
|
||||
position: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
status: ShiftStatus;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ShiftListParams extends PageParams {
|
||||
storeId?: number;
|
||||
employeeId?: number;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
}
|
||||
|
||||
export interface ShiftPayload {
|
||||
storeId: number;
|
||||
employeeId: number;
|
||||
position: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
}
|
||||
|
||||
export interface CredentialAudit {
|
||||
id: number;
|
||||
operatorName: string;
|
||||
targetEmployeeName: string;
|
||||
targetEmployeePhone: string | null;
|
||||
storeName: string | null;
|
||||
action: string;
|
||||
operatedAt: string;
|
||||
ip: string | null;
|
||||
userAgent: string | null;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface CredentialAuditListParams extends PageParams {
|
||||
operatorId?: number;
|
||||
targetEmployeeId?: number;
|
||||
storeId?: number;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
}
|
||||
|
||||
/** access-manage 后端普通响应包裹结构。 */
|
||||
export interface ApiResult<T> {
|
||||
success: boolean;
|
||||
@@ -186,6 +338,407 @@ export interface PaginatedData<T> {
|
||||
pagination: Pagination;
|
||||
}
|
||||
|
||||
type LegacyAnnouncementImportance = "LOW" | "HIGH";
|
||||
type BackendAnnouncementTargetType = "ALL" | "STORE" | "ROLE" | "EMPLOYEE";
|
||||
type BackendConcreteAnnouncementTargetType = Exclude<
|
||||
BackendAnnouncementTargetType,
|
||||
"ALL"
|
||||
>;
|
||||
|
||||
interface BackendAnnouncementTarget {
|
||||
type: BackendConcreteAnnouncementTargetType;
|
||||
id: number;
|
||||
}
|
||||
|
||||
interface BackendAnnouncement {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
level?: AnnouncementImportance | LegacyAnnouncementImportance;
|
||||
importance?: AnnouncementImportance | LegacyAnnouncementImportance;
|
||||
status: AnnouncementStatus;
|
||||
targetType?: BackendAnnouncementTargetType;
|
||||
targetScope?: AnnouncementTargetScope;
|
||||
targets?: BackendAnnouncementTarget[];
|
||||
targetStoreIds?: number[];
|
||||
targetRoleIds?: number[];
|
||||
targetEmployeeIds?: number[];
|
||||
publisherName?: string | null;
|
||||
publishedAt: string | null;
|
||||
readCount?: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
type BackendAnnouncementPayload = Omit<
|
||||
AnnouncementPayload,
|
||||
| "importance"
|
||||
| "targetScope"
|
||||
| "targetStoreIds"
|
||||
| "targetRoleIds"
|
||||
| "targetEmployeeIds"
|
||||
> & {
|
||||
level: AnnouncementImportance;
|
||||
targetType: BackendAnnouncementTargetType;
|
||||
targets: BackendAnnouncementTarget[];
|
||||
};
|
||||
|
||||
type BackendTaskStatus = TaskStatus | "CANCELED";
|
||||
|
||||
interface BackendTaskAssignee {
|
||||
id: number;
|
||||
name: string;
|
||||
phone?: string | null;
|
||||
}
|
||||
|
||||
interface BackendTaskEvent {
|
||||
id: number;
|
||||
action?: string;
|
||||
eventType?: string;
|
||||
remark?: string | null;
|
||||
comment?: string | null;
|
||||
operatorName?: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface BackendTask {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
storeId: number | null;
|
||||
storeName: string | null;
|
||||
assignees?: BackendTaskAssignee[];
|
||||
assigneeIds?: number[];
|
||||
assigneeNames?: string[];
|
||||
status: BackendTaskStatus;
|
||||
priority: TaskPriority;
|
||||
dueAt?: string | null;
|
||||
deadlineAt?: string | null;
|
||||
creatorName?: string | null;
|
||||
events?: BackendTaskEvent[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
type BackendTaskPayload = Omit<TaskPayload, "deadlineAt"> & {
|
||||
dueAt?: string | null;
|
||||
assignees?: number[];
|
||||
};
|
||||
|
||||
type BackendShiftStatus = ShiftStatus | "CANCELED";
|
||||
|
||||
interface BackendShift {
|
||||
id: number;
|
||||
storeId: number;
|
||||
storeName: string;
|
||||
employeeId: number;
|
||||
employeeName: string;
|
||||
roleName?: string | null;
|
||||
position?: string | null;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
status: BackendShiftStatus;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
type BackendShiftPayload = Omit<ShiftPayload, "position"> & {
|
||||
roleName?: string | null;
|
||||
status?: "SCHEDULED";
|
||||
};
|
||||
|
||||
interface BackendCredentialAudit {
|
||||
id: number;
|
||||
actorName?: string | null;
|
||||
operatorName?: string | null;
|
||||
targetEmployeeName: string;
|
||||
targetEmployeePhone?: string | null;
|
||||
storeName?: string | null;
|
||||
action: string;
|
||||
createdAt?: string;
|
||||
operatedAt?: string;
|
||||
ip: string | null;
|
||||
userAgent: string | null;
|
||||
reason: string | null;
|
||||
}
|
||||
|
||||
function mapApiResult<T, R>(
|
||||
result: ApiResult<T>,
|
||||
mapper: (data: T) => R
|
||||
): ApiResult<R> {
|
||||
return {
|
||||
...result,
|
||||
data: mapper(result.data)
|
||||
};
|
||||
}
|
||||
|
||||
function mapPaginatedData<T, R>(
|
||||
data: PaginatedData<T>,
|
||||
mapper: (item: T) => R
|
||||
): PaginatedData<R> {
|
||||
return {
|
||||
...data,
|
||||
items: data.items.map(mapper)
|
||||
};
|
||||
}
|
||||
|
||||
function hasOwn<T extends object>(data: T, key: keyof T) {
|
||||
return Object.prototype.hasOwnProperty.call(data, key);
|
||||
}
|
||||
|
||||
function toBackendDateTime(value?: string | null) {
|
||||
if (value === undefined) return undefined;
|
||||
if (!value) return null;
|
||||
|
||||
const normalizedValue = value.includes("T") ? value : value.replace(" ", "T");
|
||||
const date = new Date(normalizedValue);
|
||||
|
||||
return Number.isNaN(date.getTime()) ? value : date.toISOString();
|
||||
}
|
||||
|
||||
function normalizeAnnouncementImportance(
|
||||
value?: AnnouncementImportance | LegacyAnnouncementImportance | null
|
||||
): AnnouncementImportance {
|
||||
if (value === "URGENT" || value === "IMPORTANT" || value === "NORMAL") {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value === "HIGH" ? "IMPORTANT" : "NORMAL";
|
||||
}
|
||||
|
||||
function toBackendAnnouncementTargetType(
|
||||
scope: AnnouncementTargetScope
|
||||
): BackendAnnouncementTargetType {
|
||||
const scopeMap: Record<
|
||||
AnnouncementTargetScope,
|
||||
BackendAnnouncementTargetType
|
||||
> = {
|
||||
ALL_STORES: "ALL",
|
||||
STORES: "STORE",
|
||||
ROLES: "ROLE",
|
||||
EMPLOYEES: "EMPLOYEE"
|
||||
};
|
||||
|
||||
return scopeMap[scope];
|
||||
}
|
||||
|
||||
function toAnnouncementTargetScope(
|
||||
targetType?: BackendAnnouncementTargetType
|
||||
): AnnouncementTargetScope {
|
||||
const targetTypeMap: Record<
|
||||
BackendAnnouncementTargetType,
|
||||
AnnouncementTargetScope
|
||||
> = {
|
||||
ALL: "ALL_STORES",
|
||||
STORE: "STORES",
|
||||
ROLE: "ROLES",
|
||||
EMPLOYEE: "EMPLOYEES"
|
||||
};
|
||||
|
||||
return targetTypeMap[targetType ?? "ALL"];
|
||||
}
|
||||
|
||||
function getAnnouncementTargetIds(
|
||||
targets: BackendAnnouncementTarget[],
|
||||
type: BackendConcreteAnnouncementTargetType
|
||||
) {
|
||||
return targets
|
||||
.filter(target => target.type === type)
|
||||
.map(target => target.id);
|
||||
}
|
||||
|
||||
function toBackendAnnouncementPayload(
|
||||
data: Partial<AnnouncementPayload>
|
||||
): Partial<BackendAnnouncementPayload> {
|
||||
const payload: Partial<BackendAnnouncementPayload> = {};
|
||||
|
||||
if (hasOwn(data, "title")) payload.title = data.title;
|
||||
if (hasOwn(data, "content")) payload.content = data.content;
|
||||
if (hasOwn(data, "importance")) {
|
||||
payload.level = normalizeAnnouncementImportance(data.importance);
|
||||
}
|
||||
|
||||
if (hasOwn(data, "targetScope")) {
|
||||
payload.targetType = toBackendAnnouncementTargetType(
|
||||
data.targetScope ?? "ALL_STORES"
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
hasOwn(data, "targetScope") ||
|
||||
hasOwn(data, "targetStoreIds") ||
|
||||
hasOwn(data, "targetRoleIds") ||
|
||||
hasOwn(data, "targetEmployeeIds")
|
||||
) {
|
||||
const targetType =
|
||||
payload.targetType ??
|
||||
toBackendAnnouncementTargetType(data.targetScope ?? "ALL_STORES");
|
||||
const targetIds =
|
||||
targetType === "STORE"
|
||||
? (data.targetStoreIds ?? [])
|
||||
: targetType === "ROLE"
|
||||
? (data.targetRoleIds ?? [])
|
||||
: targetType === "EMPLOYEE"
|
||||
? (data.targetEmployeeIds ?? [])
|
||||
: [];
|
||||
|
||||
payload.targets =
|
||||
targetType === "ALL"
|
||||
? []
|
||||
: targetIds.map(id => ({
|
||||
type: targetType,
|
||||
id
|
||||
}));
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
function normalizeAnnouncement(
|
||||
announcement: BackendAnnouncement
|
||||
): Announcement {
|
||||
const targets = announcement.targets ?? [];
|
||||
const targetScope =
|
||||
announcement.targetScope ??
|
||||
toAnnouncementTargetScope(announcement.targetType);
|
||||
|
||||
return {
|
||||
id: announcement.id,
|
||||
title: announcement.title,
|
||||
content: announcement.content,
|
||||
importance: normalizeAnnouncementImportance(
|
||||
announcement.level ?? announcement.importance
|
||||
),
|
||||
targetScope,
|
||||
targetStoreIds:
|
||||
announcement.targetStoreIds ?? getAnnouncementTargetIds(targets, "STORE"),
|
||||
targetRoleIds:
|
||||
announcement.targetRoleIds ?? getAnnouncementTargetIds(targets, "ROLE"),
|
||||
targetEmployeeIds:
|
||||
announcement.targetEmployeeIds ??
|
||||
getAnnouncementTargetIds(targets, "EMPLOYEE"),
|
||||
status: announcement.status,
|
||||
publisherName: announcement.publisherName ?? null,
|
||||
publishedAt: announcement.publishedAt,
|
||||
readCount: announcement.readCount ?? 0,
|
||||
createdAt: announcement.createdAt,
|
||||
updatedAt: announcement.updatedAt
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTaskStatus(status: BackendTaskStatus): TaskStatus {
|
||||
return status === "CANCELED" ? "CANCELLED" : status;
|
||||
}
|
||||
|
||||
function normalizeShiftStatus(status: BackendShiftStatus): ShiftStatus {
|
||||
return status === "CANCELED" ? "CANCELLED" : status;
|
||||
}
|
||||
|
||||
function toBackendTaskStatus(status?: BackendTaskStatus) {
|
||||
return status === "CANCELED" ? "CANCELLED" : status;
|
||||
}
|
||||
|
||||
function normalizeTask(task: BackendTask): Task {
|
||||
const assignees = task.assignees ?? [];
|
||||
|
||||
return {
|
||||
id: task.id,
|
||||
title: task.title,
|
||||
description: task.description,
|
||||
storeId: task.storeId ?? 0,
|
||||
storeName: task.storeName ?? "-",
|
||||
assigneeIds: task.assigneeIds ?? assignees.map(assignee => assignee.id),
|
||||
assigneeNames:
|
||||
task.assigneeNames ?? assignees.map(assignee => assignee.name),
|
||||
status: normalizeTaskStatus(task.status),
|
||||
priority: task.priority,
|
||||
deadlineAt: task.deadlineAt ?? task.dueAt ?? null,
|
||||
creatorName: task.creatorName ?? null,
|
||||
events: task.events?.map(event => ({
|
||||
id: event.id,
|
||||
action: event.action ?? event.eventType ?? "",
|
||||
remark: event.remark ?? event.comment ?? null,
|
||||
operatorName: event.operatorName ?? null,
|
||||
createdAt: event.createdAt
|
||||
})),
|
||||
createdAt: task.createdAt,
|
||||
updatedAt: task.updatedAt
|
||||
};
|
||||
}
|
||||
|
||||
function toBackendTaskPayload(
|
||||
data: Partial<TaskPayload>
|
||||
): Partial<BackendTaskPayload> {
|
||||
const payload = { ...data } as Partial<BackendTaskPayload> &
|
||||
Partial<TaskPayload>;
|
||||
|
||||
delete payload.deadlineAt;
|
||||
|
||||
if (hasOwn(data, "deadlineAt")) {
|
||||
payload.dueAt = toBackendDateTime(data.deadlineAt);
|
||||
}
|
||||
|
||||
if (hasOwn(data, "assigneeIds")) {
|
||||
payload.assignees = data.assigneeIds;
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
function normalizeShift(shift: BackendShift): Shift {
|
||||
return {
|
||||
id: shift.id,
|
||||
storeId: shift.storeId,
|
||||
storeName: shift.storeName,
|
||||
employeeId: shift.employeeId,
|
||||
employeeName: shift.employeeName,
|
||||
position: shift.position ?? shift.roleName ?? "",
|
||||
startAt: shift.startAt,
|
||||
endAt: shift.endAt,
|
||||
status: normalizeShiftStatus(shift.status),
|
||||
createdAt: shift.createdAt,
|
||||
updatedAt: shift.updatedAt
|
||||
};
|
||||
}
|
||||
|
||||
function toBackendShiftPayload(
|
||||
data: Partial<ShiftPayload>
|
||||
): Partial<BackendShiftPayload> {
|
||||
const payload = { ...data } as Partial<BackendShiftPayload> &
|
||||
Partial<ShiftPayload>;
|
||||
|
||||
delete payload.position;
|
||||
|
||||
if (hasOwn(data, "position")) {
|
||||
payload.roleName = data.position?.trim() || null;
|
||||
}
|
||||
if (hasOwn(data, "startAt")) {
|
||||
payload.startAt = toBackendDateTime(data.startAt) ?? "";
|
||||
}
|
||||
if (hasOwn(data, "endAt")) {
|
||||
payload.endAt = toBackendDateTime(data.endAt) ?? "";
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
function normalizeCredentialAudit(
|
||||
audit: BackendCredentialAudit
|
||||
): CredentialAudit {
|
||||
return {
|
||||
id: audit.id,
|
||||
operatorName: audit.operatorName ?? audit.actorName ?? "-",
|
||||
targetEmployeeName: audit.targetEmployeeName,
|
||||
targetEmployeePhone: audit.targetEmployeePhone ?? null,
|
||||
storeName: audit.storeName ?? null,
|
||||
action: audit.action,
|
||||
operatedAt: audit.operatedAt ?? audit.createdAt ?? "",
|
||||
ip: audit.ip,
|
||||
userAgent: audit.userAgent,
|
||||
reason: audit.reason ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
export type PermissionPolicyResult = ApiResult<PermissionPolicy[]>;
|
||||
export type PermissionDefinitionsResult = ApiResult<PermissionDefinitions>;
|
||||
|
||||
@@ -282,6 +835,31 @@ export const listEmployees = (params: EmployeeListParams) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const listEmployeeOptions = async (
|
||||
params: EmployeeOptionParams = {}
|
||||
): Promise<ApiResult<Employee[]>> => {
|
||||
const items: Employee[] = [];
|
||||
let page = 1;
|
||||
let totalPages = 1;
|
||||
|
||||
do {
|
||||
const result = await listEmployees({
|
||||
...params,
|
||||
page,
|
||||
pageSize: EMPLOYEE_OPTION_PAGE_SIZE
|
||||
});
|
||||
|
||||
items.push(...result.data.items);
|
||||
totalPages = result.data.pagination.totalPages;
|
||||
page += 1;
|
||||
} while (page <= totalPages);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: items
|
||||
};
|
||||
};
|
||||
|
||||
export const getEmployee = (id: number) => {
|
||||
return http.request<ApiResult<Employee>>(
|
||||
"get",
|
||||
@@ -322,10 +900,14 @@ export const updateEmployeePassword = (
|
||||
);
|
||||
};
|
||||
|
||||
export const resetEmployeePassword = (id: number) => {
|
||||
return http.request<ApiResult<Employee>>(
|
||||
"patch",
|
||||
`${API_PREFIX}/employees/${id}/password/reset`
|
||||
export const resetEmployeePassword = (
|
||||
id: number,
|
||||
data: EmployeePasswordResetPayload
|
||||
) => {
|
||||
return http.request<ApiResult<EmployeePasswordResetResult>>(
|
||||
"post",
|
||||
`${API_PREFIX}/admin/employees/${id}/password/reset`,
|
||||
{ data }
|
||||
);
|
||||
};
|
||||
|
||||
@@ -360,3 +942,143 @@ export const updateRolePermissions = (
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/** 员工工作台运营接口:公告、任务、排班和凭据审计均按后台 admin 路径对接。 */
|
||||
export const listAnnouncements = (params: AnnouncementListParams) => {
|
||||
const { importance, ...restParams } = params;
|
||||
|
||||
return http
|
||||
.request<ApiResult<PaginatedData<BackendAnnouncement>>>(
|
||||
"get",
|
||||
`${API_PREFIX}/admin/announcements`,
|
||||
{
|
||||
params: {
|
||||
...restParams,
|
||||
level: importance
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(result =>
|
||||
mapApiResult(result, data =>
|
||||
mapPaginatedData(data, normalizeAnnouncement)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const createAnnouncement = (data: AnnouncementPayload) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendAnnouncement>
|
||||
>("post", `${API_PREFIX}/admin/announcements`, { data: toBackendAnnouncementPayload(data) })
|
||||
.then(result => mapApiResult(result, normalizeAnnouncement));
|
||||
};
|
||||
|
||||
export const updateAnnouncement = (
|
||||
id: number,
|
||||
data: Partial<AnnouncementPayload>
|
||||
) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendAnnouncement>
|
||||
>("patch", `${API_PREFIX}/admin/announcements/${id}`, { data: toBackendAnnouncementPayload(data) })
|
||||
.then(result => mapApiResult(result, normalizeAnnouncement));
|
||||
};
|
||||
|
||||
export const publishAnnouncement = (id: number) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendAnnouncement>
|
||||
>("post", `${API_PREFIX}/admin/announcements/${id}/publish`)
|
||||
.then(result => mapApiResult(result, normalizeAnnouncement));
|
||||
};
|
||||
|
||||
export const archiveAnnouncement = (id: number) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendAnnouncement>
|
||||
>("post", `${API_PREFIX}/admin/announcements/${id}/archive`)
|
||||
.then(result => mapApiResult(result, normalizeAnnouncement));
|
||||
};
|
||||
|
||||
export const listTasks = (params: TaskListParams) => {
|
||||
return http
|
||||
.request<ApiResult<PaginatedData<BackendTask>>>(
|
||||
"get",
|
||||
`${API_PREFIX}/admin/tasks`,
|
||||
{
|
||||
params: {
|
||||
...params,
|
||||
status: toBackendTaskStatus(params.status)
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(result =>
|
||||
mapApiResult(result, data => mapPaginatedData(data, normalizeTask))
|
||||
);
|
||||
};
|
||||
|
||||
export const createTask = (data: TaskPayload) => {
|
||||
return http
|
||||
.request<ApiResult<BackendTask>>("post", `${API_PREFIX}/admin/tasks`, {
|
||||
data: toBackendTaskPayload(data)
|
||||
})
|
||||
.then(result => mapApiResult(result, normalizeTask));
|
||||
};
|
||||
|
||||
export const updateTask = (id: number, data: Partial<TaskPayload>) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendTask>
|
||||
>("patch", `${API_PREFIX}/admin/tasks/${id}`, { data: toBackendTaskPayload(data) })
|
||||
.then(result => mapApiResult(result, normalizeTask));
|
||||
};
|
||||
|
||||
export const cancelTask = (id: number) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendTask>
|
||||
>("post", `${API_PREFIX}/admin/tasks/${id}/cancel`)
|
||||
.then(result => mapApiResult(result, normalizeTask));
|
||||
};
|
||||
|
||||
export const listShifts = (params: ShiftListParams) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<PaginatedData<BackendShift>>
|
||||
>("get", `${API_PREFIX}/admin/shifts`, { params })
|
||||
.then(result =>
|
||||
mapApiResult(result, data => mapPaginatedData(data, normalizeShift))
|
||||
);
|
||||
};
|
||||
|
||||
export const createShift = (data: ShiftPayload) => {
|
||||
return http
|
||||
.request<ApiResult<BackendShift>>("post", `${API_PREFIX}/admin/shifts`, {
|
||||
data: toBackendShiftPayload(data)
|
||||
})
|
||||
.then(result => mapApiResult(result, normalizeShift));
|
||||
};
|
||||
|
||||
export const updateShift = (id: number, data: Partial<ShiftPayload>) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<BackendShift>
|
||||
>("patch", `${API_PREFIX}/admin/shifts/${id}`, { data: toBackendShiftPayload(data) })
|
||||
.then(result => mapApiResult(result, normalizeShift));
|
||||
};
|
||||
|
||||
export const cancelShift = (id: number) => {
|
||||
return http.request<void>("delete", `${API_PREFIX}/admin/shifts/${id}`);
|
||||
};
|
||||
|
||||
export const listCredentialAudits = (params: CredentialAuditListParams) => {
|
||||
return http
|
||||
.request<
|
||||
ApiResult<PaginatedData<BackendCredentialAudit>>
|
||||
>("get", `${API_PREFIX}/admin/credential-audits`, { params })
|
||||
.then(result =>
|
||||
mapApiResult(result, data =>
|
||||
mapPaginatedData(data, normalizeCredentialAudit)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user