diff --git a/lib/guides/queries.ts b/lib/guides/queries.ts index 07946a3..e2c6055 100644 --- a/lib/guides/queries.ts +++ b/lib/guides/queries.ts @@ -1,6 +1,6 @@ import "server-only"; -import { and, asc, desc, eq, inArray, isNotNull, isNull, ne, sql } from "drizzle-orm"; +import { and, asc, desc, eq, inArray, isNotNull, isNull, ne, or, sql } from "drizzle-orm"; import * as z from "zod"; import { getDb } from "@/db"; @@ -336,7 +336,10 @@ async function populatedSections(guideId: string) { when 'constellations' then exists (select 1 from ${constellationRecommendations} r join ${constellationConditions} c on c.id = r.condition_id where c.guide_id = ${guideId}) when 'team' then exists (select 1 from ${teamCompositions} t where t.guide_id = ${guideId}) else exists (select 1 from ${extraSectionRows} r where r.section_id = ${guideSections.id}) end`, - }).from(guideSections).where(and(eq(guideSections.guideId, guideId), eq(guideSections.enabled, true))) + }).from(guideSections).where(and( + eq(guideSections.guideId, guideId), + or(eq(guideSections.enabled, true), eq(guideSections.kind, "extra")), + )) .orderBy(asc(guideSections.sortOrder)); return rows.filter((row) => row.populated).map((row) => row.section); } @@ -372,7 +375,12 @@ async function getGuideContent(slug: string, publicOnly: boolean, selectedSectio [...row.character.ascension, ...row.character.leveling].flatMap((group) => group.items.map((item) => item.key)), )]; const [sections, weaponConditionsRows, artifactConditionRows, profile, constellationGroups, teamConditionRows, teams, aliases, materials, poster, bleeding] = await runWithConcurrency([ - () => getDb().select().from(guideSections).where(and(eq(guideSections.guideId, row.guide.id), eq(guideSections.enabled, true))).orderBy(asc(guideSections.sortOrder)), + () => getDb().select().from(guideSections).where(and( + eq(guideSections.guideId, row.guide.id), + ...(publicOnly + ? [or(eq(guideSections.enabled, true), eq(guideSections.kind, "extra"))] + : [eq(guideSections.enabled, true)]), + )).orderBy(asc(guideSections.sortOrder)), () => wants("weapon") ? getDb().select().from(weaponConditions).where(eq(weaponConditions.guideId, row.guide.id)).orderBy(asc(weaponConditions.sortOrder)) : Promise.resolve([]), () => wants("artifact") ? getDb().select().from(artifactConditions).where(eq(artifactConditions.guideId, row.guide.id)).orderBy(asc(artifactConditions.sortOrder)) : Promise.resolve([]), () => wants("artifact") ? getDb().select().from(artifactProfiles).where(eq(artifactProfiles.guideId, row.guide.id)).limit(1) : Promise.resolve([]),