Update types for backup endpoints

This commit is contained in:
Andrew Kingston 2024-12-05 14:41:46 +00:00
parent 0da9ad02a7
commit 29a1df736a
No known key found for this signature in database
2 changed files with 29 additions and 33 deletions

View File

@ -19,7 +19,7 @@ export function createBackupsStore() {
startDate, startDate,
endDate, endDate,
}) { }) {
return API.searchBackups({ appId, trigger, type, page, startDate, endDate }) return API.searchBackups(appId, { trigger, type, page, startDate, endDate })
} }
async function restoreBackup({ appId, backupId, name }) { async function restoreBackup({ appId, backupId, name }) {

View File

@ -1,60 +1,56 @@
import { PutResponse } from "@budibase/types" import {
CreateAppBackupRequest,
CreateAppBackupResponse,
ImportAppBackupResponse,
SearchAppBackupsRequest,
UpdateAppBackupRequest,
} from "@budibase/types"
import { BaseAPIClient } from "./types" import { BaseAPIClient } from "./types"
export interface BackupEndpoints { export interface BackupEndpoints {
createManualBackup: ( createManualBackup: (
appId: string
) => Promise<{ backupId: string; message: string }>
deleteBackup: (
appId: string, appId: string,
backupId: string name?: string
) => Promise<{ message: string }> ) => Promise<CreateAppBackupResponse>
updateBackup: (
appId: string,
backupId: string,
name: string
) => Promise<PutResponse>
restoreBackup: ( restoreBackup: (
appId: string, appId: string,
backupId: string, backupId: string,
name: string name: string
) => Promise<{ restoreId: string; message: string }> ) => Promise<ImportAppBackupResponse>
// Missing request or response types // Missing request or response types
searchBackups: (opts: any) => Promise<any> searchBackups: (appId: string, opts: SearchAppBackupsRequest) => Promise<any>
updateBackup: (appId: string, backupId: string, name: string) => Promise<any>
deleteBackup: (
appId: string,
backupId: string
) => Promise<{ message: string }>
} }
export const buildBackupEndpoints = (API: BaseAPIClient): BackupEndpoints => ({ export const buildBackupEndpoints = (API: BaseAPIClient): BackupEndpoints => ({
searchBackups: async ({ appId, trigger, type, page, startDate, endDate }) => { createManualBackup: async (appId, name) => {
const opts: any = {} return await API.post<CreateAppBackupRequest, CreateAppBackupResponse>({
if (page) { url: `/api/apps/${appId}/backups`,
opts.page = page body: name
} ? {
if (trigger && type) { name,
opts.trigger = trigger.toLowerCase()
opts.type = type.toLowerCase()
}
if (startDate && endDate) {
opts.startDate = startDate
opts.endDate = endDate
} }
: undefined,
})
},
searchBackups: async (appId, opts) => {
return await API.post({ return await API.post({
url: `/api/apps/${appId}/backups/search`, url: `/api/apps/${appId}/backups/search`,
body: opts, body: opts,
}) })
}, },
createManualBackup: async appId => {
return await API.post({
url: `/api/apps/${appId}/backups`,
})
},
deleteBackup: async (appId, backupId) => { deleteBackup: async (appId, backupId) => {
return await API.delete({ return await API.delete({
url: `/api/apps/${appId}/backups/${backupId}`, url: `/api/apps/${appId}/backups/${backupId}`,
}) })
}, },
updateBackup: async (appId, backupId, name) => { updateBackup: async (appId, backupId, name) => {
return await API.patch({ return await API.patch<UpdateAppBackupRequest, any>({
url: `/api/apps/${appId}/backups/${backupId}`, url: `/api/apps/${appId}/backups/${backupId}`,
body: { name }, body: { name },
}) })