浏览代码

fix: simplify deleteTimesheet to use apiCall now that SDK sends DELETE body

ShadowMan Service User 1 天之前
父节点
当前提交
af40fe8b74
共有 1 个文件被更改,包括 5 次插入41 次删除
  1. 5 41
      lib/tasks.js

+ 5 - 41
lib/tasks.js

@@ -303,47 +303,11 @@ function listTimesheets(token, projectId, filters) {
 }
 
 function deleteTimesheet(token, projectId, logId) {
-    // v3 API DELETE — requires JSON body: {module, from_page}
-    // NOTE: If this fails with INVALID_INPUTSTREAM, the SDK may not send DELETE body correctly.
-    var portalId = shadowman.config.value('portal_id');
-    var url = API_BASE + '/api/v3/portal/' + portalId + '/projects/' + projectId + '/logs/' + String(logId);
-    var body = JSON.stringify({ module: 'task', from_page: 'timesheetdetails' });
-    var headers = {
-        'Authorization': 'Zoho-oauthtoken ' + token,
-        'Content-Type': 'application/json'
-    };
-
-    var resp = shadowman.http.request(url, {
-        method: 'DELETE',
-        body: body,
-        headers: headers,
-        contentType: 'application/json'
-    });
-
-    if (resp.status === 401) {
-        var auth = require('./auth');
-        var newToken = auth.getValidToken();
-        if (!newToken) return { error: 'Auth expired and refresh failed.' };
-        headers['Authorization'] = 'Zoho-oauthtoken ' + newToken;
-        resp = shadowman.http.request(url, {
-            method: 'DELETE',
-            body: body,
-            headers: headers,
-            contentType: 'application/json'
-        });
-    }
-
-    if (resp.status >= 400) {
-        var msg = '';
-        if (resp.body && typeof resp.body === 'object') {
-            msg = (resp.body.error && resp.body.error.message) || JSON.stringify(resp.body);
-        } else {
-            msg = String(resp.body);
-        }
-        return { error: 'Zoho API error (' + resp.status + '): ' + msg };
-    }
-
-    return { success: true };
+    return apiCall(token, 'DELETE',
+        '/api/v3/portal/{PORTALID}/projects/{PROJECTID}/logs/{LOGID}'
+        .replace('{PORTALID}', shadowman.config.value('portal_id'))
+        .replace('{PROJECTID}', projectId)
+        .replace('{LOGID}', String(logId)), { module: 'task', from_page: 'timesheetdetails' }, {});
 }
 
 module.exports = {