Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaRip committed Sep 19, 2024
1 parent 5439b67 commit d7c3f4f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 46 deletions.
5 changes: 3 additions & 2 deletions app/client/src/components/HeaderBar/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import MenuIcon from '@mui/icons-material/Menu';
import { useEffect, useState } from 'react';
import NavMenu from './NavMenu';
import AccessToken from '../../utils/AccessToken';
import { IAccessToken, User } from '../../types';
import { Token, User } from 'shared';
import Config from '../../config';

export default function HeaderBar(): JSX.Element {
const [open, setOpen] = useState(false);
const [token, setToken] = useState<IAccessToken>();
const [token, setToken] = useState<Token>();
const [user, setUser] = useState<User>();

useEffect(() => {
Expand All @@ -28,6 +28,7 @@ export default function HeaderBar(): JSX.Element {
useEffect(() => {
async function fetchUser() {
if (!token) return;
if (token.type !== 'access') return;

const res = await fetch(`${Config.basePath}/api/v1/self/user`, {
headers: {
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/pages/Briefing/Briefing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Briefing(): JSX.Element {

const headers: HeadersInit = {};

if (token) {
if (token && token.type === 'access') {
headers.authorization = `Bearer ${token.id}`;
}

Expand Down
7 changes: 0 additions & 7 deletions app/client/src/pages/Depth/Depth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Box, Button, Card, Slider, Switch, TextField, Typography } from "@mui/m
import config from "../../config";
import { navigate } from "wouter/use-browser-location";
import { useEffect, useState } from "react";
import PredictorsStorage from "../../utils/PredictorsStorage";
import { Token } from "shared";
import { useRoute } from "wouter";
import AccessToken from "../../utils/AccessToken";
Expand Down Expand Up @@ -118,12 +117,6 @@ export default function Depth(): JSX.Element {
sx={{ width: '90%', height: '4rem' }}
variant='contained'
onClick={async () => {
PredictorsStorage.set({
depth: {
unit,
value: depth
}
});
const headers: HeadersInit = {};
if (token && token.type === 'access') {
headers['authorization'] = `Bearer ${token.id}`;
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/pages/Map/markers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function Markers({ wells, regionTranslations }: props): JSX.Eleme
return (
<>
{wells.filter(
s => s.geolocation !== 'N/A' &&
s => s.geolocation != null &&
s.prediction != null &&
s.regionKey != null &&
s.staining != null &&
Expand Down Expand Up @@ -161,7 +161,7 @@ export default function Markers({ wells, regionTranslations }: props): JSX.Eleme
</Typography>

{
(p.utensilStaining !== 'N/A') &&
(p.utensilStaining != null) &&
<>
<Typography className='english' variant='body1'>
Utensil Staining: {p.utensilStaining}
Expand Down
9 changes: 7 additions & 2 deletions app/client/src/pages/MyWells/MyWells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export default function MyWells(): JSX.Element {
async function fetchUserWells() {
const token = await AccessToken.get();

if (!token) {
if (!token || token.type !== 'access') {
navigate(`${Config.basePath}/login`);
throw new Error('token not valid');
}

if (token.type !== 'access') {
console.error('Token is not access token');
return;
}

Expand Down Expand Up @@ -46,7 +51,7 @@ export default function MyWells(): JSX.Element {
async function addWell(): Promise<Well> {
const token = await AccessToken.get();

if (!token) {
if (!token || token.type !== 'access') {
navigate(`${Config.basePath}/login`);
throw new Error('token not valid');
}
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/pages/Result/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function Result(): JSX.Element {
const token = await AccessToken.get();

const headers: HeadersInit = {};
if (token) {
if (token && token.type === 'access') {
headers['authorization'] = `Bearer ${token.id}`;
}

Expand Down
5 changes: 5 additions & 0 deletions app/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ export default defineConfig({
outDir: 'static',
minify: true,
},
resolve: {
alias: {
'shared': './node_modules/shared/dist/index.js',
}
}
});
2 changes: 1 addition & 1 deletion app/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../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"
},
"keywords": [],
"author": "",
Expand Down
5 changes: 3 additions & 2 deletions app/server/src/server/services/well/produceEstimate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MessageCode, ModelData } from '../../types'
import { ModelData } from '../../types'
import { ModelMessageCode } from 'shared'
import { Well } from 'shared'
import path from 'path'
import fs from 'fs'

export default function produceEstimate(well: Well): MessageCode {
export default function produceEstimate(well: Well): ModelMessageCode {
if (!well.regionKey) throw new Error('region key not found in well data');

const div = well.regionKey.division;
Expand Down
38 changes: 11 additions & 27 deletions app/server/src/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { RegionKey } from 'shared/src/models/well.model';
import { ModelMessageCode } from 'shared';

export type Predictors = {
id: string,
regionKey: RegionKey
depth: number, // meters
flooding: boolean,
wellStaining: WellStaining,
utensilStaining?: UtensilStaining,
geolocation?: [number, number],
regionGeovalidated: boolean,
}

// staining types
export type WellStaining = 'Black' | 'Red' | 'Not sure';
export type UtensilStaining = 'Red' | 'Black' | 'No colour change to slightly blackish' | 'N/A' | undefined;

// prediction data
export type MessageCode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
// // prediction data
export type ModelData = {
[key: string]: {
districts: {
Expand All @@ -28,29 +12,29 @@ export type ModelData = {
mouzas: {
[key: string]: {
s15: {
m: MessageCode,
m: ModelMessageCode,
l?: number,
u?: number,
m2?: MessageCode,
m7?: MessageCode,
m9?: MessageCode,
m2?: ModelMessageCode,
m7?: ModelMessageCode,
m9?: ModelMessageCode,
},
s45: {
m: MessageCode,
m: ModelMessageCode,
},
s65: {
m: MessageCode,
m: ModelMessageCode,
},
s90: {
m: MessageCode,
m: ModelMessageCode,
},
s150: {
m: MessageCode,
m: ModelMessageCode,
l: number,
u: number,
},
sD: {
m: MessageCode,
m: ModelMessageCode,
l: number,
u: number,
}
Expand Down
6 changes: 6 additions & 0 deletions app/shared/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export { default as validateModel } from './validateModel';
export { WellSchema } from './well.model';
export type { Well } from './well.model';

export { CompleteWellSchema } from './well.model';
export type { CompleteWell } from './well.model';

export { PredictionSchema } from './well.model';
export type { Prediction } from './well.model';

Expand All @@ -27,6 +30,9 @@ export type { RegionKey } from './well.model';
export { RiskAssesmentSchema } from './well.model';
export type { RiskAssesment } from './well.model';

export { ModelMessageCodeSchema } from './well.model';
export type { ModelMessageCode } from './well.model';

export { StainingSchema } from './well.model';
export type { Staining } from './well.model';

Expand Down
15 changes: 14 additions & 1 deletion app/shared/src/models/well.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,25 @@ export const WellSchema = z.object({
flooding: z.boolean().optional(),
staining: StainingSchema.optional(),
utensilStaining: UtensilStainingSchema.optional(),
geolocation: z.union([z.tuple([z.number(), z.number()]), z.literal('N/A')]).optional(),
geolocation: z.tuple([z.number(), z.number()]).optional(),
prediction: PredictionSchema.optional(),
});

export type Well = z.infer<typeof WellSchema>;

export const CompleteWellSchema = WellSchema.extend({
drinkingWaterSource: z.boolean(),
regionKey: RegionKeySchema,
depth: z.number(),
flooding: z.boolean(),
staining: StainingSchema,
utensilStaining: UtensilStainingSchema.optional(),
geolocation: z.union([z.number(), z.number()]).optional(),
prediction: PredictionSchema,
});

export type CompleteWell = z.infer<typeof CompleteWellSchema>;

export const PredictorsSchema = z.object({
regionKey: RegionKeySchema,
depth: z.number(),
Expand Down

0 comments on commit d7c3f4f

Please sign in to comment.