-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiag_custom_fields.ts
More file actions
87 lines (73 loc) · 3.04 KB
/
Copy pathdiag_custom_fields.ts
File metadata and controls
87 lines (73 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { db } from "./src/db";
import { systemConfig, projects } from "./src/db/schema";
import { WorkGuruClient } from "./src/lib/workguru";
import { decrypt } from "./src/lib/crypto";
import { eq } from "drizzle-orm";
import axios from "axios";
async function runCustomFieldDiag() {
const projectNumberToTest = "11733-06"; // This one had SOME data in previous tests
console.log(`[Diag] Starting Dedicated Custom Field Diagnostic for Project: ${projectNumberToTest}`);
try {
// 1. Get Credentials
const config = await db.query.systemConfig.findFirst({
where: eq(systemConfig.key, 'WORKGURU_API_CREDENTIALS'),
});
if (!config) {
console.error("[Diag] ERROR: No API credentials found in DB.");
return;
}
const { apiKey, apiSecret } = config.value as { apiKey: string; apiSecret: string };
const decryptedKey = decrypt(apiKey);
const decryptedSecret = decrypt(apiSecret);
// 2. Find Project in DB
const project = await db.query.projects.findFirst({
where: eq(projects.projectNumber, projectNumberToTest),
});
if (!project) {
console.error(`[Diag] ERROR: Project ${projectNumberToTest} not found in DB.`);
return;
}
// 3. Authenticate
const client = new WorkGuruClient(decryptedKey, decryptedSecret);
await client.authenticate();
const token = (client as any).token;
// 4. Test Dedicated Endpoint
const baseUrl = 'https://api.workguru.io';
const endpoint = '/api/services/app/CustomField/GetCustomFieldValuesByTypeAndId';
// Testing different 'type' values if 'Project' fails
const types = ['Project', 'project', 0];
for (const type of types) {
console.log(`\n[Diag] Testing with Type: ${type}`);
try {
const response = await axios.get(`${baseUrl}${endpoint}`, {
headers: {
Authorization: `Bearer ${token}`,
'Accept': 'application/json'
},
params: {
type: type,
id: project.workguruId
}
});
console.log(`[Diag] SUCCESS for type ${type}: Status ${response.status}`);
console.log(`[Diag] Response Data:`, JSON.stringify(response.data, null, 2).substring(0, 1000));
if (response.data.result) {
console.log(`[Diag] Result count: ${response.data.result.length}`);
response.data.result.forEach((f: any) => {
console.log(`- Field: ${f.customField?.name || 'Unknown'} (ID: ${f.customFieldId}), Value: ${f.value}`);
});
}
} catch (error: any) {
console.error(`[Diag] FAILED for type ${type}: Status ${error.response?.status}`);
if (error.response?.data) {
console.error(`[Diag] Error body:`, JSON.stringify(error.response.data));
}
}
}
} catch (error) {
console.error("[Diag] Unexpected Error:", error);
} finally {
process.exit(0);
}
}
runCustomFieldDiag();