From 9b8112b478137e2092df8cb83dafb4ab9bfd8a0a Mon Sep 17 00:00:00 2001 From: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:33:47 +0530 Subject: [PATCH] fix: notion issue with empty url (#4517) --- .../pipeline/lib/handleIntegrations.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/web/app/api/(internal)/pipeline/lib/handleIntegrations.ts b/apps/web/app/api/(internal)/pipeline/lib/handleIntegrations.ts index 622d3ac46d..27e8834961 100644 --- a/apps/web/app/api/(internal)/pipeline/lib/handleIntegrations.ts +++ b/apps/web/app/api/(internal)/pipeline/lib/handleIntegrations.ts @@ -348,16 +348,16 @@ const buildNotionPayloadProperties = ( mapping.forEach((map) => { if (map.question.id === "metadata") { properties[map.column.name] = { - [map.column.type]: getValue(map.column.type, convertMetaObjectToString(data.response.meta)), + [map.column.type]: getValue(map.column.type, convertMetaObjectToString(data.response.meta)) || null, }; } else if (map.question.id === "createdAt") { properties[map.column.name] = { - [map.column.type]: getValue(map.column.type, data.response.createdAt.toISOString()), + [map.column.type]: getValue(map.column.type, data.response.createdAt) || null, }; } else { const value = responses[map.question.id]; properties[map.column.name] = { - [map.column.type]: getValue(map.column.type, value), + [map.column.type]: getValue(map.column.type, value) || null, }; } }); @@ -367,16 +367,21 @@ const buildNotionPayloadProperties = ( // notion requires specific payload for each column type // * TYPES NOT SUPPORTED BY NOTION API - rollup, created_by, created_time, last_edited_by, or last_edited_time -const getValue = (colType: string, value: string | string[] | number | Record) => { +const getValue = (colType: string, value: string | string[] | Date | number | Record) => { try { switch (colType) { case "select": - return { - name: value, - }; + if (!value) return null; + if (typeof value === "string") { + // Replace commas + const sanitizedValue = value.replace(/,/g, ""); + return { + name: sanitizedValue, + }; + } case "multi_select": if (Array.isArray(value)) { - return value.map((v: string) => ({ name: v })); + return value.map((v: string) => ({ name: v.replace(/,/g, "") })); } case "title": return [ @@ -402,7 +407,7 @@ const getValue = (colType: string, value: string | string[] | number | Record