delete derived component endpoint

This commit is contained in:
michael shanks 2019-07-27 07:43:03 +01:00
parent d70f14d6bc
commit 55bf142a95
5 changed files with 29 additions and 6 deletions

View File

@ -1 +0,0 @@
{"_name":"newTextBox","_component":"./customComponents/textbox","label":"something else"}

View File

@ -10,7 +10,8 @@ const {
savePackage,
getApps,
saveDerivedComponent,
renameDerivedComponent
renameDerivedComponent,
deleteDerivedComponent
} = require("../utilities/builder");
const builderPath = resolve(__dirname, "../builder");
@ -174,11 +175,14 @@ module.exports = (config, app) => {
ctx.request.body.newname);
ctx.response.status = StatusCodes.OK;
})
.delete("/_builder/api/:appname/derivedcomponent", async (ctx) => {
.delete("/_builder/api/:appname/derivedcomponent/*", async (ctx) => {
const name = ctx.request.path.replace(
`/_builder/api/${ctx.params.appname}/derivedcomponent/`, "");
await deleteDerivedComponent(
config,
ctx.params.appname,
ctx.request.body.name);
name);
ctx.response.status = StatusCodes.OK;
})
.get("/:appname", async (ctx) => {

View File

@ -118,5 +118,11 @@ it("should be able to rename derived component", async () => {
});
it("should be able to delete derived component", async () => {
await app.delete("/_builder/api/testApp/derivedcomponent/anotherSubFolder/newTextBox")
.expect(statusCodes.OK);
const componentFile = "./appPackages/testApp/components/anotherSubFolder/newTextBox.json";
const componentDir = "./appPackages/testApp/components/anotherSubFolder";
expect(await pathExists(componentFile)).toBe(false);
expect(await pathExists(componentDir)).toBe(false);
});

View File

@ -71,6 +71,7 @@ module.exports = () => {
post: (url, body) => postRequest(server,url,body),
patch: (url, body) => patchRequest(server,url,body),
get: (url) => getRequest(server, url),
delete: (url) => deleteRequest(server, url),
credentials: {
masterOwner: {
username: masterOwnerName,
@ -121,6 +122,12 @@ const postRequest = (server, url, body) =>
.send(body)
.set('Accept', 'application/json');
const deleteRequest = (server, url) =>
request(server)
.delete(url)
.set('Accept', 'application/json');
const getRequest = (server, url) =>
request(server)
.get(url)

View File

@ -10,7 +10,8 @@ const {
stat,
ensureDir,
rename,
unlink
unlink,
rmdir
} = require("fs-extra");
const {
resolve,
@ -94,7 +95,13 @@ module.exports.renameDerivedComponent = async (config, appname, oldName, newName
module.exports.deleteDerivedComponent = async (config, appname, name) => {
const appPath = appPackageFolder(config, appname);
await unlink(componentPath(appPath, name));
const componentFile = componentPath(appPath, name);
await unlink(componentFile);
const dir = dirname(componentFile);
if((await readdir(dir)).length === 0) {
await rmdir(dir);
}
}
const getRootComponents = async (appPath, pages ,lib) => {