From fc6fbd52bb50eb57b1066a4d1a26a07b886252d2 Mon Sep 17 00:00:00 2001 From: Marcos Pimentel Date: Fri, 15 Sep 2023 21:13:20 -0300 Subject: [PATCH] feat: req12 -refac --- src/services/postService.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/postService.js b/src/services/postService.js index c7a106d..3fb150d 100644 --- a/src/services/postService.js +++ b/src/services/postService.js @@ -11,10 +11,10 @@ const verifyCategories = async (categoryIds) => { }; const create = async ({ title, content, categoryIds, userId }) => { - const errorJoi = createPostValidation({ title, content, categoryIds }); - if (errorJoi) return { error: { status: 400, message: errorJoi.details[0].message } }; - const error = await verifyCategories(categoryIds); - if (error) return error; + const error = createPostValidation({ title, content, categoryIds }); + if (error) return { error }; + const categoryNotFound = await verifyCategories(categoryIds); + if (categoryNotFound) return categoryNotFound; const result = await sequelize.transaction(async (t) => { const { dataValues } = await BlogPost.create({ title, content, userId }, { transaction: t }); const postCategoriesList = categoryIds.map((categoryId) => ({ postId: dataValues.id, categoryId }));