fix: pages and blogs query only fetch published

This commit is contained in:
RizqiSyahrendra 2025-03-14 15:41:14 +07:00
parent 36868e4af0
commit 0e2f7da4c0
2 changed files with 9 additions and 1 deletions

View File

@ -13,7 +13,10 @@ type FetchBlogParams = {
export async function fetchBlog({ page, search = "", categoryId, tagId }: FetchBlogParams = {}) { export async function fetchBlog({ page, search = "", categoryId, tagId }: FetchBlogParams = {}) {
const payload = await getPayload({ config: payloadConfig }); const payload = await getPayload({ config: payloadConfig });
const queryCondition: Where = {}; const queryCondition: Where = {
_status: { equals: "published" },
};
if (!!search) { if (!!search) {
queryCondition["title"] = { queryCondition["title"] = {
contains: search, contains: search,
@ -57,6 +60,7 @@ export async function fetchBlogSuggestion() {
const limitPerPage = 2; const limitPerPage = 2;
const blogCountQuery = await payload.count({ const blogCountQuery = await payload.count({
collection: "blogs", collection: "blogs",
where: { _status: { equals: "published" } },
}); });
// randomize page // randomize page
@ -92,6 +96,7 @@ export async function fetchBlogDetail(slug: string | undefined) {
const blogDataQuery = await payload.find({ const blogDataQuery = await payload.find({
collection: "blogs", collection: "blogs",
where: { where: {
_status: { equals: "published" },
slug: { equals: slug }, slug: { equals: slug },
}, },
limit: 1, limit: 1,
@ -118,6 +123,7 @@ export async function fetchBlogCategoryBySlug(slug: string) {
const category = await payload.find({ const category = await payload.find({
collection: "blogCategories", collection: "blogCategories",
where: { where: {
_status: { equals: "published" },
slug: { equals: slug }, slug: { equals: slug },
}, },
}); });
@ -134,6 +140,7 @@ export async function fetchBlogTagBySlug(slug: string) {
const tag = await payload.find({ const tag = await payload.find({
collection: "blogTags", collection: "blogTags",
where: { where: {
_status: { equals: "published" },
slug: { equals: slug }, slug: { equals: slug },
}, },
}); });

View File

@ -11,6 +11,7 @@ export const fetchPageBySlug = async ({ slug }: { slug: string | undefined }) =>
pagination: false, pagination: false,
// overrideAccess: draft, // overrideAccess: draft,
where: { where: {
_status: { equals: "published" },
slug: { slug: {
equals: slug, equals: slug,
}, },