fix(Todoist Node): Fix listSearch filter bug in Todoist Node (#10989)

This commit is contained in:
aya 2024-09-27 18:15:09 +03:00 committed by GitHub
parent 846cfde8dc
commit c4b327248d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 34 deletions

View file

@ -54,6 +54,11 @@ export interface Service {
execute(ctx: Context, operation: OperationType, itemIndex: number): Promise<TodoistResponse>; execute(ctx: Context, operation: OperationType, itemIndex: number): Promise<TodoistResponse>;
} }
export interface TodoistProjectType {
id: number;
name: string;
}
export interface TodoistResponse { export interface TodoistResponse {
success?: boolean; success?: boolean;
data?: IDataObject; data?: IDataObject;

View file

@ -13,7 +13,7 @@ import {
import { todoistApiRequest } from '../GenericFunctions'; import { todoistApiRequest } from '../GenericFunctions';
import type { OperationType } from './Service'; import type { OperationType, TodoistProjectType } from './Service';
import { TodoistService } from './Service'; import { TodoistService } from './Service';
// interface IBodyCreateTask { // interface IBodyCreateTask {
@ -610,22 +610,24 @@ export class TodoistV2 implements INodeType {
methods = { methods = {
listSearch: { listSearch: {
async searchProjects(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> { async searchProjects(
const projects = await todoistApiRequest.call(this, 'GET', '/projects'); this: ILoadOptionsFunctions,
filter?: string,
): Promise<INodeListSearchResult> {
const projects: TodoistProjectType[] = await todoistApiRequest.call(
this,
'GET',
'/projects',
);
return { return {
results: projects.map((project: IDataObject) => ({ results: projects
name: project.name, .filter(
value: project.id, (project) => !filter || project.name.toLowerCase().includes(filter.toLowerCase()),
})), )
}; .map((project) => ({
}, name: project.name,
async searchLabels(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> { value: project.id,
const labels = await todoistApiRequest.call(this, 'GET', '/labels'); })),
return {
results: labels.map((label: IDataObject) => ({
name: label.name,
value: label.name,
})),
}; };
}, },
}, },
@ -636,12 +638,9 @@ export class TodoistV2 implements INodeType {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
const projects = await todoistApiRequest.call(this, 'GET', '/projects'); const projects = await todoistApiRequest.call(this, 'GET', '/projects');
for (const project of projects) { for (const project of projects) {
const projectName = project.name;
const projectId = project.id;
returnData.push({ returnData.push({
name: projectName, name: project.name,
value: projectId, value: project.id,
}); });
} }
@ -666,12 +665,9 @@ export class TodoistV2 implements INodeType {
const qs: IDataObject = { project_id: projectId }; const qs: IDataObject = { project_id: projectId };
const sections = await todoistApiRequest.call(this, 'GET', '/sections', {}, qs); const sections = await todoistApiRequest.call(this, 'GET', '/sections', {}, qs);
for (const section of sections) { for (const section of sections) {
const sectionName = section.name;
const sectionId = section.id;
returnData.push({ returnData.push({
name: sectionName, name: section.name,
value: sectionId, value: section.id,
}); });
} }
} }
@ -706,12 +702,9 @@ export class TodoistV2 implements INodeType {
const items = await todoistApiRequest.call(this, 'GET', '/tasks', {}, qs); const items = await todoistApiRequest.call(this, 'GET', '/tasks', {}, qs);
for (const item of items) { for (const item of items) {
const itemContent = item.content;
const itemId = item.id;
returnData.push({ returnData.push({
name: itemContent, name: item.content,
value: itemId, value: item.id,
}); });
} }
} }
@ -726,10 +719,9 @@ export class TodoistV2 implements INodeType {
const labels = await todoistApiRequest.call(this, 'GET', '/labels'); const labels = await todoistApiRequest.call(this, 'GET', '/labels');
for (const label of labels) { for (const label of labels) {
const labelName = label.name;
returnData.push({ returnData.push({
name: labelName, name: label.name,
value: labelName, value: label.name,
}); });
} }