@elobdev/zoho-projects-wrapper 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,274 @@
1
+ import { ResourceBase } from '@/resource-base.ts';
2
+ import type {
3
+ ZohoGeneralTimeLogBody,
4
+ ZohoTimeLogApprovalBody,
5
+ ZohoTimeLogBody,
6
+ ZohoTimeLogCreateBody,
7
+ ZohoTimeLogReportParams,
8
+ ZohoTimeLogSettings,
9
+ ZohoTimeLogActionBody,
10
+ ZohoTimeLogUpdateBody,
11
+ ZohoTimeLogListParams,
12
+ ZohoTimeSheetCustomField,
13
+ ZohoTimeSheetLayout,
14
+ } from '@/types.ts';
15
+
16
+ function setFormValue(form: FormData, key: string, value: unknown): void {
17
+ if (value === undefined || value === null) return;
18
+ if (typeof value === 'object') {
19
+ form.set(key, JSON.stringify(value));
20
+ return;
21
+ }
22
+ form.set(key, String(value));
23
+ }
24
+
25
+ export class TimeLogsResource extends ResourceBase {
26
+ private timeLogsPath(portalId: string | number, ...parts: Array<string | number | undefined>): string {
27
+ return this.buildPath(['portal', portalId, 'timelogs', ...parts]);
28
+ }
29
+
30
+ private projectTimeLogsPath(portalId: string | number, projectId: string | number, ...parts: Array<string | number | undefined>): string {
31
+ return this.buildPath(['portal', portalId, 'projects', projectId, 'timelogs', ...parts]);
32
+ }
33
+
34
+ listProjectLogs(portalId: string | number, projectId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
35
+ return this.get(this.projectPath(portalId, projectId, 'logs'), params);
36
+ }
37
+
38
+ listMyLogs(portalId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
39
+ return this.get(this.portalPath(portalId, 'logs'), params);
40
+ }
41
+
42
+ listPortalTimeLogs(portalId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
43
+ return this.get(this.portalPath(portalId, 'logs'), params);
44
+ }
45
+
46
+ listProjectTimeLogs(portalId: string | number, projectId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
47
+ return this.get(this.projectPath(portalId, projectId, 'logs'), params);
48
+ }
49
+
50
+ getTimeLogDetail(portalId: string | number, projectId: string | number, logId: string | number, type: 'task' | 'issue' | 'general'): Promise<unknown> {
51
+ return this.get(this.projectPath(portalId, projectId, 'logs', logId), { type });
52
+ }
53
+
54
+ addTimeLog(portalId: string | number, projectId: string | number, body: ZohoTimeLogCreateBody): Promise<unknown> {
55
+ return this.post(this.projectPath(portalId, projectId, 'logs'), body);
56
+ }
57
+
58
+ bulkUpdateTimeLogs(portalId: string | number, body: ZohoTimeLogUpdateBody): Promise<unknown> {
59
+ return this.patch(this.timeLogsPath(portalId), body);
60
+ }
61
+
62
+ bulkDeleteTimeLogs(portalId: string | number, body: { id: string | number; module: 'task' | 'issue' | 'general' }): Promise<unknown> {
63
+ return this.delete(this.timeLogsPath(portalId), body);
64
+ }
65
+
66
+ getPortalTimeLogReport(portalId: string | number, params: ZohoTimeLogReportParams = {}): Promise<unknown> {
67
+ return this.get(this.timeLogsPath(portalId, 'report'), params);
68
+ }
69
+
70
+ getProjectTimeLogReport(portalId: string | number, projectId: string | number, params: ZohoTimeLogReportParams = {}): Promise<unknown> {
71
+ return this.get(this.projectTimeLogsPath(portalId, projectId, 'report'), params);
72
+ }
73
+
74
+ getDefaultApprover(portalId: string | number, projectId: string | number): Promise<unknown> {
75
+ return this.get(this.projectTimeLogsPath(portalId, projectId, 'approver'));
76
+ }
77
+
78
+ listPinnedPortalTimeLogs(portalId: string | number): Promise<unknown> {
79
+ return this.get(this.timeLogsPath(portalId, 'pin'));
80
+ }
81
+
82
+ listPinnedProjectTimeLogs(portalId: string | number, projectId: string | number): Promise<unknown> {
83
+ return this.get(this.projectTimeLogsPath(portalId, projectId, 'pin'));
84
+ }
85
+
86
+ createPinnedPortalTimeLog(portalId: string | number, body: Record<string, unknown>): Promise<unknown> {
87
+ return this.post(this.timeLogsPath(portalId, 'pin'), body);
88
+ }
89
+
90
+ updatePinnedPortalTimeLog(portalId: string | number, body: Record<string, unknown>): Promise<unknown> {
91
+ return this.patch(this.timeLogsPath(portalId, 'pin'), body);
92
+ }
93
+
94
+ deletePinnedPortalTimeLog(portalId: string | number, body: Record<string, unknown>): Promise<unknown> {
95
+ return this.delete(this.timeLogsPath(portalId, 'pin'), body);
96
+ }
97
+
98
+ createPinnedProjectTimeLog(portalId: string | number, projectId: string | number, body: Record<string, unknown>): Promise<unknown> {
99
+ return this.post(this.projectTimeLogsPath(portalId, projectId, 'pin'), body);
100
+ }
101
+
102
+ updatePinnedProjectTimeLog(portalId: string | number, projectId: string | number, body: Record<string, unknown>): Promise<unknown> {
103
+ return this.patch(this.projectTimeLogsPath(portalId, projectId, 'pin'), body);
104
+ }
105
+
106
+ deletePinnedProjectTimeLog(portalId: string | number, projectId: string | number, body: Record<string, unknown>): Promise<unknown> {
107
+ return this.delete(this.projectTimeLogsPath(portalId, projectId, 'pin'), body);
108
+ }
109
+
110
+ listRunningTimers(portalId: string | number, params: Record<string, unknown> = {}): Promise<unknown> {
111
+ return this.get(this.timeLogsPath(portalId, 'timers'), params);
112
+ }
113
+
114
+ getTimerDetailsByLogId(
115
+ portalId: string | number,
116
+ projectId: string | number,
117
+ entityType: 'task' | 'issue',
118
+ logId: string | number,
119
+ ): Promise<unknown> {
120
+ return this.get(this.buildPath(['portal', portalId, 'projects', projectId, entityType, 'logs', logId, 'timers']));
121
+ }
122
+
123
+ startTimer(portalId: string | number, body: ZohoTimeLogActionBody): Promise<unknown> {
124
+ return this.post(this.timeLogsPath(portalId, 'timers'), body);
125
+ }
126
+
127
+ pauseTimer(portalId: string | number, timerId: string | number, body: ZohoTimeLogActionBody): Promise<unknown> {
128
+ return this.patch(this.timeLogsPath(portalId, 'timers', timerId, 'pause'), body);
129
+ }
130
+
131
+ resumeTimer(portalId: string | number, timerId: string | number, body: ZohoTimeLogActionBody): Promise<unknown> {
132
+ return this.patch(this.timeLogsPath(portalId, 'timers', timerId, 'resume'), body);
133
+ }
134
+
135
+ stopTimer(portalId: string | number, timerId: string | number, body: Record<string, unknown>): Promise<unknown> {
136
+ return this.patch(this.timeLogsPath(portalId, 'timers', timerId, 'stop'), body);
137
+ }
138
+
139
+ deleteTimer(portalId: string | number, timerId: string | number): Promise<unknown> {
140
+ return this.delete(this.timeLogsPath(portalId, 'timers', timerId));
141
+ }
142
+
143
+ getTimeLogSettingsMetaData(portalId: string | number): Promise<unknown> {
144
+ return this.get(this.portalPath(portalId, 'settings', 'timelog', 'meta-data'));
145
+ }
146
+
147
+ getTimeLogSettings(portalId: string | number): Promise<ZohoTimeLogSettings> {
148
+ return this.get(this.portalPath(portalId, 'settings', 'timelog'));
149
+ }
150
+
151
+ updateTimeLogSettings(portalId: string | number, body: Record<string, unknown>): Promise<unknown> {
152
+ return this.patch(this.portalPath(portalId, 'settings', 'timelog'), body);
153
+ }
154
+
155
+ listTaskLogs(portalId: string | number, projectId: string | number, taskId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
156
+ return this.get(this.projectPath(portalId, projectId, 'tasks', taskId, 'logs'), params);
157
+ }
158
+
159
+ addTaskLog(portalId: string | number, projectId: string | number, taskId: string | number, body: ZohoTimeLogBody): Promise<unknown> {
160
+ const form = this.buildLogForm(body);
161
+ return this.request(this.projectPath(portalId, projectId, 'tasks', taskId, 'logs'), {
162
+ method: 'POST',
163
+ formData: form,
164
+ });
165
+ }
166
+
167
+ updateTaskLog(portalId: string | number, projectId: string | number, taskId: string | number, logId: string | number, body: ZohoTimeLogBody): Promise<unknown> {
168
+ const form = this.buildLogForm(body);
169
+ return this.request(this.projectPath(portalId, projectId, 'tasks', taskId, 'logs', logId), {
170
+ method: 'POST',
171
+ formData: form,
172
+ });
173
+ }
174
+
175
+ approveTaskLog(portalId: string | number, projectId: string | number, taskId: string | number, logId: string | number, body: ZohoTimeLogApprovalBody): Promise<unknown> {
176
+ const form = new FormData();
177
+ setFormValue(form, 'approval', body.approval);
178
+ setFormValue(form, 'reason', body.reason);
179
+ return this.request(this.projectPath(portalId, projectId, 'tasks', taskId, 'logs', logId, 'approval'), {
180
+ method: 'POST',
181
+ formData: form,
182
+ });
183
+ }
184
+
185
+ deleteTaskLog(portalId: string | number, projectId: string | number, taskId: string | number, logId: string | number): Promise<unknown> {
186
+ return this.delete(this.projectPath(portalId, projectId, 'tasks', taskId, 'logs', logId));
187
+ }
188
+
189
+ listBugLogs(portalId: string | number, projectId: string | number, issueId: string | number, params: ZohoTimeLogListParams = {}): Promise<unknown> {
190
+ return this.get(this.projectPath(portalId, projectId, 'bugs', issueId, 'logs'), params);
191
+ }
192
+
193
+ addBugLog(portalId: string | number, projectId: string | number, issueId: string | number, body: ZohoTimeLogBody): Promise<unknown> {
194
+ const form = this.buildLogForm(body);
195
+ return this.request(this.projectPath(portalId, projectId, 'bugs', issueId, 'logs'), {
196
+ method: 'POST',
197
+ formData: form,
198
+ });
199
+ }
200
+
201
+ updateBugLog(portalId: string | number, projectId: string | number, issueId: string | number, logId: string | number, body: ZohoTimeLogBody): Promise<unknown> {
202
+ const form = this.buildLogForm(body);
203
+ return this.request(this.projectPath(portalId, projectId, 'bugs', issueId, 'logs', logId), {
204
+ method: 'POST',
205
+ formData: form,
206
+ });
207
+ }
208
+
209
+ approveBugLog(portalId: string | number, projectId: string | number, issueId: string | number, logId: string | number, body: ZohoTimeLogApprovalBody): Promise<unknown> {
210
+ const form = new FormData();
211
+ setFormValue(form, 'approval', body.approval);
212
+ setFormValue(form, 'reason', body.reason);
213
+ return this.request(this.projectPath(portalId, projectId, 'bugs', issueId, 'logs', logId, 'approval'), {
214
+ method: 'POST',
215
+ formData: form,
216
+ });
217
+ }
218
+
219
+ deleteBugLog(portalId: string | number, projectId: string | number, issueId: string | number, logId: string | number): Promise<unknown> {
220
+ return this.delete(this.projectPath(portalId, projectId, 'bugs', issueId, 'logs', logId));
221
+ }
222
+
223
+ addGeneralLog(portalId: string | number, projectId: string | number, body: ZohoGeneralTimeLogBody): Promise<unknown> {
224
+ const form = this.buildLogForm(body);
225
+ setFormValue(form, 'name', body.name);
226
+ return this.request(this.projectPath(portalId, projectId, 'logs'), {
227
+ method: 'POST',
228
+ formData: form,
229
+ });
230
+ }
231
+
232
+ updateGeneralLog(portalId: string | number, projectId: string | number, logId: string | number, body: ZohoGeneralTimeLogBody): Promise<unknown> {
233
+ const form = this.buildLogForm(body);
234
+ setFormValue(form, 'name', body.name);
235
+ return this.request(this.projectPath(portalId, projectId, 'logs', logId), {
236
+ method: 'POST',
237
+ formData: form,
238
+ });
239
+ }
240
+
241
+ approveGeneralLog(portalId: string | number, projectId: string | number, logId: string | number, body: ZohoTimeLogApprovalBody): Promise<unknown> {
242
+ const form = new FormData();
243
+ setFormValue(form, 'approval', body.approval);
244
+ setFormValue(form, 'reason', body.reason);
245
+ return this.request(this.projectPath(portalId, projectId, 'logs', logId, 'approval'), {
246
+ method: 'POST',
247
+ formData: form,
248
+ });
249
+ }
250
+
251
+ deleteGeneralLog(portalId: string | number, projectId: string | number, logId: string | number): Promise<unknown> {
252
+ return this.delete(this.projectPath(portalId, projectId, 'logs', logId));
253
+ }
254
+
255
+ getTimesheetLayoutDetails(portalId: string | number, projectId: string | number): Promise<ZohoTimeSheetLayout> {
256
+ return this.get(this.projectPath(portalId, projectId, 'timesheetlayouts'));
257
+ }
258
+
259
+ getAllTimesheetCustomFields(portalId: string | number): Promise<ZohoTimeSheetCustomField[]> {
260
+ return this.get(this.portalPath(portalId, 'timesheetcustomfields'));
261
+ }
262
+
263
+ private buildLogForm(body: ZohoTimeLogBody | ZohoGeneralTimeLogBody): FormData {
264
+ const form = new FormData();
265
+ setFormValue(form, 'date', body.date);
266
+ setFormValue(form, 'owner', body.owner);
267
+ setFormValue(form, 'bill_status', body.bill_status);
268
+ setFormValue(form, 'hours', body.hours);
269
+ setFormValue(form, 'notes', body.notes);
270
+ setFormValue(form, 'cost_per_hour', body.cost_per_hour);
271
+ setFormValue(form, 'custom_fields', body.custom_fields);
272
+ return form;
273
+ }
274
+ }