Skip to content

Commit d3d9428

Browse files
committed
fix(api): use Date objects instead of Date.now() for timestamp_ms columns
Drizzle ORM with mode: "timestamp_ms" expects Date objects, not raw numbers. Passing Date.now() caused .getTime() to fail on a number, resulting in 500 errors on API key generation, ratings, reviews, favorites, and usage reports.
1 parent 6ece094 commit d3d9428

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

apps/web/app/routes/api.skill-favorite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function action({ request, params, context }: ActionFunctionArgs) {
6262
await db.insert(favorites).values({
6363
user_id: session.user.id,
6464
skill_id: skill.id,
65-
created_at: Date.now(),
65+
created_at: new Date(),
6666
});
6767
favorited = true;
6868
}

apps/web/app/routes/api.skill-rate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function action({ request, params, context }: ActionFunctionArgs) {
4545

4646
// Upsert rating (update if exists, insert if not)
4747
const ratingId = `${session.user.id}-${skill.id}`;
48-
const now = Date.now();
48+
const now = new Date();
4949

5050
await db
5151
.insert(ratings)

apps/web/app/routes/api.skill-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function action({ request, params, context }: ActionFunctionArgs) {
8787

8888
// Create review
8989
const reviewId = `review-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
90-
const now = Date.now();
90+
const now = new Date();
9191

9292
const [review] = await db
9393
.insert(reviews)

apps/web/app/routes/api.usage-report.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function action({ request, context }: ActionFunctionArgs) {
4747
// Update last used timestamp
4848
await db
4949
.update(apiKeys)
50-
.set({ last_used_at: Date.now() })
50+
.set({ last_used_at: new Date() })
5151
.where(eq(apiKeys.id, foundKey.id));
5252

5353
// Parse and validate body
@@ -89,7 +89,7 @@ export async function action({ request, context }: ActionFunctionArgs) {
8989
model: model || null,
9090
outcome,
9191
duration_ms: duration_ms || null,
92-
created_at: Date.now(),
92+
created_at: new Date(),
9393
});
9494

9595
// Recompute leaderboard scores

apps/web/app/routes/api.user-api-keys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function action({ request, context }: ActionFunctionArgs) {
7474

7575
const { plaintext, hash, prefix } = await generateApiKey();
7676
const keyId = `key-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
77-
const now = Date.now();
77+
const now = new Date();
7878

7979
await db.insert(apiKeys).values({
8080
id: keyId,
@@ -105,7 +105,7 @@ export async function action({ request, context }: ActionFunctionArgs) {
105105
// Verify ownership and revoke
106106
const result = await db
107107
.update(apiKeys)
108-
.set({ revoked_at: Date.now() })
108+
.set({ revoked_at: new Date() })
109109
.where(
110110
and(
111111
eq(apiKeys.id, keyId),

apps/web/app/routes/settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default function Settings() {
101101
);
102102
};
103103

104-
const formatDate = (timestamp: number) => {
104+
const formatDate = (timestamp: number | string | Date) => {
105105
return new Intl.DateTimeFormat("en-US", {
106106
year: "numeric",
107107
month: "short",

0 commit comments

Comments
 (0)