add apis and svelte store

This commit is contained in:
Peter Clement 2022-10-18 19:00:19 +01:00
parent 81aa2fbfcc
commit 7ae1e3a3ee
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import { writable } from "svelte/store"
import { API } from "api"
export function createBackupsStore() {
const { subscribe, set } = writable([])
async function load() {
set([
{
trigger: "PUBLISH",
name: "A Backup",
date: "1665407451",
userId: "Peter Clement",
contents: [
{ datasources: ["datasource1", "datasource2"] },
{ screens: ["screen1", "screen2"] },
{ automations: ["automation1", "automation2"] },
],
},
])
}
async function searchBackups(appId) {
return API.searchBackups(appId)
}
async function createManualBackup(appId, name) {
let resp = API.createManualBackup(appId, name)
return resp
}
return {
subscribe,
load,
createManualBackup,
searchBackups,
}
}
export const backups = createBackupsStore()

View File

@ -9,3 +9,4 @@ export { templates } from "./templates"
export { licensing } from "./licensing"
export { groups } from "./groups"
export { plugins } from "./plugins"
export { backups } from "./backups"

View File

@ -0,0 +1,20 @@
export const buildBackupsEndpoints = API => ({
/**
* Gets a list of users in the current tenant.
*/
searchBackups: async appId => {
return await API.post({
url: `/api/apps/${appId}/backups/search`,
body: {
trigger: "MANUAL",
},
})
},
createManualBackup: async ({ appId, name }) => {
return await API.post({
url: `/api/apps/${appId}/backups`,
body: { name },
})
},
})

View File

@ -25,6 +25,7 @@ import { buildViewEndpoints } from "./views"
import { buildLicensingEndpoints } from "./licensing"
import { buildGroupsEndpoints } from "./groups"
import { buildPluginEndpoints } from "./plugins"
import { buildBackupsEndpoints } from "./backups"
const defaultAPIClientConfig = {
/**
@ -245,5 +246,6 @@ export const createAPIClient = config => {
...buildLicensingEndpoints(API),
...buildGroupsEndpoints(API),
...buildPluginEndpoints(API),
...buildBackupsEndpoints(API),
}
}