Skip to content

Commit

Permalink
Fix - form validation and slug regeneration issue with resource
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Jun 25, 2024
1 parent 89e0059 commit e3521da
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions admin/src/api/post/content-types/post/lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ async function modifyContentAndSetErrorMsg(event) {
// validate input fields
validateFields(result);

if (result.is_resource && result.title) {
// generate slug from title
event.params.data.slug = generateSlug(result.title, result.slug);
}

// generate table of contents
await generateTOC(result, event);
await generateNewToc(result, event);
Expand Down Expand Up @@ -153,27 +148,62 @@ function generateRandomNumber() {

function validateFields(result) {
// set required message for summary,tags and meta_description
if (!result.title) {
const error = new YupValidationError({
path: "title",
message: "This value is required.",
});
throw error;
}
if (result.tags && result.tags.length == 0) {
const error = new YupValidationError({
path: "tags",
message: "This value is required.",
});
throw error;
}
if (result.author.connect.length == 0) {
const error = new YupValidationError({
path: "author",
message: "This value is required.",
});
throw error;
}
if (!result.summary) {
const error = new YupValidationError({
path: "summary",
message: "This value is required.",
});
throw error;
}
if (result.summary && result.summary.length > 200) {
const error = new YupValidationError({
path: "summary",
message: "Allow max 200 chars only",
});
throw error;
}
if (!result.meta_description) {
const error = new YupValidationError({
path: "meta_description",
message: "This value is required.",
});
throw error;
}
if (result.meta_description && result.meta_description.length > 160) {
const error = new YupValidationError({
path: "meta_description",
message: "Allow max 160 chars only",
});
throw error;
}
if (result.blog_content == '') {
const error = new YupValidationError({
path: "blog_content",
message: "This value is required.",
});
throw error;
}
}

async function generateTOC(result, event) {
Expand Down

0 comments on commit e3521da

Please sign in to comment.