fix(waitlist): use slice instead of split to avoid TS strict null check errors
TypeScript's split()[0] is typed as string | undefined in strict mode. Using slice(0, 10) is cleaner and avoids the type issue. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
committed by
Flea Flicker
parent
1f56ba98f7
commit
84ab5a00f5
@@ -17,7 +17,7 @@ import type { AppEnv } from "../middleware/rbac.js";
|
|||||||
export const waitlistRouter = new Hono<AppEnv>();
|
export const waitlistRouter = new Hono<AppEnv>();
|
||||||
|
|
||||||
async function markExpiredEntries(db: ReturnType<typeof getDb>, rows: typeof waitlistEntries.$inferSelect[]) {
|
async function markExpiredEntries(db: ReturnType<typeof getDb>, rows: typeof waitlistEntries.$inferSelect[]) {
|
||||||
const today = new Date().toISOString().split("T")[0];
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
const expiredIds = rows
|
const expiredIds = rows
|
||||||
.filter((r) => r.status === "active" && r.preferredDate < today)
|
.filter((r) => r.status === "active" && r.preferredDate < today)
|
||||||
.map((r) => r.id);
|
.map((r) => r.id);
|
||||||
@@ -67,7 +67,7 @@ waitlistRouter.get("/", async (c) => {
|
|||||||
|
|
||||||
await markExpiredEntries(db, rows);
|
await markExpiredEntries(db, rows);
|
||||||
|
|
||||||
const today = new Date().toISOString().split("T")[0];
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
|
||||||
const enriched = await Promise.all(
|
const enriched = await Promise.all(
|
||||||
rows.map(async (entry) => {
|
rows.map(async (entry) => {
|
||||||
@@ -111,7 +111,7 @@ waitlistRouter.get("/:id", async (c) => {
|
|||||||
if (!row) return c.json({ error: "Not found" }, 404);
|
if (!row) return c.json({ error: "Not found" }, 404);
|
||||||
|
|
||||||
await markExpiredEntries(db, [row]);
|
await markExpiredEntries(db, [row]);
|
||||||
const today = new Date().toISOString().split("T")[0];
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
const isExpired = row.status === "active" && row.preferredDate < today;
|
const isExpired = row.status === "active" && row.preferredDate < today;
|
||||||
return c.json({
|
return c.json({
|
||||||
...row,
|
...row,
|
||||||
|
|||||||
Reference in New Issue
Block a user