feat : update
This commit is contained in:
@@ -116,7 +116,7 @@ export async function saveWeapons(guideId: string, input: unknown) {
|
||||
await tx.update(guideSections).set({ note: data.note }).where(and(eq(guideSections.guideId, guideId), eq(guideSections.slug, "weapon")));
|
||||
await tx.delete(weaponConditions).where(eq(weaponConditions.guideId, guideId));
|
||||
for (const [sortOrder, group] of data.groups.entries()) {
|
||||
const [created] = await tx.insert(weaponConditions).values({ guideId, note: group.note, sortOrder }).returning();
|
||||
const [created] = await tx.insert(weaponConditions).values({ guideId, name: group.name, note: group.note, sortOrder }).returning();
|
||||
if (group.rows.length) await tx.insert(weaponRecommendations).values(group.rows.map((row, rowOrder) => ({ ...row, refinement: row.refinement, overallPercent: row.overallPercent?.toString() ?? null, personalPercent: row.personalPercent?.toString() ?? null, conditionId: created.id, sortOrder: rowOrder })));
|
||||
}
|
||||
return updated;
|
||||
|
||||
@@ -66,6 +66,16 @@ describe("structured guide validation", () => {
|
||||
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, note: null, groups: [{ note: null, rows: [{ ...row, note: "x".repeat(2_001) }] }] }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("normalizes optional weapon condition names", () => {
|
||||
const row = { weaponKey: "1", refinement: 1, overallPercent: 100, personalPercent: null, note: null };
|
||||
const named = weaponSectionSchema.parse({ expectedVersion: 1, note: null, groups: [{ name: " Main DPS ", note: null, rows: [row] }] });
|
||||
const unnamed = weaponSectionSchema.parse({ expectedVersion: 1, note: null, groups: [{ name: "", note: null, rows: [row] }] });
|
||||
|
||||
expect(named.groups[0].name).toBe("Main DPS");
|
||||
expect(unnamed.groups[0].name).toBeNull();
|
||||
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, note: null, groups: [{ name: "x".repeat(121), note: null, rows: [row] }] }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("limits weapon and constellation header notes", () => {
|
||||
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, note: "Header note", groups: [] }).success).toBe(true);
|
||||
expect(weaponSectionSchema.safeParse({ expectedVersion: 1, note: "x".repeat(2_001), groups: [] }).success).toBe(false);
|
||||
|
||||
@@ -52,6 +52,7 @@ export const weaponSectionSchema = z.strictObject({
|
||||
expectedVersion: z.number().int().positive(),
|
||||
note: z.string().trim().max(2_000).nullable(),
|
||||
groups: z.array(z.strictObject({
|
||||
name: z.string().trim().max(120).nullable().optional().transform((value) => value || null),
|
||||
note: z.string().trim().max(2_000).nullable(),
|
||||
rows: z.array(z.strictObject({
|
||||
weaponKey: catalogKey,
|
||||
|
||||
Reference in New Issue
Block a user