Skip to content

Commit

Permalink
feat: add payment transaction date
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed May 29, 2023
1 parent c35e915 commit 3683dae
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
1 change: 1 addition & 0 deletions d1/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
1 change: 1 addition & 0 deletions src/lib/server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface Payment {
email: string;
account: string;
time: string;
updated: string;
}

export interface Database {
Expand Down
11 changes: 8 additions & 3 deletions src/routes/api/payment/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions src/routes/dash/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const load: LayoutServerLoad = async ({ locals, platform }) => {
email: locals.token.email,
account: "",
time: "",
updated: "",
},
};
};
69 changes: 49 additions & 20 deletions src/routes/dash/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
method: "PUT",
body: JSON.stringify({
account: data.payment.account,
time: data.payment.time,
}),
});
Expand Down Expand Up @@ -238,21 +239,37 @@
</span>
{/if}
</label>
<label class="input-group">
<input
type="text"
placeholder="12345"
class="input-bordered input w-full"
bind:value={data.payment.account}
/>
<button
class="btn-primary btn"
on:click={update_payment}
disabled={uploading || data.payment.account.length !== 5}
>
儲存
</button>
<input
type="text"
placeholder="12345"
class="input-bordered input w-full"
bind:value={data.payment.account}
/>

<label class="label" for="">
<span class="label-text">匯款日期</span>
{#if has_payment}
<span class="label-text text-success">
<Icon icon="carbon:checkmark" class="mr-1 inline-block" />
已填寫
</span>
{/if}
</label>
<input
type="date"
class="input-bordered input w-full"
bind:value={data.payment.time}
/>

<button
class="btn-primary btn my-4 mt-2 self-end"
on:click={update_payment}
disabled={uploading ||
data.payment.account.length !== 5 ||
!data.payment.time}
>
儲存
</button>
</div>

<div class="form-control w-full">
Expand All @@ -277,7 +294,7 @@
<label class="input-group">
<input
type="file"
class="file-input-bordered file-input-primary file-input w-full rounded-l-lg"
class="file-input-bordered file-input-primary file-input w-full !rounded-l-lg"
accept="application/pdf"
on:change={(evt) => {
// @ts-expect-error svelte missing type
Expand All @@ -286,11 +303,23 @@
disabled={uploading}
/>
</label>
{#if upload_status}
<label class="label" for="">
<span class="label-text">{upload_status}</span>
</label>
{/if}
<label class="label" for="">
<span class="label-text">
{#if upload_status}
{upload_status}
{/if}
</span>
<span class="label-text">
<a
href="https://drive.google.com/file/d/1biU7xrUDut9MjMw4p44g3Ww48uC29xg3/view"
title="下載家長同意書"
target="_blank"
>
<Icon icon="carbon:download" class="mr-1 inline-block" />
下載家長同意書
</a>
</span>
</label>
</div>
{/if}

Expand Down

0 comments on commit 3683dae

Please sign in to comment.