From 29a1df736ad98461c63f7d6a8fac32056e507471 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 5 Dec 2024 14:41:46 +0000 Subject: [PATCH] Update types for backup endpoints --- packages/builder/src/stores/portal/backups.js | 2 +- packages/frontend-core/src/api/backups.ts | 60 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/packages/builder/src/stores/portal/backups.js b/packages/builder/src/stores/portal/backups.js index 6ac70ef36c..d367ec73e8 100644 --- a/packages/builder/src/stores/portal/backups.js +++ b/packages/builder/src/stores/portal/backups.js @@ -19,7 +19,7 @@ export function createBackupsStore() { startDate, 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 }) { diff --git a/packages/frontend-core/src/api/backups.ts b/packages/frontend-core/src/api/backups.ts index 98ef0698ff..7ec9e72322 100644 --- a/packages/frontend-core/src/api/backups.ts +++ b/packages/frontend-core/src/api/backups.ts @@ -1,60 +1,56 @@ -import { PutResponse } from "@budibase/types" +import { + CreateAppBackupRequest, + CreateAppBackupResponse, + ImportAppBackupResponse, + SearchAppBackupsRequest, + UpdateAppBackupRequest, +} from "@budibase/types" import { BaseAPIClient } from "./types" export interface BackupEndpoints { createManualBackup: ( - appId: string - ) => Promise<{ backupId: string; message: string }> - deleteBackup: ( appId: string, - backupId: string - ) => Promise<{ message: string }> - updateBackup: ( - appId: string, - backupId: string, - name: string - ) => Promise + name?: string + ) => Promise restoreBackup: ( appId: string, backupId: string, name: string - ) => Promise<{ restoreId: string; message: string }> + ) => Promise // Missing request or response types - searchBackups: (opts: any) => Promise + searchBackups: (appId: string, opts: SearchAppBackupsRequest) => Promise + updateBackup: (appId: string, backupId: string, name: string) => Promise + deleteBackup: ( + appId: string, + backupId: string + ) => Promise<{ message: string }> } export const buildBackupEndpoints = (API: BaseAPIClient): BackupEndpoints => ({ - searchBackups: async ({ appId, trigger, type, page, startDate, endDate }) => { - const opts: any = {} - if (page) { - opts.page = page - } - if (trigger && type) { - opts.trigger = trigger.toLowerCase() - opts.type = type.toLowerCase() - } - if (startDate && endDate) { - opts.startDate = startDate - opts.endDate = endDate - } + createManualBackup: async (appId, name) => { + return await API.post({ + url: `/api/apps/${appId}/backups`, + body: name + ? { + name, + } + : undefined, + }) + }, + searchBackups: async (appId, opts) => { return await API.post({ url: `/api/apps/${appId}/backups/search`, body: opts, }) }, - createManualBackup: async appId => { - return await API.post({ - url: `/api/apps/${appId}/backups`, - }) - }, deleteBackup: async (appId, backupId) => { return await API.delete({ url: `/api/apps/${appId}/backups/${backupId}`, }) }, updateBackup: async (appId, backupId, name) => { - return await API.patch({ + return await API.patch({ url: `/api/apps/${appId}/backups/${backupId}`, body: { name }, })