From a280286bae70924373cfab08d5020824810ea9df Mon Sep 17 00:00:00 2001 From: kiwijos Date: Sun, 7 Jan 2024 15:35:19 +0100 Subject: [PATCH] Add types --- src/routes/(main)/me/account/prepay/+page.server.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/routes/(main)/me/account/prepay/+page.server.ts b/src/routes/(main)/me/account/prepay/+page.server.ts index 3d7495a..6a5fc79 100644 --- a/src/routes/(main)/me/account/prepay/+page.server.ts +++ b/src/routes/(main)/me/account/prepay/+page.server.ts @@ -5,21 +5,17 @@ import { PUBLIC_REST_API_URL } from '$env/static/public'; const prepay: Action = async ({ request, fetch }) => { const data = await request.formData(); - let amount = data.get('amount'); + const amount = data.get('amount'); // Check amount should be a value larger than 0 if (typeof amount !== 'string' || !amount) { return fail(400, { errors: [{ field: 'amount', message: 'Ange ett belopp' }] }); // return early to avoid checks that are dependent on the amount being a number } - try { - amount = amount.replace(',', '.'); - amount = parseFloat(amount); - } catch (e) { - return fail(400, { errors: [{ field: 'amount', message: 'Beloppet är inte giltigt' }] }); - } + const amountString: string = amount.replace(',', '.'); + const amountNumeric: number = parseFloat(amountString); - if (amount < 0) { + if (amountNumeric < 0) { return fail(400, { errors: [{ field: 'amount', message: 'Beloppet måste vara större än 0' }] }); }