Skip to content

Commit

Permalink
add topup timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Oct 25, 2024
1 parent 841cb5b commit b1e2fde
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ router.post("/addMoney", async (req, res) => {
topupRow.admin_uid = req.user!.uid
topupRow.admin_name = req.user!.name
topupRow.amount = amountToDP.toFixed(2)
topupRow.completed_timestamp = new Date()

await sql`
UPDATE Users
Expand Down
3 changes: 2 additions & 1 deletion backend/src/api/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ router.post("/createToken", async (req, res) => {
admin_uid: null,
admin_name: null,
amount: null,
completed_timestamp: null,
}
await sql`INSERT INTO Topup ${sql(topup)}`
res.json({ topup_id: topupId })
Expand Down Expand Up @@ -175,7 +176,7 @@ router.get("/getTransactions", async (req, res) => {

router.get("/getTopups", async (req, res) => {
const topups = await sql<{ lucky_draw_code: string; amount: string }[]>`
SELECT Topup.amount, Topup.lucky_draw_code FROM Topup WHERE student_uid = ${
SELECT Topup.amount, Topup.lucky_draw_code, Topup.completed_timestamp FROM Topup WHERE student_uid = ${
req.user!.uid
} AND admin_uid IS NOT NULL
`
Expand Down
1 change: 1 addition & 0 deletions backend/src/types/topup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type TopupTable = {
admin_name: string | null // VARCHAR(255)
amount: string | null // DECIMAL(10, 2)
lucky_draw_code: string // CHAR(13)
completed_timestamp: Date | null // TIMESTAMP
}

export interface TopupTableInsert extends Omit<TopupTable, "lucky_draw_code"> {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ export async function getTransactionHistoryBooth(): Promise<
export async function getTopupHistory(): Promise<TopupHistoryDetails[] | null> {
try {
const resp = await fetcher.get("/student/getTopups");
return resp.data as TopupHistoryDetails[];
return resp.data.map((obj: Record<string, string>) => ({
...obj,
completed_timestamp: new Date(obj.completed_timestamp),
})) as TopupHistoryDetails[];
} catch (error) {
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/routes/student_topups_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export default function StudentTopupHistoryPage() {
<Typography variant="body1">
Code: {topup.lucky_draw_code}
</Typography>
<Typography variant="body1">
{topup.completed_timestamp.toLocaleString()}
</Typography>
</CardContent>
</Card>
))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/topup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type TopupDetails = {
export type TopupHistoryDetails = {
lucky_draw_code: string;
amount: string;
completed_timestamp: Date;
};
1 change: 1 addition & 0 deletions sql/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ CREATE TABLE Topup(
admin_uid CHAR(36),
admin_name VARCHAR(255),
amount DECIMAL(10, 2),
completed_timestamp TIMESTAMP,
lucky_draw_code CHAR(13) DEFAULT 'EXCITE-' || LPAD(NEXTVAL('LuckyDrawCodeSeq')::TEXT, 6, '0') NOT NULL
);

0 comments on commit b1e2fde

Please sign in to comment.