feat(assist-platform): add approve command and support direct link generation for enter
This commit is contained in:
1 parent
e98948529e
commit
f0fc7148ec
11 files changed
+806
-455
No files matched your search
@@ -309,3 +309,73 @@ export async function createAssistTicketApi(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export interface ApproveAssistTicketApiParams {
|
||||
ticketId: string;
|
||||
corporationId: string;
|
||||
status?: number; // 默认 1 (通过授权 / 已提供)
|
||||
}
|
||||
|
||||
export interface ApproveAssistTicketApiResponse {
|
||||
id: string;
|
||||
corporationId: string;
|
||||
status: number;
|
||||
active: boolean;
|
||||
startTime: number;
|
||||
endTime: number;
|
||||
applyMessage: string;
|
||||
userName?: string;
|
||||
responsibleUserName?: string;
|
||||
}
|
||||
|
||||
export async function approveAssistTicketApi(
|
||||
client: KyInstance,
|
||||
params: ApproveAssistTicketApiParams
|
||||
): Promise<ApproveAssistTicketApiResponse> {
|
||||
const { ticketId, corporationId, status = 1 } = params;
|
||||
if (!ticketId || !ticketId.trim()) {
|
||||
throw new BusinessError("必须指定协助工单编号 (ticketId)");
|
||||
}
|
||||
if (!corporationId || !corporationId.trim()) {
|
||||
throw new BusinessError("必须指定目标企业 ID (corporationId)");
|
||||
}
|
||||
|
||||
const cleanTicketId = ticketId.trim();
|
||||
const cleanCorpId = corporationId.trim();
|
||||
|
||||
try {
|
||||
const res = await client
|
||||
.put(`api/assistPlatform/$${cleanTicketId}/updateStatus`, {
|
||||
searchParams: {
|
||||
corpId: cleanCorpId,
|
||||
},
|
||||
json: {
|
||||
id: cleanTicketId,
|
||||
status,
|
||||
},
|
||||
})
|
||||
.json<{
|
||||
value?: Record<string, unknown>;
|
||||
}>();
|
||||
|
||||
const val = res.value || {};
|
||||
return {
|
||||
id: String(val.id || cleanTicketId),
|
||||
corporationId: String(val.corporationId || cleanCorpId),
|
||||
status: typeof val.status === "number" ? val.status : status,
|
||||
active: Boolean(val.active),
|
||||
startTime: Number(val.startTime || 0),
|
||||
endTime: Number(val.endTime || 0),
|
||||
applyMessage: String(val.applyMessage || ""),
|
||||
userName: val.userName ? String(val.userName) : undefined,
|
||||
responsibleUserName: val.responsibleUserName ? String(val.responsibleUserName) : undefined,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error && (error.name === "AuthenticationError" || error.name === "BusinessError")) {
|
||||
throw error;
|
||||
}
|
||||
throw new EkbApiError(
|
||||
`审批协助工单失败: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test";
|
||||
import ky from "ky";
|
||||
import {
|
||||
applyAssistTicket,
|
||||
approveAssistTicket,
|
||||
findStaff,
|
||||
generateAssistSession,
|
||||
getCorporationDetail,
|
||||
@@ -218,4 +219,36 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
expect(res.id).toBe("ID01XelIEeCbw3");
|
||||
expect(res.status).toBe(0);
|
||||
});
|
||||
|
||||
it("approveAssistTicket 审批通过协助工单", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
expect(req.url).toContain("assistPlatform/$ID01Xeno3GpoNV/updateStatus");
|
||||
expect(req.url).toContain("corpId=ID01ofWoOC1wiX");
|
||||
expect(req.method).toBe("PUT");
|
||||
const body = (await req.json()) as any;
|
||||
expect(body.id).toBe("ID01Xeno3GpoNV");
|
||||
expect(body.status).toBe(1);
|
||||
return Response.json({
|
||||
value: {
|
||||
id: "ID01Xeno3GpoNV",
|
||||
corporationId: "ID01ofWoOC1wiX",
|
||||
status: 1,
|
||||
active: true,
|
||||
startTime: 1792552656850,
|
||||
endTime: 1792595856850,
|
||||
applyMessage: "测试二次授权接口",
|
||||
userName: "谢子豪",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const res = await approveAssistTicket(client, {
|
||||
ticketId: "ID01Xeno3GpoNV",
|
||||
corporationId: "ID01ofWoOC1wiX",
|
||||
});
|
||||
expect(res.id).toBe("ID01Xeno3GpoNV");
|
||||
expect(res.status).toBe(1);
|
||||
expect(res.active).toBe(true);
|
||||
expect(res.userName).toBe("谢子豪");
|
||||
});
|
||||
});
|
||||
@@ -3,12 +3,15 @@ import { BusinessError, NotFoundError } from "../../core/errors.js";
|
||||
import { importFromLink, type ImportFromLinkOptions } from "../../core/auth/link-import.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import {
|
||||
approveAssistTicketApi,
|
||||
createAssistTicketApi,
|
||||
getAssistTokenApi,
|
||||
getCorporationDetailApi,
|
||||
getStaffApi,
|
||||
searchAssistTicketsApi,
|
||||
searchCorporationsApi,
|
||||
type ApproveAssistTicketApiParams,
|
||||
type ApproveAssistTicketApiResponse,
|
||||
type CreateAssistTicketApiParams,
|
||||
type CreateAssistTicketApiResponse,
|
||||
type SearchCorporationsApiParams,
|
||||
@@ -58,6 +61,13 @@ export async function applyAssistTicket(
|
||||
return await createAssistTicketApi(client, params);
|
||||
}
|
||||
|
||||
export async function approveAssistTicket(
|
||||
client: KyInstance,
|
||||
params: ApproveAssistTicketApiParams
|
||||
): Promise<ApproveAssistTicketApiResponse> {
|
||||
return await approveAssistTicketApi(client, params);
|
||||
}
|
||||
|
||||
export interface GenerateAssistSessionParams {
|
||||
corpId: string;
|
||||
ticketId?: string;
|
||||
@@ -165,7 +175,11 @@ export async function importAssistSessionToLocal(
|
||||
elevate: params.elevate ?? true,
|
||||
};
|
||||
|
||||
const corpConfig = await importFromLink(sessionResult.loginUrl, importOptions);
|
||||
const linkToImport = sessionResult.loginUrl.includes("accessToken=")
|
||||
? sessionResult.loginUrl
|
||||
: `https://app.ekuaibao.com/web/thirdparty.html?accessToken=${encodeURIComponent(sessionResult.token)}&ekbCorpId=${encodeURIComponent(sessionResult.corporationId)}${sessionResult.staffId ? `&staffId=${encodeURIComponent(sessionResult.staffId)}` : ""}`;
|
||||
|
||||
const corpConfig = await importFromLink(linkToImport, importOptions);
|
||||
|
||||
return {
|
||||
sessionResult,
|
||||
|
||||
Reference in new issue
Block a user