feat(guides): organize schemas and export teams
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { cleanLunarisText, constellationSnapshot } from "@/lib/catalog/lunaris";
|
||||
import {
|
||||
characterDetailSchema,
|
||||
cleanLunarisText,
|
||||
constellationSnapshot,
|
||||
} from "@/lib/catalog/lunaris";
|
||||
|
||||
describe("Lunaris character data", () => {
|
||||
it("removes display markup from constellation text", () => {
|
||||
@@ -20,4 +24,10 @@ describe("Lunaris character data", () => {
|
||||
iconKey: "catalog/1/constellations/UI_Talent_Test_01.webp",
|
||||
}]);
|
||||
});
|
||||
|
||||
it("accepts characters that do not have constellations", () => {
|
||||
const detail = characterDetailSchema.parse({ constellations: null });
|
||||
|
||||
expect(constellationSnapshot(detail, (icon) => icon)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ const constellationSchema = z.object({
|
||||
});
|
||||
|
||||
export const characterDetailSchema = z.object({
|
||||
constellations: z.record(z.string(), constellationSchema),
|
||||
constellations: z.record(z.string(), constellationSchema).nullish(),
|
||||
});
|
||||
|
||||
export function cleanLunarisText(value: string): string {
|
||||
@@ -32,7 +32,7 @@ export function constellationSnapshot(
|
||||
const result: CatalogConstellation[] = [];
|
||||
for (const index of Array.from({ length: 6 }, (_, itemIndex) => itemIndex)) {
|
||||
const level = index + 1;
|
||||
const item = value.constellations[`const${level}`];
|
||||
const item = value.constellations?.[`const${level}`];
|
||||
if (!item) continue;
|
||||
result.push({
|
||||
level,
|
||||
|
||||
@@ -125,4 +125,44 @@ export async function getLatestCatalogSyncJob() {
|
||||
return job ?? null;
|
||||
}
|
||||
|
||||
export async function getPublicTeamExport(teamId: string) {
|
||||
const [row] = await getDb()
|
||||
.select({ team: teamCompositions, guide: guides })
|
||||
.from(teamCompositions)
|
||||
.innerJoin(guides, eq(guides.id, teamCompositions.guideId))
|
||||
.innerJoin(
|
||||
guideSections,
|
||||
and(
|
||||
eq(guideSections.guideId, guides.id),
|
||||
eq(guideSections.slug, "team"),
|
||||
eq(guideSections.enabled, true),
|
||||
),
|
||||
)
|
||||
.where(and(eq(teamCompositions.id, teamId), isNull(guides.trashedAt)))
|
||||
.limit(1);
|
||||
if (!row) return null;
|
||||
|
||||
const members = await getDb()
|
||||
.select({ member: teamMembers, character: catalogCharacters })
|
||||
.from(teamMembers)
|
||||
.innerJoin(
|
||||
catalogCharacters,
|
||||
and(
|
||||
eq(catalogCharacters.version, teamMembers.catalogVersion),
|
||||
eq(catalogCharacters.key, teamMembers.characterKey),
|
||||
),
|
||||
)
|
||||
.where(eq(teamMembers.teamId, teamId))
|
||||
.orderBy(asc(teamMembers.position));
|
||||
|
||||
return {
|
||||
...row.team,
|
||||
guideName: row.guide.name,
|
||||
members: members.map(({ member, character }) => ({
|
||||
...member,
|
||||
character: catalogCharacterWithUrls(character),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export type PublicGuide = NonNullable<Awaited<ReturnType<typeof getPublicGuide>>>;
|
||||
|
||||
Reference in New Issue
Block a user