Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Notion (Beta) Node): Fix create database page fails if relation param is empty/undefined #5182

Merged
merged 6 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/nodes-base/nodes/Notion/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ import moment from 'moment-timezone';

import { validate as uuidValidate } from 'uuid';

const uuidValidateWithoutDashes = (value: string) => {
if (!value || typeof value !== 'string') return false;
if (uuidValidate(value)) return true;
if (value.length !== 32) return false;
//prettier-ignore
const strWithDashes = `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
return uuidValidate(strWithDashes);
};

export type SortData = { key: string; type: string; direction: string; timestamp: boolean };

const apiVersion: { [key: number]: string } = {
1: '2021-05-13',
2: '2021-08-16',
Expand Down Expand Up @@ -289,10 +300,13 @@ function getPropertyKeyValue(value: any, type: string, timezone: string, version
case 'relation':
result = {
type: 'relation',

relation: value.relationValue.reduce((acc: [], cur: any) => {
return acc.concat(cur.split(',').map((relation: string) => ({ id: relation.trim() })));
}, []),
relation: value.relationValue
.filter((rv: string) => {
return uuidValidateWithoutDashes(rv);
})
.reduce((acc: [], cur: any) => {
return acc.concat(cur.split(',').map((relation: string) => ({ id: relation.trim() })));
}, []),
};
break;
case 'multi_select':
Expand Down Expand Up @@ -415,9 +429,7 @@ export function mapProperties(properties: IDataObject[], timezone: string, versi
);
}

export function mapSorting(
data: [{ key: string; type: string; direction: string; timestamp: boolean }],
) {
export function mapSorting(data: SortData[]) {
return data.map((sort) => {
return {
direction: sort.direction,
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
notionApiRequest,
notionApiRequestAllItems,
simplifyObjects,
SortData,
validateJSON,
} from '../GenericFunctions';

Expand Down Expand Up @@ -536,8 +537,7 @@ export class NotionV2 implements INodeType {
delete body.filter;
}
if (sort) {
//@ts-expect-error
body.sorts = mapSorting(sort);
body.sorts = mapSorting(sort as SortData[]);
}
if (returnAll) {
responseData = await notionApiRequestAllItems.call(
Expand Down