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

popstas / planfix-mcp-server / 25313863059

04 May 2026 10:25AM UTC coverage: 80.525% (+0.04%) from 80.487%
25313863059

push

github

popstas
1.8.8

534 of 735 branches covered (72.65%)

Branch coverage included in aggregate %.

3518 of 4297 relevant lines covered (81.87%)

3.32 hits per line

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

66.18
/src/lib/extendPostBodyWithCustomFields.ts
1
import type {
2
  ContactResponse,
3
  CustomFieldDataType,
4
  TaskResponse,
5
} from "../types.js";
6
import type { CustomField } from "./extendSchemaWithCustomFields.js";
7
import {
1✔
8
  addDirectoryEntries,
9
  addDirectoryEntry,
10
} from "../lib/planfixDirectory.js";
11

12
export interface HasCustomFieldData {
13
  customFieldData?: CustomFieldDataType[];
14
  template: {
15
    id: number;
16
  };
17
}
18

19
export async function extendPostBodyWithCustomFields(
9✔
20
  postBody: HasCustomFieldData,
9✔
21
  args: Record<string, unknown>,
9✔
22
  fields: CustomField[],
9✔
23
  task?: TaskResponse,
9✔
24
  contact?: ContactResponse,
9✔
25
  forceUpdate?: boolean,
9✔
26
): Promise<void> {
9✔
27
  if (!fields.length) return;
9✔
28
  for (const field of fields) {
4✔
29
    const value =
4✔
30
      (args[field.argName as keyof typeof args] as unknown) || field.default;
4✔
31
    if (value === undefined || value === null || value === "") continue;
4!
32

33
    const current = task || contact;
4✔
34
    const currentField = current?.customFieldData?.find(
4✔
35
      (f) => f.field.id === Number(field.id),
4✔
36
    );
4✔
37
    let currentValue;
4✔
38
    if (field.type === "enum") {
4✔
39
      currentValue =
2✔
40
        currentField && Array.isArray(currentField.value)
2✔
41
          ? currentField?.value?.[0]
2!
42
          : "";
×
43
    }
2✔
44
    if (field.type === "handbook_record") {
4!
45
      await addDirectoryEntry({
×
46
        objectId: postBody.template.id,
×
47
        fieldId: field.id,
×
48
        value: value as string,
×
49
        postBody,
×
50
        allowCreate: field.allowCreate,
×
51
      });
×
52
      continue;
×
53
    }
×
54
    if (field.type === "handbook_record_multiple") {
4!
55
      await addDirectoryEntries({
×
56
        objectId: postBody.template.id,
×
57
        fieldId: field.id,
×
58
        values: value as string[],
×
59
        postBody,
×
60
        allowCreate: field.allowCreate,
×
61
      });
×
62
      continue;
×
63
    }
×
64
    if (!forceUpdate && currentValue === value) continue;
4✔
65

66
    if (!postBody.customFieldData) postBody.customFieldData = [];
3✔
67
    postBody.customFieldData.push({
3✔
68
      field: { id: Number(field.id) },
3✔
69
      value: value as
3✔
70
        | string
71
        | number
72
        | string[]
73
        | { id: number }
74
        | { id: number }[],
75
    });
3✔
76
  }
3✔
77
}
4✔
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