2022-06-20 16:42:08 -07:00
|
|
|
import {
|
|
|
|
CloseHandler,
|
|
|
|
CreateHandler,
|
|
|
|
DeleteHandler,
|
|
|
|
GetAllHandler,
|
|
|
|
GetHandler,
|
|
|
|
MoveHandler,
|
|
|
|
ReopenHandler,
|
|
|
|
SyncHandler,
|
2022-08-17 08:50:24 -07:00
|
|
|
UpdateHandler,
|
2022-06-20 16:42:08 -07:00
|
|
|
} from './OperationHandler';
|
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { Context } from '../GenericFunctions';
|
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
2022-06-20 16:42:08 -07:00
|
|
|
|
|
|
|
export class TodoistService implements Service {
|
2022-08-17 08:50:24 -07:00
|
|
|
async execute(
|
|
|
|
ctx: Context,
|
|
|
|
operation: OperationType,
|
|
|
|
itemIndex: number,
|
|
|
|
): Promise<TodoistResponse> {
|
2022-07-04 00:43:56 -07:00
|
|
|
return this.handlers[operation].handleOperation(ctx, itemIndex);
|
2022-06-20 16:42:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private handlers = {
|
2022-08-17 08:50:24 -07:00
|
|
|
create: new CreateHandler(),
|
|
|
|
close: new CloseHandler(),
|
|
|
|
delete: new DeleteHandler(),
|
|
|
|
get: new GetHandler(),
|
|
|
|
getAll: new GetAllHandler(),
|
|
|
|
reopen: new ReopenHandler(),
|
|
|
|
update: new UpdateHandler(),
|
|
|
|
move: new MoveHandler(),
|
|
|
|
sync: new SyncHandler(),
|
2022-06-20 16:42:08 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-21 04:23:15 -07:00
|
|
|
export type OperationType =
|
|
|
|
| 'create'
|
|
|
|
| 'close'
|
|
|
|
| 'delete'
|
|
|
|
| 'get'
|
|
|
|
| 'getAll'
|
|
|
|
| 'reopen'
|
|
|
|
| 'update'
|
|
|
|
| 'move'
|
|
|
|
| 'sync';
|
2022-06-20 16:42:08 -07:00
|
|
|
|
|
|
|
export interface Section {
|
|
|
|
name: string;
|
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Service {
|
2022-07-04 00:43:56 -07:00
|
|
|
execute(ctx: Context, operation: OperationType, itemIndex: number): Promise<TodoistResponse>;
|
2022-06-20 16:42:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface TodoistResponse {
|
|
|
|
success?: boolean;
|
|
|
|
data?: IDataObject;
|
|
|
|
}
|