Fix some article bugs (#1102)

This commit is contained in:
LautaroCesso 2021-12-01 20:00:36 -03:00 committed by GitHub
parent 4b9a55b334
commit 5a1b558a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 17 deletions

View File

@ -14,7 +14,7 @@ DataValidator::with('CustomValidations', true);
* *
* @apiPermission staff2 * @apiPermission staff2
* *
* @apiParam {String} name Name of the new article. * @apiParam {String} title Title of the new article.
* @apiParam {String} content Content of the new article. * @apiParam {String} content Content of the new article.
* @apiParam {Number} position Position of the new article. * @apiParam {Number} position Position of the new article.
* @apiParam {Number} topicId Id of the articles's topic. * @apiParam {Number} topicId Id of the articles's topic.
@ -22,10 +22,9 @@ DataValidator::with('CustomValidations', true);
* @apiParam image_i The image file of index `i` (mutiple params accepted) * @apiParam image_i The image file of index `i` (mutiple params accepted)
* *
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* @apiUse INVALID_NAME * @apiUse INVALID_TITLE
* @apiUse INVALID_CONTENT * @apiUse INVALID_CONTENT
* @apiUse INVALID_TOPIC * @apiUse INVALID_TOPIC
* @apiUse INVALID_FILE
* *
* @apiSuccess {Object} data Article info * @apiSuccess {Object} data Article info
* @apiSuccess {Number} data.articleId Article id * @apiSuccess {Number} data.articleId Article id
@ -39,9 +38,9 @@ class AddArticleController extends Controller {
return [ return [
'permission' => 'staff_2', 'permission' => 'staff_2',
'requestData' => [ 'requestData' => [
'name' => [ 'title' => [
'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_TITLE
], ],
'content' => [ 'content' => [
'validation' => DataValidator::content(), 'validation' => DataValidator::content(),
@ -64,7 +63,7 @@ class AddArticleController extends Controller {
$article = new Article(); $article = new Article();
$article->setProperties([ $article->setProperties([
'title' => Controller::request('name', true), 'title' => Controller::request('title', true),
'content' => $this->replaceWithImagePaths($imagePaths, $content), 'content' => $this->replaceWithImagePaths($imagePaths, $content),
'lastEdited' => Date::getCurrentDate(), 'lastEdited' => Date::getCurrentDate(),
'position' => Controller::request('position') || 1 'position' => Controller::request('position') || 1

View File

@ -22,6 +22,7 @@ DataValidator::with('CustomValidations', true);
* *
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* @apiUse INVALID_TOPIC * @apiUse INVALID_TOPIC
* @apiUse INVALID_NAME
* *
* @apiSuccess {Object} data Empty object * @apiSuccess {Object} data Empty object
* *
@ -42,8 +43,7 @@ class EditTopicController extends Controller {
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ]
] ]
]; ];
} }

View File

@ -17,7 +17,7 @@ DataValidator::with('CustomValidations', true);
* @apiParam {Number} articleId Id of the article. * @apiParam {Number} articleId Id of the article.
* @apiParam {Number} topicId Id of the topic of the article. Optional. * @apiParam {Number} topicId Id of the topic of the article. Optional.
* @apiParam {String} content The new content of the article. Optional. * @apiParam {String} content The new content of the article. Optional.
* @apiParam {String} name The new name of the article. Optional. * @apiParam {String} title The new title of the article. Optional.
* @apiParam {Number} position The new position of the article. Optional. * @apiParam {Number} position The new position of the article. Optional.
* @apiParam {Number} images The number of images in the content * @apiParam {Number} images The number of images in the content
* @apiParam image_i The image file of index `i` (mutiple params accepted) * @apiParam image_i The image file of index `i` (mutiple params accepted)
@ -25,6 +25,7 @@ DataValidator::with('CustomValidations', true);
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* @apiUse INVALID_TOPIC * @apiUse INVALID_TOPIC
* @apiUse INVALID_FILE * @apiUse INVALID_FILE
* @apiUse INVALID_TITLE
* *
* @apiSuccess {Object} data Empty object * @apiSuccess {Object} data Empty object
* *
@ -42,17 +43,17 @@ class EditArticleController extends Controller {
'validation' => DataValidator::dataStoreId('article'), 'validation' => DataValidator::dataStoreId('article'),
'error' => ERRORS::INVALID_TOPIC 'error' => ERRORS::INVALID_TOPIC
], ],
'name' => [ 'title' => [
'validation' => DataValidator::oneOf( 'validation' => DataValidator::oneOf(
DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE),
DataValidator::nullType() DataValidator::nullType()
), ),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_TITLE
], ],
'content' => [ 'content' => [
'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()), 'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()),
'error' => ERRORS::INVALID_CONTENT 'error' => ERRORS::INVALID_CONTENT
], ]
] ]
]; ];
} }
@ -81,8 +82,8 @@ class EditArticleController extends Controller {
$article->content = $this->replaceWithImagePaths($imagePaths, $content); $article->content = $this->replaceWithImagePaths($imagePaths, $content);
} }
if(Controller::request('name')) { if(Controller::request('title')) {
$article->title = Controller::request('name'); $article->title = Controller::request('title');
} }
if(Controller::request('position')) { if(Controller::request('position')) {

View File

@ -21,6 +21,9 @@ use Respect\Validation\Validator as DataValidator;
* @apiParam {Boolean} sendEmailOnNewTicket Indicates if it receives an email when a new ticket is created. * @apiParam {Boolean} sendEmailOnNewTicket Indicates if it receives an email when a new ticket is created.
* *
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* @apiUse INVALID_EMAIL
* @apiUse INVALID_PASSWORD
* @apiUse INVALID_LEVEL
* @apiUse INVALID_STAFF * @apiUse INVALID_STAFF
* *
* @apiSuccess {Object} data Empty object * @apiSuccess {Object} data Empty object
@ -52,7 +55,6 @@ class EditStaffController extends Controller {
'validation' => DataValidator::oneOf(DataValidator::between(1, 3, true), DataValidator::falseVal()), 'validation' => DataValidator::oneOf(DataValidator::between(1, 3, true), DataValidator::falseVal()),
'error' => ERRORS::INVALID_LEVEL 'error' => ERRORS::INVALID_LEVEL
] ]
] ]
]; ];
} }