-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't allow to set child element as parent. #19
Conversation
src/routes/pages.js
Outdated
@@ -24,6 +24,18 @@ router.get('/page/edit/:id', async (req, res, next) => { | |||
let page = await Pages.get(pageId); | |||
let pagesAvailable = await Pages.getAll(); | |||
|
|||
(function childrenRemove(parent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- нужно оформить в виде нормального метода класса, с понятным названием и документацией.
- эта логика не должна быть в роутах. Скорее в модели.
src/routes/pages.js
Outdated
@@ -24,6 +24,18 @@ router.get('/page/edit/:id', async (req, res, next) => { | |||
let page = await Pages.get(pageId); | |||
let pagesAvailable = await Pages.getAll(); | |||
|
|||
(function childrenRemove(parent) { | |||
pagesAvailable.forEach((item, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
метод не должен использовать внешние переменные
src/controllers/pages.js
Outdated
/** | ||
* Change wrong pages to null | ||
* | ||
* @returns {Promise<Page[]>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
она еще true|false возвращает. Надо описать, когда какое значение возвращается и для чего
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true false возвращает стрелочная функция а не метод а метод всегда возвращает array
static async getWithoutChildren(parent) { | ||
let pagesAvailable = this.removeChildren(await Pages.getAll(), parent); | ||
|
||
return pagesAvailable.filter((item) => item !== null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут может быть не только array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно по подробнее
pages.getAll всегда возвращает array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
твоя функция возвращает не только array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
функция в любом случае возвращает array так как там будет хотя бы сам вызываемый элемент parent
static async getWithoutChildren(parent) { | ||
let pagesAvailable = this.removeChildren(await Pages.getAll(), parent); | ||
|
||
return pagesAvailable.filter((item) => item !== null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
твоя функция возвращает не только array
src/controllers/pages.js
Outdated
/** | ||
* Change wrong pages to null | ||
* | ||
* @returns page[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не правильно задокументированы типы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и не описаны параметры
src/controllers/pages.js
Outdated
} | ||
|
||
/** | ||
* Change wrong pages to null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не понятное описание
src/controllers/pages.js
Outdated
* @param {string} parent - id of current page | ||
* @returns {Promise<Page[]>} | ||
*/ | ||
static async getWithoutChildren(parent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAllExceptChildrends
src/routes/pages.js
Outdated
@@ -22,7 +22,7 @@ router.get('/page/edit/:id', async (req, res, next) => { | |||
|
|||
try { | |||
let page = await Pages.get(pageId); | |||
let pagesAvailable = await Pages.getAll(); | |||
let pagesAvailable = await Pages.getAllExceptChildrends(pageId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let pagesAvailable = await Pages.getAllExceptChildrends(pageId); | |
let pagesAvailable = await Pages.getAllExceptChildrens(pageId); |
src/controllers/pages.js
Outdated
@@ -41,6 +41,38 @@ class Pages { | |||
return Model.getAll(); | |||
} | |||
|
|||
/** | |||
* @static | |||
* Return all pages without children pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Return all pages without children pages | |
* Return all pages without children of passed page |
src/controllers/pages.js
Outdated
* @static | ||
* Set all children elements to null | ||
* | ||
* @param {Array<?Page>} pagesAvailable - Array of all pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {Array<?Page>} pagesAvailable - Array of all pages | |
* @param {Page[]} [pagesAvailable] - Array of all pages |
Co-Authored-By: cabad11 <44175180+cabad11@users.noreply.github.com>
…am/codex.docs into child-element-as-parent
* @static | ||
* Set all children elements to null | ||
* | ||
* @param {Page[]} [pagesAvailable] - Array of all pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
разве этот параметр опционален? не нужны квадратные скобки
Resolves #15