| 298 | } |
| 299 | |
| 300 | function unwrapOdata(body: unknown): unknown { |
| 301 | if (!body || typeof body !== 'object') return body |
| 302 | const root = (body as { d?: unknown }).d |
| 303 | if (root === undefined) return body |
| 304 | if (root && typeof root === 'object' && 'results' in (root as Record<string, unknown>)) { |
| 305 | const rootObj = root as { results: unknown; __count?: string; __next?: string } |
| 306 | if (rootObj.__count !== undefined || rootObj.__next !== undefined) { |
| 307 | return { |
| 308 | results: rootObj.results, |
| 309 | ...(rootObj.__count !== undefined && { __count: rootObj.__count }), |
| 310 | ...(rootObj.__next !== undefined && { __next: rootObj.__next }), |
| 311 | } |
| 312 | } |
| 313 | return rootObj.results |
| 314 | } |
| 315 | return root |
| 316 | } |
| 317 | |
| 318 | export const POST = withRouteHandler(async (request: NextRequest) => { |
| 319 | const requestId = generateRequestId() |