Merge pull request #423 from Budibase/feature/delete-apps
adds delete functionality to application
This commit is contained in:
commit
91b4850b69
|
@ -1,14 +1,25 @@
|
||||||
<script>
|
<script>
|
||||||
|
import { params, goto } from "@sveltech/routify"
|
||||||
import { Input, TextArea, Button } from "@budibase/bbui"
|
import { Input, TextArea, Button } from "@budibase/bbui"
|
||||||
import Title from "../TabTitle.svelte"
|
import Title from "../TabTitle.svelte"
|
||||||
|
import { del } from "builderStore/api"
|
||||||
|
|
||||||
let value = ""
|
let value = ""
|
||||||
let loading = false
|
let loading = false
|
||||||
|
|
||||||
const deleteApp = () => {
|
async function deleteApp() {
|
||||||
loading = true
|
loading = true
|
||||||
// Do stuff here to delete app!
|
const id = $params.application
|
||||||
// Navigate to start
|
const res = await del(`/api/${id}`)
|
||||||
|
const json = await res.json()
|
||||||
|
|
||||||
|
loading = false
|
||||||
|
if (res.ok) {
|
||||||
|
$goto("/")
|
||||||
|
return json
|
||||||
|
} else {
|
||||||
|
throw new Error(json)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ const { budibaseAppsDir } = require("../../utilities/budibaseDir")
|
||||||
const { exec } = require("child_process")
|
const { exec } = require("child_process")
|
||||||
const sqrl = require("squirrelly")
|
const sqrl = require("squirrelly")
|
||||||
const setBuilderToken = require("../../utilities/builder/setBuilderToken")
|
const setBuilderToken = require("../../utilities/builder/setBuilderToken")
|
||||||
|
const fs = require("fs-extra")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const db = new CouchDB(ClientDb.name(getClientId(ctx)))
|
const db = new CouchDB(ClientDb.name(getClientId(ctx)))
|
||||||
|
@ -106,6 +107,19 @@ exports.update = async function(ctx) {
|
||||||
ctx.body = response
|
ctx.body = response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.delete = async function(ctx) {
|
||||||
|
const db = new CouchDB(ClientDb.name(getClientId(ctx)))
|
||||||
|
const app = await db.get(ctx.params.applicationId)
|
||||||
|
const result = await db.remove(app)
|
||||||
|
await fs.rmdir(`${budibaseAppsDir()}/${ctx.params.applicationId}`, {
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx.status = 200
|
||||||
|
ctx.message = `Application ${app.name} deleted successfully.`
|
||||||
|
ctx.body = result
|
||||||
|
}
|
||||||
|
|
||||||
const createEmptyAppPackage = async (ctx, app) => {
|
const createEmptyAppPackage = async (ctx, app) => {
|
||||||
const templateFolder = resolve(
|
const templateFolder = resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
|
|
|
@ -14,5 +14,6 @@ router
|
||||||
)
|
)
|
||||||
.put("/api/:applicationId", authorized(BUILDER), controller.update)
|
.put("/api/:applicationId", authorized(BUILDER), controller.update)
|
||||||
.post("/api/applications", authorized(BUILDER), controller.create)
|
.post("/api/applications", authorized(BUILDER), controller.create)
|
||||||
|
.delete("/api/:applicationId", authorized(BUILDER), controller.delete)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
Loading…
Reference in New Issue