1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-09 07:25:21 +02:00
This commit is contained in:
Murod Khaydarov 2019-01-25 06:06:52 +03:00
parent e2d412ead3
commit a8b8ed0032
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
6 changed files with 31 additions and 32 deletions

View file

@ -21,14 +21,6 @@ class Aliases {
return alias; return alias;
} }
/**
* @param id
* @returns {Promise<void>}
*/
static async removeById(id) {
return Alias.destroyByEntityId(id);
}
} }
module.exports = Aliases; module.exports = Aliases;

View file

@ -186,6 +186,10 @@ class Pages {
throw new Error('Page with given id does not exist'); throw new Error('Page with given id does not exist');
} }
const alias = await Alias.get(page.uri);
await alias.destroy();
return page.destroy(); return page.destroy();
} }
} }

View file

@ -13,6 +13,8 @@ const binaryMD5 = require('../utils/crypto');
/** /**
* @class Alias * @class Alias
* @classdesc Alias model
*
* @property {string} _id - alias id * @property {string} _id - alias id
* @property {string} hash - alias binary hash * @property {string} hash - alias binary hash
* @property {string} type - entity type * @property {string} type - entity type
@ -47,18 +49,6 @@ class Alias {
return new Alias(data); return new Alias(data);
} }
/**
* @param {string} id
* @returns {Promise<void>}
*/
static async destroyByEntityId(id) {
await aliasesDb.remove({id});
delete this._id;
return this;
}
/** /**
* @constructor * @constructor
* *
@ -136,6 +126,17 @@ class Alias {
return alias.save(); return alias.save();
} }
/**
* @returns {Promise<Alias>}
*/
async destroy() {
await aliasesDb.remove({_id: this._id});
delete this._id;
return this;
}
} }
module.exports = Alias; module.exports = Alias;

View file

@ -117,16 +117,21 @@ router.delete('/page/:id', async (req, res) => {
const pageBeforeId = parentPageOrder.getPageBefore(page._id); const pageBeforeId = parentPageOrder.getPageBefore(page._id);
const pageAfterId = parentPageOrder.getPageAfter(page._id); const pageAfterId = parentPageOrder.getPageAfter(page._id);
let responsePage; let pageToRedirect;
if (pageBeforeId) { if (pageBeforeId) {
responsePage = await Pages.get(pageBeforeId); pageToRedirect = await Pages.get(pageBeforeId);
} else if (pageAfterId) { } else if (pageAfterId) {
responsePage = await Pages.get(pageAfterId); pageToRedirect = await Pages.get(pageAfterId);
} else { } 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) { async function deleteRecursively(startFrom) {
let order = []; let order = [];
try { try {
@ -138,24 +143,21 @@ router.delete('/page/:id', async (req, res) => {
await deleteRecursively(id); await deleteRecursively(id);
}); });
await Pages.remove(startFrom);
try { try {
await Pages.remove(startFrom);
await PagesOrder.remove(startFrom); await PagesOrder.remove(startFrom);
await Aliases.removeById(startFrom);
} catch (e) {} } catch (e) {}
} }
await deleteRecursively(req.params.id); await deleteRecursively(req.params.id);
// remove also from parent's order // remove also from parent's order
parentPageOrder.remove(req.params.id); parentPageOrder.remove(req.params.id);
await Aliases.removeById(req.params.id);
await parentPageOrder.save(); await parentPageOrder.save();
res.json({ res.json({
success: true, success: true,
result: responsePage result: pageToRedirect
}); });
} catch (err) { } catch (err) {
res.status(400).json({ res.status(400).json({

View file

@ -49,7 +49,7 @@
<div id="codex-editor"></div> <div id="codex-editor"></div>
<div class="writing-buttons"> <div class="writing-buttons">
{% if page._id is not empty %} {% 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 %} {% endif %}
</div> </div>
{% if page is not empty %} {% if page is not empty %}

View file

@ -28,7 +28,7 @@
</h1> </h1>
<section class="page__content"> <section class="page__content">
{% for block in page.body.blocks %} {% 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 not (loop.first and block.type == 'header') %}
{% if block.type in ['paragraph', 'header', 'list', 'code'] %} {% if block.type in ['paragraph', 'header', 'list', 'code'] %}
{% include './blocks/' ~ block.type ~ '.twig' with block.data %} {% include './blocks/' ~ block.type ~ '.twig' with block.data %}