From 15a42e53609706564a28c9de9bb5ac43f9ee0760 Mon Sep 17 00:00:00 2001 From: JavaRip Date: Thu, 19 Sep 2024 19:51:29 +0100 Subject: [PATCH] fix map --- app/client/src/pages/Map/Map.tsx | 10 +++++++--- app/client/src/pages/Map/markers.tsx | 4 ++++ app/client/src/utils/AccessToken.ts | 6 +++++- app/client/vite.config.ts | 2 +- .../iArsenic API/environments/localhost.bru | 2 +- app/server/iArsenic API/get wells.bru | 15 +++++++++++++++ app/server/package.json | 2 +- app/server/src/server/routes/v1/index.ts | 2 ++ app/server/src/server/routes/v1/well.ts | 2 +- 9 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 app/server/iArsenic API/get wells.bru diff --git a/app/client/src/pages/Map/Map.tsx b/app/client/src/pages/Map/Map.tsx index 6b4aa56f..004e14af 100644 --- a/app/client/src/pages/Map/Map.tsx +++ b/app/client/src/pages/Map/Map.tsx @@ -39,14 +39,15 @@ export default function Map() { throw new Error(`Failed to fetch well data:, ${res}`); } - const wells = await res.json(); - setWells(wells.data); + const data = await res.json(); + setWells(data.wells); } async function getRegionTranslations() { const translations = await RegionTranslationsFetcher(); setRegionTranslations(translations); } + useEffect(() => { async function fetchToken() { const token = await AccessToken.get(); @@ -58,9 +59,12 @@ export default function Map() { fetchToken(); getRegionTranslations(); getInteractiveMap(); - getPredictionPinData(); }, []); + useEffect(() => { + getPredictionPinData(); + }, [token]); + if (!interactiveMap || !wells || !regionTranslations) return ( diff --git a/app/client/src/pages/Map/markers.tsx b/app/client/src/pages/Map/markers.tsx index 7ac7f1b5..41c2359a 100644 --- a/app/client/src/pages/Map/markers.tsx +++ b/app/client/src/pages/Map/markers.tsx @@ -63,6 +63,10 @@ export default function Markers({ wells, regionTranslations }: props): JSX.Eleme } } + console.log('================================'); + console.log(wells); + console.log(wells.filter); + return ( <> {wells.filter( diff --git a/app/client/src/utils/AccessToken.ts b/app/client/src/utils/AccessToken.ts index 43e6a268..66bf643d 100644 --- a/app/client/src/utils/AccessToken.ts +++ b/app/client/src/utils/AccessToken.ts @@ -11,7 +11,11 @@ export default class AccessToken { if (!accessToken) return null; const parsedAccessToken = JSON.parse(accessToken); - const tokenValidationRes = TokenSchema.safeParse(parsedAccessToken); + const tokenValidationRes = TokenSchema.safeParse({ + ...parsedAccessToken, + createdAt: parsedAccessToken.createdAt = new Date(parsedAccessToken.createdAt), + expiresAt: parsedAccessToken.expiresAt = new Date(parsedAccessToken.expiresAt), + }); if (!tokenValidationRes.success) { console.error('Failed to validate access token:', tokenValidationRes.error); diff --git a/app/client/vite.config.ts b/app/client/vite.config.ts index 19d92d8d..d8efa428 100644 --- a/app/client/vite.config.ts +++ b/app/client/vite.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ }, resolve: { alias: { - 'shared': './node_modules/shared/dist/index.js', + 'shared': './node_modules/shared/src/index.ts', } } }); diff --git a/app/server/iArsenic API/environments/localhost.bru b/app/server/iArsenic API/environments/localhost.bru index a68a99cb..f6d1c29f 100644 --- a/app/server/iArsenic API/environments/localhost.bru +++ b/app/server/iArsenic API/environments/localhost.bru @@ -2,7 +2,7 @@ vars { base_url: http://127.0.0.1:5001/iarsenic-staging/us-central1/default } vars:secret [ - test_password, access_token, + test_password, well_id ] diff --git a/app/server/iArsenic API/get wells.bru b/app/server/iArsenic API/get wells.bru new file mode 100644 index 00000000..0fc92cbf --- /dev/null +++ b/app/server/iArsenic API/get wells.bru @@ -0,0 +1,15 @@ +meta { + name: get wells + type: http + seq: 14 +} + +get { + url: {{base_url}}/api/v1/well/ + body: none + auth: none +} + +headers { + authorization: Bearer {{access_token}} +} diff --git a/app/server/package.json b/app/server/package.json index 90da5fee..5bc44ac0 100644 --- a/app/server/package.json +++ b/app/server/package.json @@ -5,7 +5,7 @@ "main": "index.ts", "scripts": { "build": "rm -rf dist && tsc && ../client/ run build && cp -r ../client/static/ dist/static/", - "build:firebase": "npm --prefix ../shared run build && npm --prefix ../client/ run build && rm -rf dist && tsc && rm -rf ../../firebase-functions/dist && cp -r dist/* ../../firebase-functions" + "build:firebase": "npm --prefix ../shared run build && npm --prefix ../client run build && rm -rf dist && tsc && rm -rf ../../firebase-functions/dist && cp -r dist/* ../../firebase-functions && cp -r ../client/static ../../firebase-functions" }, "keywords": [], "author": "", diff --git a/app/server/src/server/routes/v1/index.ts b/app/server/src/server/routes/v1/index.ts index e3825916..86e9f8dd 100644 --- a/app/server/src/server/routes/v1/index.ts +++ b/app/server/src/server/routes/v1/index.ts @@ -3,6 +3,7 @@ import healthcheck from './healthcheck' import Router from '@koa/router' import self from './self' import user from './user' +import well from './well' const routes = new Router({ prefix: '/api/v1' }) @@ -13,5 +14,6 @@ routes.use(errorHandler) routes.use(healthcheck.routes()) routes.use(user.routes()) routes.use(self.routes()) +routes.use(well.routes()) export default routes \ No newline at end of file diff --git a/app/server/src/server/routes/v1/well.ts b/app/server/src/server/routes/v1/well.ts index 78733dec..46e44a91 100644 --- a/app/server/src/server/routes/v1/well.ts +++ b/app/server/src/server/routes/v1/well.ts @@ -1,6 +1,6 @@ import Router from '@koa/router' import { adminOnly } from '../../middleware' -import { WellController } from 'src/server/controllers'; +import { WellController } from '../../controllers'; const well = new Router({ prefix: '/well' })