From ca7b3d273a50344604fcfb3b7e7cdaae1368623b Mon Sep 17 00:00:00 2001 From: cp-dharti-r Date: Thu, 27 Jun 2024 14:49:35 +0530 Subject: [PATCH] Fix author validation --- .github/workflows/admin.yml | 2 +- .../src/api/post/content-types/post/lifecycles.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/admin.yml b/.github/workflows/admin.yml index 104bd11..8221780 100644 --- a/.github/workflows/admin.yml +++ b/.github/workflows/admin.yml @@ -3,7 +3,7 @@ name: Deploy Admin-panel on: push: branches: - - fix-update-form-author-issue + - main jobs: deploy-admin-panel: diff --git a/admin/src/api/post/content-types/post/lifecycles.js b/admin/src/api/post/content-types/post/lifecycles.js index d6a5fe8..948ede3 100644 --- a/admin/src/api/post/content-types/post/lifecycles.js +++ b/admin/src/api/post/content-types/post/lifecycles.js @@ -9,11 +9,11 @@ const puppeteer = require("puppeteer"); module.exports = { async beforeCreate(event) { - await modifyContentAndSetErrorMsg(event); + await modifyContentAndSetErrorMsg(event, false); }, async beforeUpdate(event) { - await modifyContentAndSetErrorMsg(event); + await modifyContentAndSetErrorMsg(event, true); }, async afterUpdate(event) { @@ -61,12 +61,12 @@ module.exports = { }, }; -async function modifyContentAndSetErrorMsg(event) { +async function modifyContentAndSetErrorMsg(event, is_from_update) { const result = event.params.data; if (result) { // validate input fields - validateFields(result); + validateFields(result, is_from_update); // generate table of contents await generateTOC(result, event); @@ -146,12 +146,12 @@ function generateRandomNumber() { return Math.floor(Math.random() * 9000000000) + 1000000000; } -function validateFields(result) { +function validateFields(result, is_from_update) { // no need to validate if it's only going to publish or unpublish if (Object.keys(result).length <= 3) { return; } - + // set required message for summary,tags and meta_description if (!result.title) { const error = new YupValidationError({ @@ -167,7 +167,7 @@ function validateFields(result) { }); throw error; } - if (result.author.connect.length == 0) { + if (!is_from_update && result.author.connect.length == 0) { const error = new YupValidationError({ path: "author", message: "This value is required.",