Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

691 B
Raw Blame
import { LinkFormData } from "./link-builder-provider";

export function buildLinkBody({ data }: { data: LinkFormData }) {
  // @ts-ignore – exclude extra attributes from `data` object before sending to API
  const { user, tags, tagId, folderId, ...rest } = data;

  return {
    ...rest,

    // Map tags to tagIds
    tagIds: tags.map(({ id }) => id),

    // Replace "unsorted" folder ID w/ null
    folderId: folderId === "unsorted" ? null : folderId,

    // Manually reset empty strings to null
    expiredUrl: rest.expiredUrl || null,
    ios: rest.ios || null,
    android: rest.android || null,
    externalId: rest.externalId || null,
    tenantId: rest.tenantId || null,
  };
}