From fd1998616e8fb7f1e89667051b3624671a5b790f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 27 Nov 2024 16:17:22 +0000 Subject: [PATCH] Update backups endpoints to use TS --- packages/frontend-core/src/api/backups.js | 46 --------------- packages/frontend-core/src/api/backups.ts | 70 +++++++++++++++++++++++ 2 files changed, 70 insertions(+), 46 deletions(-) delete mode 100644 packages/frontend-core/src/api/backups.js create mode 100644 packages/frontend-core/src/api/backups.ts diff --git a/packages/frontend-core/src/api/backups.js b/packages/frontend-core/src/api/backups.js deleted file mode 100644 index 40546b6f66..0000000000 --- a/packages/frontend-core/src/api/backups.js +++ /dev/null @@ -1,46 +0,0 @@ -export const buildBackupsEndpoints = API => ({ - searchBackups: async ({ appId, trigger, type, page, startDate, endDate }) => { - const opts = {} - 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 - } - 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({ - url: `/api/apps/${appId}/backups/${backupId}`, - body: { name }, - }) - }, - - restoreBackup: async ({ appId, backupId, name }) => { - return await API.post({ - url: `/api/apps/${appId}/backups/${backupId}/import`, - body: { name }, - }) - }, -}) diff --git a/packages/frontend-core/src/api/backups.ts b/packages/frontend-core/src/api/backups.ts new file mode 100644 index 0000000000..4010f17a74 --- /dev/null +++ b/packages/frontend-core/src/api/backups.ts @@ -0,0 +1,70 @@ +import { PutResponse } from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface BackupsEndpoints { + createManualBackup: ( + appId: string + ) => Promise<{ backupId: string; message: string }> + deleteBackup: ( + appId: string, + backupId: string + ) => Promise<{ message: string }> + updateBackup: ( + appId: string, + backupId: string, + name: string + ) => Promise + restoreBackup: ( + appId: string, + backupId: string, + name: string + ) => Promise<{ restoreId: string; message: string }> + + // Missing request or response types + searchBackups: (opts: any) => Promise +} + +export const buildBackupsEndpoints = ( + API: BaseAPIClient +): BackupsEndpoints => ({ + 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 + } + 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({ + url: `/api/apps/${appId}/backups/${backupId}`, + body: { name }, + }) + }, + restoreBackup: async (appId, backupId, name) => { + return await API.post({ + url: `/api/apps/${appId}/backups/${backupId}/import`, + body: { name }, + }) + }, +})