Skip to content

Commit

Permalink
Update logic for author field
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Jun 27, 2024
1 parent 9c0e070 commit 9bad5a2
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions admin/src/api/post/content-types/post/lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function validateFields(result, is_from_update) {
if (Object.keys(result).length <= 3) {
return;
}

if (!result.title) {
const error = new YupValidationError({
path: "title",
Expand All @@ -167,17 +167,12 @@ function validateFields(result, is_from_update) {
});
throw error;
}

// required author when add post
if (!is_from_update && result.author.connect.length == 0) {
const error = new YupValidationError({
path: "author",
message: "This value is required.",
});
throw error;
}
// required author when update post
if (is_from_update && result.author.disconnect.length > 0) {

if (
(result.author.disconnect.length > 0 &&
result.author.connect.length == 0) ||
(result.author.connect.length == 0 && result.author.disconnect.length == 0)
) {
const error = new YupValidationError({
path: "author",
message: "This value is required.",
Expand Down

0 comments on commit 9bad5a2

Please sign in to comment.