mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 15:05:26 +02:00
bugfix
This commit is contained in:
parent
e2d412ead3
commit
a8b8ed0032
6 changed files with 31 additions and 32 deletions
|
@ -21,14 +21,6 @@ class Aliases {
|
|||
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async removeById(id) {
|
||||
return Alias.destroyByEntityId(id);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Aliases;
|
||||
|
|
|
@ -186,6 +186,10 @@ class Pages {
|
|||
throw new Error('Page with given id does not exist');
|
||||
}
|
||||
|
||||
const alias = await Alias.get(page.uri);
|
||||
|
||||
await alias.destroy();
|
||||
|
||||
return page.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ const binaryMD5 = require('../utils/crypto');
|
|||
|
||||
/**
|
||||
* @class Alias
|
||||
* @classdesc Alias model
|
||||
*
|
||||
* @property {string} _id - alias id
|
||||
* @property {string} hash - alias binary hash
|
||||
* @property {string} type - entity type
|
||||
|
@ -47,18 +49,6 @@ class Alias {
|
|||
return new Alias(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async destroyByEntityId(id) {
|
||||
await aliasesDb.remove({id});
|
||||
|
||||
delete this._id;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
|
@ -136,6 +126,17 @@ class Alias {
|
|||
|
||||
return alias.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Alias>}
|
||||
*/
|
||||
async destroy() {
|
||||
await aliasesDb.remove({_id: this._id});
|
||||
|
||||
delete this._id;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Alias;
|
||||
|
|
|
@ -117,16 +117,21 @@ router.delete('/page/:id', async (req, res) => {
|
|||
const pageBeforeId = parentPageOrder.getPageBefore(page._id);
|
||||
const pageAfterId = parentPageOrder.getPageAfter(page._id);
|
||||
|
||||
let responsePage;
|
||||
let pageToRedirect;
|
||||
if (pageBeforeId) {
|
||||
responsePage = await Pages.get(pageBeforeId);
|
||||
pageToRedirect = await Pages.get(pageBeforeId);
|
||||
} else if (pageAfterId) {
|
||||
responsePage = await Pages.get(pageAfterId);
|
||||
pageToRedirect = await Pages.get(pageAfterId);
|
||||
} else {
|
||||
responsePage = page._parent !== "0" ? await Pages.get(page._parent) : null;
|
||||
pageToRedirect = page._parent !== "0" ? await Pages.get(page._parent) : null;
|
||||
}
|
||||
|
||||
// remove current page and go deeper to remove children with orders
|
||||
/**
|
||||
* remove current page and go deeper to remove children with orders
|
||||
*
|
||||
* @param startFrom
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function deleteRecursively(startFrom) {
|
||||
let order = [];
|
||||
try {
|
||||
|
@ -138,24 +143,21 @@ router.delete('/page/:id', async (req, res) => {
|
|||
await deleteRecursively(id);
|
||||
});
|
||||
|
||||
await Pages.remove(startFrom);
|
||||
try {
|
||||
await Pages.remove(startFrom);
|
||||
await PagesOrder.remove(startFrom);
|
||||
await Aliases.removeById(startFrom);
|
||||
} catch (e) {}
|
||||
|
||||
}
|
||||
|
||||
await deleteRecursively(req.params.id);
|
||||
|
||||
// remove also from parent's order
|
||||
parentPageOrder.remove(req.params.id);
|
||||
await Aliases.removeById(req.params.id);
|
||||
await parentPageOrder.save();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
result: responsePage
|
||||
result: pageToRedirect
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(400).json({
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<div id="codex-editor"></div>
|
||||
<div class="writing-buttons">
|
||||
{% if page._id is not empty %}
|
||||
<span class="writing-buttons__remove" name="js-submit-remove">Remove</span>
|
||||
<span class="writing-buttons__remove" name="js-submit-remove">Remove</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if page is not empty %}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
</h1>
|
||||
<section class="page__content">
|
||||
{% for block in page.body.blocks %}
|
||||
{#Skip first header, because it is already showed as a Title#}
|
||||
{# Skip first header, because it is already showed as a Title #}
|
||||
{% if not (loop.first and block.type == 'header') %}
|
||||
{% if block.type in ['paragraph', 'header', 'list', 'code'] %}
|
||||
{% include './blocks/' ~ block.type ~ '.twig' with block.data %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue