diff --git a/components/toggl/actions/create-new-client/create-new-client.mjs b/components/toggl/actions/create-new-client/create-new-client.mjs new file mode 100644 index 0000000000000..d70d50d8b03aa --- /dev/null +++ b/components/toggl/actions/create-new-client/create-new-client.mjs @@ -0,0 +1,28 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + name: "Create a new client", + version: "0.0.1", + description: "Create a new Client [See docs here.](https://developers.track.toggl.com/docs/api/clients/index.html#post-create-client)", + type: "action", + key: "toggle-create-new-client", + props: { + toggl, + name: { + type: "string", + label: "Name", + }, + workspace_id: { + type: "integer", + label: "Workspace ID", + } + }, + async run({ $ }) { + const response = await this.toggl.createNewClient({ + name: this.name, + workspace_id: this.workspace_id, + }) + + response && $.export("$summary", "Successfully created new client"); + } +} \ No newline at end of file diff --git a/components/toggl/actions/create-project/create-project.mjs b/components/toggl/actions/create-project/create-project.mjs new file mode 100644 index 0000000000000..4e55cb4be5856 --- /dev/null +++ b/components/toggl/actions/create-project/create-project.mjs @@ -0,0 +1,138 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + name: "Create a new Project", + version: "0.0.1", + description: "Create project for given workspace. [See docs here.](https://developers.track.toggl.com/docs/api/projects#post-workspaceprojects)", + type: "action", + key: "toggle-create-new-project", + props: { + toggl, + name: { + type: "string", + label: "Name", + description: 'unique for client and workspace' + }, + workspace_id: { + type: "integer", + label: "Workspace ID", + description: "Numeric ID of the workspace" + }, + client_id: { + type: 'integer', + label: 'client ID', + optional: true, + }, + client_name: { + type: 'string', + label: 'client Name', + optional: true, + }, + active: { + type: 'boolean', + label: 'Active', + optional: true, + description: ' Whether the project is archived or not', + }, + is_private: { + type: 'boolean', + label: 'Is Private', + optional: true, + description: 'Whether project is accessible for only project users or for all workspace users', + }, + template: { + type: 'boolean', + label: 'Template', + optional: true, + description: 'Whether the project can be used as a template', + }, + template_id: { + type: 'integer', + label: 'Template ID', + description: "Id of the template project used on current project's creation", + optional: true, + }, + billable: { + type: 'boolean', + label: 'Billable', + description: "Whether the project is billable or no (available only for pro workspaces)", + }, + auto_estimates: { + type: 'boolean', + label: 'Auto Estimates', + optional: true, + description: "whether the estimated hours are automatically calculated based on task estimations or manually fixed based on the value of 'estimated_hours' (premium functionality) ", + }, + estimated_hours: { + type: 'boolean', + label: 'Estimated Hours', + optional: true, + description: "if auto_estimates is true then the sum of task estimations is returned, otherwise user inserted hours (premium functionality)" + + }, + color: { + type: 'string', + label: 'Color', + description: 'Project color (hex value in the form of #[0-9a-f]{6}.)', + }, + rate: { + type: 'integer', + label: 'Rate', + description: 'Hourly Rate. premium feature', + optional: true, + }, + fixed_fee: { + type: 'integer', + label: 'Rate', + description: 'Project fixed fee. premium feature', + optional: true, + }, + currency: { + type: 'string', + label: 'Currency', + description: 'Project currency. premium feature', + optional: true, + }, + start_date: { + type: 'string', + label: 'Start Date', + description: 'Start date of a project timeframe', + }, + end_date: { + type: 'string', + label: 'End Date', + description: 'End date of a project timeframe', + }, + }, + async run({ $ }) { + const { + name, workspace_id,client_id,client_name, active, + is_private, template, template_id, billable, auto_estimates, + estimated_hours, color, rate, fixed_fee, currency, start_date, end_date} = this; + const payload = { + name, + workspace_id, + client_id, + client_name, + active, + is_private, + template, + template_id, + billable, + auto_estimates, + estimated_hours, + color, + rate, + fixed_fee, + currency, + start_date, + end_date + } + const response = await this.toggl.createProject({ + workspace_id: this.workspace_id, + payload, + }) + + response && $.export("$summary", `Successfully created new project, ${response.name}`); + } +} \ No newline at end of file diff --git a/components/toggl/actions/update-client/update-client.mjs b/components/toggl/actions/update-client/update-client.mjs new file mode 100644 index 0000000000000..41d35dd43115f --- /dev/null +++ b/components/toggl/actions/update-client/update-client.mjs @@ -0,0 +1,33 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + name: "Update new client", + version: "0.0.1", + description: "Upate a Client [See docs here.](https://developers.track.toggl.com/docs/api/clients/index.html#put-change-client)", + type: "action", + key: "toggle-update-client", + props: { + toggl, + name: { + type: "string", + label: "Name", + }, + workspace_id: { + type: "integer", + label: "Workspace ID", + }, + client_id: { + type: "integer", + label: "Client ID", + }, + }, + async run({ $ }) { + const response = await this.toggl.updateClient({ + name: this.name, + workspace_id: this.workspace_id, + client_id: this.client_id + }) + + response && $.export("$summary", "Successfully updated client info."); + } +} \ No newline at end of file diff --git a/components/toggl/actions/update-project/update-project.mjs b/components/toggl/actions/update-project/update-project.mjs new file mode 100644 index 0000000000000..0b83eb38a79fd --- /dev/null +++ b/components/toggl/actions/update-project/update-project.mjs @@ -0,0 +1,144 @@ +import toggl from "../../toggl.app.mjs"; + +export default { + name: "Update a Project", + version: "0.0.1", + description: "Update project for given workspace. [See docs here.](https://developers.track.toggl.com/docs/api/projects#post-workspaceprojects)", + type: "action", + key: "toggle-update-project", + props: { + toggl, + workspace_id: { + type: "integer", + label: "Workspace ID", + description: "Numeric ID of the workspace" + }, + project_id: { + type: "integer", + label: "Project ID", + description: "Numeric ID of the project" + }, + name: { + type: "string", + label: "Name", + description: 'unique for client and workspace' + }, + client_id: { + type: 'integer', + label: 'client ID', + optional: true, + }, + client_name: { + type: 'string', + label: 'client Name', + optional: true, + }, + active: { + type: 'boolean', + label: 'Active', + optional: true, + description: ' Whether the project is archived or not', + }, + is_private: { + type: 'boolean', + label: 'Is Private', + optional: true, + description: 'Whether project is accessible for only project users or for all workspace users', + }, + template: { + type: 'boolean', + label: 'Template', + optional: true, + description: 'Whether the project can be used as a template', + }, + template_id: { + type: 'integer', + label: 'Template ID', + description: "Id of the template project used on current project's creation", + optional: true, + }, + billable: { + type: 'boolean', + label: 'Billable', + description: "Whether the project is billable or no (available only for pro workspaces)", + }, + auto_estimates: { + type: 'boolean', + label: 'Auto Estimates', + optional: true, + description: "whether the estimated hours are automatically calculated based on task estimations or manually fixed based on the value of 'estimated_hours' (premium functionality) ", + }, + estimated_hours: { + type: 'boolean', + label: 'Estimated Hours', + optional: true, + description: "if auto_estimates is true then the sum of task estimations is returned, otherwise user inserted hours (premium functionality)" + + }, + color: { + type: 'string', + label: 'Color', + description: 'Project color', + }, + rate: { + type: 'integer', + label: 'Rate', + description: 'Hourly Rate. premium feature', + optional: true, + }, + fixed_fee: { + type: 'integer', + label: 'Rate', + description: 'Project fixed fee. premium feature', + optional: true, + }, + currency: { + type: 'string', + label: 'Currency', + description: 'Project currency. premium feature', + optional: true, + }, + start_date: { + type: 'string', + label: 'Start Date', + description: 'Start date of a project timeframe', + }, + end_date: { + type: 'string', + label: 'End Date', + description: 'End date of a project timeframe', + }, + }, + async run({ $ }) { + const { + name, workspace_id,client_id,client_name, active, + is_private, template, template_id, billable, auto_estimates, + estimated_hours, color, rate, fixed_fee, currency, start_date, end_date} = this; + const data = { + name, + workspace_id, + client_id, + client_name, + active, + is_private, + template, + template_id, + billable, + auto_estimates, + estimated_hours, + color, + rate, + fixed_fee, + currency, + start_date, + end_date + } + const response = await this.toggl.updateProject({ + workspace_id: this.workspace_id, + project_id: this.project_id, + payload: data, + }) + + response && $.export("$summary", `Successfully created updated the ${response.name} project`); + } +} \ No newline at end of file diff --git a/components/toggl/common/constants.mjs b/components/toggl/common/constants.mjs index d4032e7086010..dd646afbce07b 100644 --- a/components/toggl/common/constants.mjs +++ b/components/toggl/common/constants.mjs @@ -2,5 +2,6 @@ export default { API_BASE_URL_VERSIONS: { "v1": "https://track.toggl.com/webhooks/api/v1", "v8": "https://api.track.toggl.com/api/v8", + "v9": "https://api.track.toggl.com/api/v9" }, }; diff --git a/components/toggl/toggl.app.mjs b/components/toggl/toggl.app.mjs index 8d9440a03cefd..3bcc297acceea 100644 --- a/components/toggl/toggl.app.mjs +++ b/components/toggl/toggl.app.mjs @@ -99,5 +99,39 @@ export default { return data; }, + async createNewClient({name, workspace_id, $, } = {}) { + const { data } = await this._makeRequest("v9", `workspaces/${workspace_id}/clients`, { + method: 'post', + data: { + name, + wid: workspace_id, + } + }, $) + return data; + }, + async updateClient({name, workspace_id, client_id, $, } = {}) { + const { data } = await this._makeRequest("v9", `workspaces/${workspace_id}/clients/${client_id}`, { + method: 'put', + data: { + name, + wid: workspace_id, + } + }, $) + return data; + }, + async createProject({workspace_id, payload, $, } = {}) { + const { data } = await this._makeRequest("v9", `workspaces/${workspace_id}/projects`, { + method: 'post', + data: payload, + }, $) + return data; + }, + async updateProject({workspace_id, payload, project_id, $, } = {}) { + const { data } = await this._makeRequest("v9", `workspaces/${workspace_id}/projects/${project_id}`, { + method: 'put', + data: payload, + }, $) + return data; + }, }, };