fix: react-doctor label-has-associated-control 9→0, async-await-in-loop 3→0 (Promise.allSettled), role-supports-aria-props 3→0 (already done in prior batch)

This commit is contained in:
Nora
2026-06-26 06:01:06 -06:00
parent ed5afe4b21
commit d6d6a366e3
7 changed files with 220 additions and 139 deletions
+37 -10
View File
@@ -40,29 +40,56 @@ await getSession(); const adminUser = await getAdminUser();
let created = 0;
const errors: { product: string; error: string }[] = [];
const validProducts: Array<{ name: string; description: string; price: number; type: string; active: boolean; image_url?: string }> = [];
const skipped: { product: { name: string; description: string; price: number; type: string; active: boolean; image_url?: string }; error: string }[] = [];
for (const p of productsToImport) {
const priceCents = Math.round(Number(p.price) * 100);
if (!Number.isFinite(priceCents) || priceCents < 0) {
errors.push({ product: p.name, error: "Invalid price" });
continue;
skipped.push({ product: p, error: "Invalid price" });
} else {
validProducts.push(p);
}
try {
await withBrand(brandId, (db) =>
}
const settled = await Promise.allSettled(
validProducts.map((p) =>
withBrand(brandId, (db) =>
db.insert(products).values({
brandId: brandId,
name: p.name,
description: p.description ?? null,
priceCents,
priceCents: Math.round(Number(p.price) * 100),
active: p.active,
})
);
created++;
} catch (err) {
}),
).then(
() => p,
(err) => ({ p, err }),
),
),
);
for (const entry of settled) {
if (entry.status === "rejected") {
const err = (entry as PromiseRejectedResult).reason;
errors.push({
product: p.name,
product: "<unknown>",
error: err instanceof Error ? err.message : String(err),
});
continue;
}
const value = entry.value;
if ("err" in value) {
errors.push({
product: value.p.name,
error: value.err instanceof Error ? value.err.message : String(value.err),
});
} else {
created++;
}
}
for (const s of skipped) {
errors.push({ product: s.product.name, error: s.error });
}
return { success: true, created, updated: 0, errors };