export async function searchWorkitemsFunc()

in operations/projex/workitem.ts [23:74]


export async function searchWorkitemsFunc(
  organizationId: string,
  category: string,
  spaceId: string,
  subject?: string,
  status?: string,
  createdAfter?: string,
  createdBefore?: string,
  creator?: string,
  assignedTo?: string,
  advancedConditions?: string,
  orderBy: string = "gmtCreate" // Possible values: gmtCreate, subject, status, priority, assignedTo
): Promise<z.infer<typeof WorkItemSchema>[]> {
  const url = `/oapi/v1/projex/organizations/${organizationId}/workitems:search`;

  // Prepare payload
  const payload: Record<string, any> = {
    category: category,
    spaceId: spaceId,
  };

  // Process condition parameters
  const conditions = buildWorkitemConditions({
    subject,
    status,
    createdAfter,
    createdBefore,
    creator,
    assignedTo,
    advancedConditions
  });
  
  if (conditions) {
    payload.conditions = conditions;
  }

  // Add orderBy parameter
  payload.orderBy = orderBy;

  const response = await yunxiaoRequest(url, {
    method: "POST",
    body: payload,
  });

  // Ensure response is an array
  if (!Array.isArray(response)) {
    return [];
  }

  // Parse each work item object
  return response.map(workitem => WorkItemSchema.parse(workitem));
}