From 909f17a03d116135117a5f68524320004e0fd99d Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Wed, 19 Jul 2023 18:11:44 +0300 Subject: [PATCH 1/8] Move fines and charities pages to a common group --- src/routes/{ => (tokenAuth)}/charities/+layout.server.ts | 0 src/routes/{ => (tokenAuth)}/charities/+page.svelte | 0 .../{ => (tokenAuth)}/charities/[program_code]/+page.svelte | 0 src/routes/{ => (tokenAuth)}/charities/[program_code]/+page.ts | 0 src/routes/{ => (tokenAuth)}/fines/+page.svelte | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/routes/{ => (tokenAuth)}/charities/+layout.server.ts (100%) rename src/routes/{ => (tokenAuth)}/charities/+page.svelte (100%) rename src/routes/{ => (tokenAuth)}/charities/[program_code]/+page.svelte (100%) rename src/routes/{ => (tokenAuth)}/charities/[program_code]/+page.ts (100%) rename src/routes/{ => (tokenAuth)}/fines/+page.svelte (100%) diff --git a/src/routes/charities/+layout.server.ts b/src/routes/(tokenAuth)/charities/+layout.server.ts similarity index 100% rename from src/routes/charities/+layout.server.ts rename to src/routes/(tokenAuth)/charities/+layout.server.ts diff --git a/src/routes/charities/+page.svelte b/src/routes/(tokenAuth)/charities/+page.svelte similarity index 100% rename from src/routes/charities/+page.svelte rename to src/routes/(tokenAuth)/charities/+page.svelte diff --git a/src/routes/charities/[program_code]/+page.svelte b/src/routes/(tokenAuth)/charities/[program_code]/+page.svelte similarity index 100% rename from src/routes/charities/[program_code]/+page.svelte rename to src/routes/(tokenAuth)/charities/[program_code]/+page.svelte diff --git a/src/routes/charities/[program_code]/+page.ts b/src/routes/(tokenAuth)/charities/[program_code]/+page.ts similarity index 100% rename from src/routes/charities/[program_code]/+page.ts rename to src/routes/(tokenAuth)/charities/[program_code]/+page.ts diff --git a/src/routes/fines/+page.svelte b/src/routes/(tokenAuth)/fines/+page.svelte similarity index 100% rename from src/routes/fines/+page.svelte rename to src/routes/(tokenAuth)/fines/+page.svelte From a11057306aeb25523b79bb487d65aca672519778 Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Wed, 19 Jul 2023 18:17:04 +0300 Subject: [PATCH 2/8] Factor out token check to the common layout --- src/routes/(tokenAuth)/+layout.server.ts | 14 ++++++++++++++ src/routes/(tokenAuth)/charities/+layout.server.ts | 10 ++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 src/routes/(tokenAuth)/+layout.server.ts diff --git a/src/routes/(tokenAuth)/+layout.server.ts b/src/routes/(tokenAuth)/+layout.server.ts new file mode 100644 index 0000000..d753845 --- /dev/null +++ b/src/routes/(tokenAuth)/+layout.server.ts @@ -0,0 +1,14 @@ +import { redirect } from '@sveltejs/kit'; +import type { LayoutServerLoad } from './$types'; + +export const load: LayoutServerLoad = async ({ cookies, url }) => { + const accessToken = url.searchParams.get('accessToken') ?? cookies.get('accessToken'); + if (accessToken == undefined) { + // No access token found. Go to the MTS login page, and redirect to the same page again + // SvelteKit seems to default it to HTTP during dev + const redirectUrl = url.href.replace('http:', 'https:'); + throw redirect(307, `/login?redirectUrl=${redirectUrl}`); + } + + return { accessToken }; +}; diff --git a/src/routes/(tokenAuth)/charities/+layout.server.ts b/src/routes/(tokenAuth)/charities/+layout.server.ts index f6fbd82..63c7732 100644 --- a/src/routes/(tokenAuth)/charities/+layout.server.ts +++ b/src/routes/(tokenAuth)/charities/+layout.server.ts @@ -3,14 +3,8 @@ import type { LayoutServerLoad } from './$types'; import { sampleCharities, type TCharity } from '$lib/api/charity'; import { API_BASE } from '$lib/api/mts'; -export const load: LayoutServerLoad = async ({ fetch, cookies, url }) => { - const accessToken = url.searchParams.get('accessToken') ?? cookies.get('accessToken'); - if (accessToken == undefined) { - // No access token found. Go to the MTS login page, and redirect to the same page again - // SvelteKit seems to default it to HTTP during dev - const redirectUrl = url.href.replace('http:', 'https:'); - throw redirect(307, `/login?redirectUrl=${redirectUrl}`); - } +export const load: LayoutServerLoad = async ({ fetch, cookies, url, parent }) => { + const { accessToken } = await parent(); const res = await fetch(API_BASE + '/rnip2/charges/charitycatalog', { headers: { Authorization: `Bearer ${accessToken}`, From a173d732c9a8a77a2dabbe6c9b789a1a154aeb30 Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Wed, 19 Jul 2023 18:51:36 +0300 Subject: [PATCH 3/8] Modify the document id value to match the API --- src/lib/api/document.ts | 8 +++++++- src/routes/docs/+page.svelte | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/api/document.ts b/src/lib/api/document.ts index 0b19167..1a91785 100644 --- a/src/lib/api/document.ts +++ b/src/lib/api/document.ts @@ -1,7 +1,13 @@ export enum DocType { - PASSPORT = 'Passport', + PASSPORT = '01', + STS = '24', } +export const docName: Record = { + [DocType.PASSPORT]: 'Passport', + [DocType.STS]: 'STS', +}; + export type Doc = { type: string; value: string; diff --git a/src/routes/docs/+page.svelte b/src/routes/docs/+page.svelte index 8391547..aa2e08a 100644 --- a/src/routes/docs/+page.svelte +++ b/src/routes/docs/+page.svelte @@ -1,10 +1,12 @@ @@ -41,7 +42,7 @@

Fines

Edit docs - {#each fines.chargeResponseList.map((fine) => fine) as { amountToPay, billDate, billFor }} + {#each fines.map((fine) => fine) as { amountToPay, billDate, billFor }}
{billFor}
- {Intl.NumberFormat('ru', { style: 'currency', currency: 'RUB' }).format(amountToPay)} + {Intl.NumberFormat('ru', { style: 'currency', currency: 'RUB' }).format(amountToPay / 100)}
{/each} From ea26448a359626ca228860f15395e21750b9644c Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Thu, 20 Jul 2023 12:25:36 +0300 Subject: [PATCH 8/8] Fix reading the access token in charities --- src/routes/(tokenAuth)/charities/+layout.server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(tokenAuth)/charities/+layout.server.ts b/src/routes/(tokenAuth)/charities/+layout.server.ts index 63c7732..935549d 100644 --- a/src/routes/(tokenAuth)/charities/+layout.server.ts +++ b/src/routes/(tokenAuth)/charities/+layout.server.ts @@ -3,8 +3,8 @@ import type { LayoutServerLoad } from './$types'; import { sampleCharities, type TCharity } from '$lib/api/charity'; import { API_BASE } from '$lib/api/mts'; -export const load: LayoutServerLoad = async ({ fetch, cookies, url, parent }) => { - const { accessToken } = await parent(); +export const load: LayoutServerLoad = async ({ fetch, cookies, url, locals }) => { + const { accessToken } = locals; const res = await fetch(API_BASE + '/rnip2/charges/charitycatalog', { headers: { Authorization: `Bearer ${accessToken}`,