( params: PerformRestoreTableParams )
| 23 | } |
| 24 | |
| 25 | export async function performRestoreTable( |
| 26 | params: PerformRestoreTableParams |
| 27 | ): Promise<PerformRestoreTableResult> { |
| 28 | const { tableId, userId } = params |
| 29 | const requestId = params.requestId ?? generateRequestId() |
| 30 | |
| 31 | const archivedTable = await getTableById(tableId, { includeArchived: true }) |
| 32 | if (!archivedTable) { |
| 33 | return { success: false, error: 'Table not found', errorCode: 'not_found' } |
| 34 | } |
| 35 | |
| 36 | try { |
| 37 | await restoreTable(tableId, requestId) |
| 38 | const table = (await getTableById(tableId)) ?? archivedTable |
| 39 | |
| 40 | logger.info(`[${requestId}] Restored table ${tableId}`) |
| 41 | |
| 42 | recordAudit({ |
| 43 | workspaceId: archivedTable.workspaceId, |
| 44 | actorId: userId, |
| 45 | action: AuditAction.TABLE_RESTORED, |
| 46 | resourceType: AuditResourceType.TABLE, |
| 47 | resourceId: tableId, |
| 48 | resourceName: table.name, |
| 49 | description: `Restored table "${table.name}"`, |
| 50 | metadata: { |
| 51 | tableName: table.name, |
| 52 | workspaceId: table.workspaceId, |
| 53 | }, |
| 54 | }) |
| 55 | |
| 56 | return { success: true, table } |
| 57 | } catch (error) { |
| 58 | logger.error(`[${requestId}] Failed to restore table ${tableId}`, { error }) |
| 59 | if (error instanceof TableConflictError) { |
| 60 | return { success: false, error: error.message, errorCode: 'conflict' } |
| 61 | } |
| 62 | return { success: false, error: toError(error).message, errorCode: 'internal' } |
| 63 | } |
| 64 | } |
no test coverage detected