feat: add CLI submitted task query
This commit is contained in:
1 parent
12247fd350
commit
97abdb4f96
7 files changed
+62
-7
No files matched your search
@@ -23,6 +23,13 @@ function approvedDateFilter(options: TaskQueryOptions): string {
|
||||
return `&&((approvedFlow.updateTime > ${from}) && (approvedFlow.updateTime < ${to}))`;
|
||||
}
|
||||
|
||||
function submittedDateFilter(options: TaskQueryOptions): string {
|
||||
if (options.from === undefined && options.to === undefined) return "";
|
||||
const from = options.from ?? 0;
|
||||
const to = options.to ?? 32503680000000;
|
||||
return `&&((form.submitDate > ${from}) && (form.submitDate < ${to}))`;
|
||||
}
|
||||
|
||||
function selectForBacklog(): string {
|
||||
return "flowId(ownerId(id,name,enName),form(title,code,specificationId(active,id,name,enName,nameSpell,code),submitDate,submitterId(id,name,enName,nickName,code,email,cellphone,note),reviewStatus,expenseMoney,loanMoney,requisitionMoney,payMoney),`...`),`...`";
|
||||
}
|
||||
@@ -40,6 +47,23 @@ export async function fetchTaskPage(
|
||||
const start = options.start ?? 0;
|
||||
const count = options.count ?? 20;
|
||||
|
||||
if (view === "submitted") {
|
||||
const response = await client.post("api/flow/v1/flows/my", {
|
||||
searchParams: {
|
||||
type: "home5",
|
||||
delegatedFilter: "DELEGATE_TO_ME",
|
||||
corpId,
|
||||
},
|
||||
json: {
|
||||
filterBy: `(state.in("rejected","draft","sending","receiving","receivingExcep","approving","pending","paying","paid"))&&(INSTR(form.specificationId,"${corpId}:system:对账单")==0)${submittedDateFilter(options)}`,
|
||||
limit: { start, count },
|
||||
orderBy: [{ value: "form.submitDate", order: "DESC" }],
|
||||
},
|
||||
});
|
||||
const json = (await response.json()) as { count?: number; items?: Record<string, unknown>[] };
|
||||
return { count: json.count ?? json.items?.length ?? 0, items: json.items ?? [] };
|
||||
}
|
||||
|
||||
if (view === "cc") {
|
||||
const searchParams = new URLSearchParams({ corpId });
|
||||
searchParams.append("join", "flowId.id,nodeState,/flow/v2/backlogs/state");
|
||||
|
||||
@@ -28,4 +28,25 @@ describe("Task Domain - 待办任务模型", () => {
|
||||
expect(item.amount?.value).toBe("120.00");
|
||||
expect(item.actions).toEqual(["freeflow.agree", "freeflow.reject"]);
|
||||
});
|
||||
|
||||
test("normalizes flows returned by the submitted-bills endpoint", () => {
|
||||
const item = normalizeTask({
|
||||
flow: {
|
||||
id: "flow-submitted-1",
|
||||
state: "approving",
|
||||
ownerId: { id: "staff-1", name: "张三" },
|
||||
},
|
||||
form: {
|
||||
code: "BX26000002",
|
||||
title: "差旅报销",
|
||||
specification: { name: "差旅报销单" },
|
||||
submitterId: { id: "staff-1", name: "张三", code: "1001" },
|
||||
amount: { standard: "88.00", standardStrCode: "CNY", standardSymbol: "¥" },
|
||||
},
|
||||
});
|
||||
expect(item.taskId).toBe("flow-submitted-1");
|
||||
expect(item.state).toBe("approving");
|
||||
expect(item.templateName).toBe("差旅报销单");
|
||||
expect(item.amount?.value).toBe("88.00");
|
||||
});
|
||||
});
|
||||
@@ -29,11 +29,11 @@ function money(value: unknown): TaskItem["amount"] {
|
||||
}
|
||||
|
||||
export function normalizeTask(raw: Record<string, unknown>): TaskItem {
|
||||
const flow = record(raw.flowId);
|
||||
const flow = record(raw.flowId ?? raw.flow);
|
||||
const form = record(flow.form ?? raw.form);
|
||||
const nodeState = record(raw.nodeState ?? flow.nodeState);
|
||||
const amount = money(form.expenseMoney ?? form.payMoney ?? form.requisitionMoney ?? form.loanMoney);
|
||||
const specification = record(form.specificationId);
|
||||
const amount = money(form.expenseMoney ?? form.payMoney ?? form.requisitionMoney ?? form.loanMoney ?? form.amount);
|
||||
const specification = record(form.specificationId ?? form.specification);
|
||||
const submitter = person(form.submitterId);
|
||||
const owner = person(flow.ownerId ?? raw.ownerId);
|
||||
const actionsByStaff = record(flow.actions ?? raw.actions);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const TaskViewSchema = z.enum(["todo", "approved", "processed", "cc"]);
|
||||
export const TaskViewSchema = z.enum(["todo", "approved", "processed", "cc", "submitted"]);
|
||||
export type TaskView = z.infer<typeof TaskViewSchema>;
|
||||
|
||||
export interface TaskQueryOptions {
|
||||
|
||||
Reference in new issue
Block a user