diff --git a/d1/schema.sql b/d1/schema.sql index e44e58d..be946d1 100644 --- a/d1/schema.sql +++ b/d1/schema.sql @@ -65,4 +65,5 @@ CREATE TABLE IF NOT EXISTS Payment ( email TEXT NOT NULL PRIMARY KEY, account TEXT NOT NULL, time TEXT NOT NULL, + updated TEXT NOT NULL ); diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index 1fb13d6..8f3fd78 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -60,6 +60,7 @@ export interface Payment { email: string; account: string; time: string; + updated: string; } export interface Database { diff --git a/src/routes/api/payment/+server.ts b/src/routes/api/payment/+server.ts index 00ef955..6058045 100644 --- a/src/routes/api/payment/+server.ts +++ b/src/routes/api/payment/+server.ts @@ -18,13 +18,17 @@ export const PUT: RequestHandler = async ({ locals, request, platform }) => { } const body = await request.json(); - const { account } = body as { account: string }; + const { account, time } = body as { account: string; time: string }; if (typeof account !== "string" || account.length !== 5) { throw error(400, "Bad Request"); } - const time = new Date().toISOString(); + if (typeof time !== "string" || time.length > 100) { + throw error(400, "Bad Request"); + } + + const updated = new Date().toISOString(); const db = new D1(platform); @@ -34,8 +38,9 @@ export const PUT: RequestHandler = async ({ locals, request, platform }) => { email: locals.token.email, account, time, + updated, }) - .onConflict((oc) => oc.columns(["email"]).doUpdateSet({ account, time })) + .onConflict((oc) => oc.columns(["email"]).doUpdateSet({ account, time, updated })) .execute(); return json({ ok: true }); diff --git a/src/routes/dash/+layout.server.ts b/src/routes/dash/+layout.server.ts index 29c8ed1..7960441 100644 --- a/src/routes/dash/+layout.server.ts +++ b/src/routes/dash/+layout.server.ts @@ -28,6 +28,7 @@ export const load: LayoutServerLoad = async ({ locals, platform }) => { email: locals.token.email, account: "", time: "", + updated: "", }, }; }; diff --git a/src/routes/dash/+page.svelte b/src/routes/dash/+page.svelte index 46acda4..e8777f3 100644 --- a/src/routes/dash/+page.svelte +++ b/src/routes/dash/+page.svelte @@ -149,6 +149,7 @@ method: "PUT", body: JSON.stringify({ account: data.payment.account, + time: data.payment.time, }), }); @@ -238,21 +239,37 @@ {/if} -