Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - form validation and slug regeneration issue with resource #160

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading