Skip to content

Commit 4615046

Browse files
committed
refactor(servicenow): type upload-attachment response per file-route convention
Match the SharePoint/OneDrive upload pattern: import the named ServiceNowAttachment type from the tool's types, cast response.json() to it, and extract specific fields with ?? null instead of passing data.result through as an opaque unknown blob.
1 parent 584c5ca commit 4615046

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

  • apps/sim

apps/sim/app/api/tools/servicenow/upload-attachment/route.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1010
import { processSingleFileToUserFile } from '@/lib/uploads/utils/file-utils'
1111
import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server'
1212
import { assertToolFileAccess } from '@/app/api/files/authorization'
13+
import type { ServiceNowAttachment } from '@/tools/servicenow/types'
1314
import { createBasicAuthHeader } from '@/tools/servicenow/utils'
1415

1516
export const dynamic = 'force-dynamic'
@@ -97,7 +98,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
9798
return NextResponse.json({ success: false, error: errorMessage }, { status: response.status })
9899
}
99100

100-
const data = (await response.json()) as { result?: unknown }
101+
const data = (await response.json()) as { result?: ServiceNowAttachment }
102+
const result = data.result
101103

102104
logger.info(`[${requestId}] File attached to ServiceNow record successfully`, {
103105
tableName: body.tableName,
@@ -107,7 +109,17 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
107109
return NextResponse.json({
108110
success: true,
109111
output: {
110-
attachment: data.result,
112+
attachment: result
113+
? {
114+
sys_id: result.sys_id ?? null,
115+
file_name: result.file_name ?? null,
116+
content_type: result.content_type ?? null,
117+
size_bytes: result.size_bytes ?? null,
118+
table_name: result.table_name ?? null,
119+
table_sys_id: result.table_sys_id ?? null,
120+
download_link: result.download_link ?? null,
121+
}
122+
: null,
111123
metadata: { recordCount: 1 },
112124
},
113125
})

apps/sim/tools/servicenow/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface ServiceNowAggregateResponse extends ToolResponse {
9696
}
9797
}
9898

99-
interface ServiceNowAttachment {
99+
export interface ServiceNowAttachment {
100100
sys_id: string
101101
file_name: string
102102
content_type: string

0 commit comments

Comments
 (0)