• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

popstas / planfix-mcp-server / 18244711899

04 Oct 2025 01:05PM UTC coverage: 80.448% (+0.2%) from 80.254%
18244711899

push

github

web-flow
Allow sell task creation without resolved contact (#55)

465 of 651 branches covered (71.43%)

Branch coverage included in aggregate %.

3238 of 3952 relevant lines covered (81.93%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.07
/src/tools/planfix_create_sell_task.ts
1
import { z } from "zod";
1✔
2
import { getToolWithHandler, log } from "../helpers.js";
1✔
3
import {
1✔
4
  createSellTaskIds,
5
  CreateSellTaskOutputSchema,
6
} from "./planfix_create_sell_task_ids.js";
7
import { searchLeadTask } from "./planfix_search_lead_task.js";
1✔
8
import { planfixSearchCompany } from "./planfix_search_company.js";
1✔
9
import type { UsersListType } from "../types.js";
10

11
export const CreateSellTaskInputSchema = z.object({
1✔
12
  name: z.string().min(1, "Task name is required"),
1✔
13
  agency: z.string().optional(),
1✔
14
  email: z.string().min(1, "Email is required"),
1✔
15
  contactName: z.string().optional(),
1✔
16
  employeeName: z.string().optional(),
1✔
17
  telegram: z.string().optional(),
1✔
18
  description: z.string().min(1, "Description is required"),
1✔
19
  project: z.string().optional(),
1✔
20
});
1✔
21

22
function extractAssigneeIds(assignees?: UsersListType): number[] | undefined {
3✔
23
  if (!assignees?.users?.length) {
3✔
24
    return undefined;
2✔
25
  }
2✔
26

27
  const ids = assignees.users
1✔
28
    .map((user) => {
1✔
29
      if (!user?.id) return undefined;
2!
30
      const match = user.id.match(/(?:user:)?(\d+)/);
2✔
31
      if (!match) return undefined;
2!
32
      const parsed = Number(match[1]);
2✔
33
      return Number.isFinite(parsed) ? parsed : undefined;
2!
34
    })
1✔
35
    .filter((value): value is number => typeof value === "number");
1✔
36

37
  return ids.length ? ids : undefined;
3!
38
}
3✔
39

40
export async function createSellTask(
3✔
41
  args: z.infer<typeof CreateSellTaskInputSchema>,
3✔
42
): Promise<z.infer<typeof CreateSellTaskOutputSchema>> {
3✔
43
  const {
3✔
44
    name,
3✔
45
    agency,
3✔
46
    email,
3✔
47
    contactName,
3✔
48
    employeeName,
3✔
49
    telegram,
3✔
50
    description,
3✔
51
    project,
3✔
52
  } = args;
3✔
53

54
  const resolvedContactName = contactName ?? employeeName;
3✔
55

56
  const searchResult = await searchLeadTask({
3✔
57
    name: resolvedContactName,
3✔
58
    email,
3✔
59
    telegram,
3✔
60
    company: agency,
3✔
61
  });
3✔
62

63
  const {
3✔
64
    clientId,
3✔
65
    taskId: leadTaskId,
3✔
66
    agencyId: initialAgencyId,
3✔
67
    assignees,
3✔
68
  } = searchResult;
3✔
69
  let resolvedAgencyId = initialAgencyId;
3✔
70

71
  if (!resolvedAgencyId && agency) {
3✔
72
    try {
1✔
73
      const companyResult = await planfixSearchCompany({ name: agency });
1✔
74
      if ("contactId" in companyResult && companyResult.contactId) {
1✔
75
        resolvedAgencyId = companyResult.contactId;
1✔
76
      }
1✔
77
    } catch (error) {
1!
78
      log(
×
79
        `[createSellTask] Failed to resolve agency '${agency}': ${error instanceof Error ? error.message : String(error)}`,
×
80
      );
×
81
    }
×
82
  }
1✔
83

84
  const assigneeIds = extractAssigneeIds(assignees);
3✔
85

86
  return createSellTaskIds({
3✔
87
    clientId,
3✔
88
    leadTaskId: leadTaskId || undefined,
3✔
89
    agencyId: resolvedAgencyId,
3✔
90
    assignees: assigneeIds,
3✔
91
    name,
3✔
92
    description,
3✔
93
    project,
3✔
94
  });
3✔
95
}
3✔
96

97
async function handler(args?: Record<string, unknown>) {
×
98
  const parsedArgs = CreateSellTaskInputSchema.parse(args);
×
99
  return createSellTask(parsedArgs);
×
100
}
×
101

102
export const planfixCreateSellTaskTool = getToolWithHandler({
1✔
103
  name: "planfix_create_sell_task",
1✔
104
  description:
1✔
105
    "Create a sell task in Planfix using textual data for agency and contact",
1✔
106
  inputSchema: CreateSellTaskInputSchema,
1✔
107
  outputSchema: CreateSellTaskOutputSchema,
1✔
108
  handler,
1✔
109
});
1✔
110

111
export default planfixCreateSellTaskTool;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc