|
| 1 | +import toggl from "../../toggl.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + key: "toggl-update-project", |
| 5 | + name: "Update Project", |
| 6 | + description: "Updates an existing project in Toggl. [See the documentation](https://engineering.toggl.com/docs/api/projects#put-workspaceproject)", |
| 7 | + version: "0.0.1", |
| 8 | + type: "action", |
| 9 | + props: { |
| 10 | + toggl, |
| 11 | + workspaceId: { |
| 12 | + propDefinition: [ |
| 13 | + toggl, |
| 14 | + "workspaceId", |
| 15 | + ], |
| 16 | + }, |
| 17 | + projectId: { |
| 18 | + propDefinition: [ |
| 19 | + toggl, |
| 20 | + "projectId", |
| 21 | + (c) => ({ |
| 22 | + workspaceId: c.workspaceId, |
| 23 | + }), |
| 24 | + ], |
| 25 | + }, |
| 26 | + name: { |
| 27 | + propDefinition: [ |
| 28 | + toggl, |
| 29 | + "projectName", |
| 30 | + ], |
| 31 | + optional: true, |
| 32 | + }, |
| 33 | + startDate: { |
| 34 | + propDefinition: [ |
| 35 | + toggl, |
| 36 | + "startDate", |
| 37 | + ], |
| 38 | + optional: true, |
| 39 | + }, |
| 40 | + endDate: { |
| 41 | + propDefinition: [ |
| 42 | + toggl, |
| 43 | + "endDate", |
| 44 | + ], |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + active: { |
| 48 | + type: "boolean", |
| 49 | + label: "Active", |
| 50 | + description: "Whether the project is active or archived.", |
| 51 | + optional: true, |
| 52 | + }, |
| 53 | + isPrivate: { |
| 54 | + type: "boolean", |
| 55 | + label: "Is Private?", |
| 56 | + description: "Whether the project is private or not.", |
| 57 | + optional: true, |
| 58 | + }, |
| 59 | + isShared: { |
| 60 | + type: "boolean", |
| 61 | + label: "Is Shared?", |
| 62 | + description: "Whether the project is shared or not.", |
| 63 | + optional: true, |
| 64 | + }, |
| 65 | + clientId: { |
| 66 | + propDefinition: [ |
| 67 | + toggl, |
| 68 | + "clientId", |
| 69 | + (c) => ({ |
| 70 | + workspaceId: c.workspaceId, |
| 71 | + }), |
| 72 | + ], |
| 73 | + optional: true, |
| 74 | + }, |
| 75 | + }, |
| 76 | + async run({ $ }) { |
| 77 | + const project = await this.toggl.getProject({ |
| 78 | + $, |
| 79 | + workspaceId: this.workspaceId, |
| 80 | + projectId: this.projectId, |
| 81 | + }); |
| 82 | + const response = await this.toggl.updateProject({ |
| 83 | + $, |
| 84 | + workspaceId: this.workspaceId, |
| 85 | + projectId: this.projectId, |
| 86 | + data: { |
| 87 | + name: this.name || project.name, |
| 88 | + start_date: this.startDate || project.start_date, |
| 89 | + end_date: this.endDate || project.end_date, |
| 90 | + active: this.active || project.active, |
| 91 | + is_private: this.isPrivate || project.isPrivate, |
| 92 | + is_shared: this.isShared || project.is_shared, |
| 93 | + client_id: this.clientId || project.client_id, |
| 94 | + }, |
| 95 | + }); |
| 96 | + if (response.id) { |
| 97 | + $.export("$summary", `Successfully updated project with ID: ${response.id}`); |
| 98 | + } |
| 99 | + return response; |
| 100 | + }, |
| 101 | +}; |
0 commit comments