Skip to content

Commit

Permalink
Fix author validation
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Jun 27, 2024
1 parent 374f822 commit ca7b3d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy Admin-panel
on:
push:
branches:
- fix-update-form-author-issue
- main

jobs:
deploy-admin-panel:
Expand Down
14 changes: 7 additions & 7 deletions admin/src/api/post/content-types/post/lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand All @@ -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.",
Expand Down

0 comments on commit ca7b3d2

Please sign in to comment.