update
This commit is contained in:
+53
-4
@@ -113,23 +113,72 @@ export async function getActiveCatalog() {
|
||||
|
||||
export async function listGuideCards(includeTrash = false) {
|
||||
const rows = await getDb()
|
||||
.select({ guide: guides, cover: media })
|
||||
.select({
|
||||
id: guides.id,
|
||||
characterKey: guides.characterKey,
|
||||
name: guides.name,
|
||||
overview: guides.overview,
|
||||
version: guides.version,
|
||||
updatedAt: guides.updatedAt,
|
||||
trashedAt: guides.trashedAt,
|
||||
isPublic: guides.isPublic,
|
||||
coverObjectKey: media.objectKey,
|
||||
})
|
||||
.from(guides)
|
||||
.innerJoin(media, eq(media.id, guides.coverMediaId))
|
||||
.where(includeTrash ? isNotNull(guides.trashedAt) : isNull(guides.trashedAt))
|
||||
.orderBy(asc(guides.sortOrder), asc(guides.name));
|
||||
return rows.map(({ guide, cover }) => ({ ...guide, coverUrl: publicMediaUrl(cover.objectKey) }));
|
||||
return rows.map(({ coverObjectKey, ...guide }) => ({
|
||||
...guide,
|
||||
coverUrl: publicMediaUrl(coverObjectKey),
|
||||
}));
|
||||
}
|
||||
|
||||
export async function listPublicGuideCards() {
|
||||
const [rows, aliases] = await Promise.all([getDb()
|
||||
.select({ guide: guides, cover: media })
|
||||
.select({
|
||||
id: guides.id,
|
||||
characterKey: guides.characterKey,
|
||||
slug: guides.slug,
|
||||
name: guides.name,
|
||||
overview: guides.overview,
|
||||
version: guides.version,
|
||||
coverObjectKey: media.objectKey,
|
||||
})
|
||||
.from(guides)
|
||||
.innerJoin(media, eq(media.id, guides.coverMediaId))
|
||||
.where(and(eq(guides.isPublic, true), isNull(guides.trashedAt)))
|
||||
.orderBy(asc(guides.sortOrder), asc(guides.name)), getDb().select().from(glossaryAliases)]);
|
||||
const grouped = aliasesByItem(aliases);
|
||||
return rows.map(({ guide, cover }) => ({ ...guide, aliases: grouped.character.get(guide.characterKey) ?? [], coverUrl: publicMediaUrl(cover.objectKey) }));
|
||||
return rows.map(({ coverObjectKey, ...guide }) => ({
|
||||
...guide,
|
||||
aliases: grouped.character.get(guide.characterKey) ?? [],
|
||||
coverUrl: publicMediaUrl(coverObjectKey),
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getGuideEditorHeader(characterKey: string) {
|
||||
const [row] = await getDb()
|
||||
.select({
|
||||
id: guides.id,
|
||||
characterKey: guides.characterKey,
|
||||
slug: guides.slug,
|
||||
name: guides.name,
|
||||
version: guides.version,
|
||||
coverObjectKey: media.objectKey,
|
||||
})
|
||||
.from(guides)
|
||||
.innerJoin(media, eq(media.id, guides.coverMediaId))
|
||||
.where(and(eq(guides.characterKey, characterKey), isNull(guides.trashedAt)))
|
||||
.limit(1);
|
||||
if (!row) return null;
|
||||
const sections = await getDb()
|
||||
.select()
|
||||
.from(guideSections)
|
||||
.where(eq(guideSections.guideId, row.id))
|
||||
.orderBy(asc(guideSections.sortOrder));
|
||||
const { coverObjectKey, ...guide } = row;
|
||||
return { ...guide, coverUrl: publicMediaUrl(coverObjectKey), sections };
|
||||
}
|
||||
|
||||
export async function getGuideByCharacterKey(characterKey: string) {
|
||||
|
||||
Reference in New Issue
Block a user