Skip to content

Commit

Permalink
feat: req12 -refac
Browse files Browse the repository at this point in the history
  • Loading branch information
dopimentel committed Feb 21, 2024
1 parent 56d30ea commit fc6fbd5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/postService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down

0 comments on commit fc6fbd5

Please sign in to comment.