import { ModelClient } from '../client/model-client'; import { Task, PatchedTask } from './task'; export class TaskClient extends ModelClient { pluralName = 'tasks'; async createDSL(dsl: string, extraFields: any = {}): Promise { const url = `/${this.version}/${this.pluralName}/create`; const response = await this.client.post(url, { dsl, ...extraFields }); return this.validate(response.data); } async search(query: string): Promise { return await this.list({ query }); } async complete(id: string): Promise { const url = `/${this.version}/${this.pluralName}/${id}/complete`; const response = await this.client.put(url); this.clearMemo(); return this.validate(response.data); } async defer(id: string, context?: string): Promise { const url = context ? `/${this.version}/${this.pluralName}/${id}/defer?context=${context}` : `/${this.version}/${this.pluralName}/${id}/defer`; const response = await this.client.put(url); this.clearMemo(); return this.validate(response.data); } async next(context?: string): Promise { const url = context ? `/${this.version}/${this.pluralName}/next?context=${context}` : `/${this.version}/${this.pluralName}/next`; const response = await this.client.get(url); return this.validate(response.data); } async reorder( moved: string, above?: string, context?: string ): Promise { this.clearMemo(); let url = `/${this.version}/${this.pluralName}/reorder?moved=${moved}`; if (context) { url = `${url}&?context=${context}`; } if (above) { url = `${url}&above=${above}`; } const response = await this.client.put(url); if (!this.isPaginated(response.data)) { throw new Error('Unexpected response!'); } return response.data; } }