Skip to content

Commit

Permalink
Merge pull request #49 from jaroslavhuss/jarda-core
Browse files Browse the repository at this point in the history
problem with password in console
  • Loading branch information
jaroslavhuss authored Jun 3, 2022
2 parents fbdc476 + 4f99b1a commit f88178e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 69 deletions.
87 changes: 34 additions & 53 deletions client/src/routes/iotDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import AppBar from "../molecules/AppBar";
import { Lang } from "../langauges/Dictionary"
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { GLOBAL_URL } from '../GLOBAL_URL'
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import { fetchAPI } from "../utils/FetchAPI";
import { FetchMethods } from "../interface/methods.enum";
import { setError } from "../store/reducers/errorReducer";

interface GateWayCreateInterface {
name: string;
Expand Down Expand Up @@ -33,6 +35,7 @@ interface ITemperature {

const StudentsDashboard = () => {
const navigate = useNavigate()
const dispatch = useDispatch()
const authState = useSelector((data: any) => { return data.auth })
const lang = useSelector((data: any) => { return data.language.language })
const [listOfGateways, setListOfGateways] = useState<GateWayCreateInterface[]>([])
Expand All @@ -45,17 +48,13 @@ const StudentsDashboard = () => {
const [isLoading, setIsLoading] = useState<boolean>(false)

const getAllGateways = async () => {

const token: string | null = localStorage.getItem("token");
const response: Response = await fetch(`${GLOBAL_URL}/gateway/all/`, {
method: "GET",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
}
})
const data: GateWayCreateInterface[] = await response.json();
try {
const data:GateWayCreateInterface[] = await fetchAPI("/gateway/all/", FetchMethods.GET)
setListOfGateways(data);
} catch (error:any) {
dispatch(setError(error.message))
}

}

useEffect(() => {
Expand All @@ -78,52 +77,34 @@ const StudentsDashboard = () => {
const getDataFromGW = async (id: string, start: Date, end: Date) => {
setIsLoading(true);
try {
const token: string | null = localStorage.getItem("token");

const responseHumidity: Response = await fetch(`${GLOBAL_URL}/gateway/data/humidity/`, {
method: "POST",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
id,
startDate,
endDate
})
const humidityData:IHumidity[] = await fetchAPI("/gateway/data/humidity/", FetchMethods.POST, {
id,
startDate,
endDate
})
const temperatureData:ITemperature[] = await fetchAPI("/gateway/data/temperature/", FetchMethods.POST, {
id,
startDate,
endDate
})

humidityData.forEach((h) => {
const niceDate = new Date(h.date).toLocaleDateString() + " " + new Date(h.date).toLocaleTimeString();
h.date = niceDate;
h.humidity = parseFloat(h.humidity.toFixed(1));
})
const responseTemperature: Response = await fetch(`${GLOBAL_URL}/gateway/data/temperature/`, {
method: "POST",
headers: {
"Content-type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
id,
startDate,
endDate
})

temperatureData.forEach((h: ITemperature) => {
const niceDate = new Date(h.date).toLocaleDateString() + " " + new Date(h.date).toLocaleTimeString();
h.date = niceDate;
h.temperature = parseFloat(h.temperature.toFixed(1));
})

const humidityData: IHumidity[] = await responseHumidity.json();
const temperatureData: ITemperature[] = await responseTemperature.json();
setHumidity(humidityData)
setTemperature(temperatureData);

// humidityData.forEach((h) => {
// const niceDate = new Date(h.date).toLocaleDateString() + " " + new Date(h.date).toLocaleTimeString();
// h.date = niceDate;
// h.humidity = parseFloat(h.humidity.toFixed(1));
// })

// temperatureData.forEach((h: ITemperature) => {
// const niceDate = new Date(h.date).toLocaleDateString() + " " + new Date(h.date).toLocaleTimeString();
// h.date = niceDate;
// h.temperature = parseFloat(h.temperature.toFixed(1));
// })

setIsLoading(false);
} catch (error) {
} catch (error:any) {
dispatch(setError(error.message))
setIsLoading(false)
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/store/reducers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const authSlice = createSlice({
state.subjects = action.payload.subjects;
},
authUserFailed: (state) => {
localStorage.removeItem("token");
// localStorage.removeItem("token");
state.isAuthenticated = false;
state.token = null;
state.loading = true;
Expand Down
2 changes: 2 additions & 0 deletions client/src/utils/setAuthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { authUserFailed, authUserSuccess } from "../store/reducers/auth";
import { fetchAPI } from "./FetchAPI";
import { FetchMethods } from "../interface/methods.enum";
import { UserInterface } from "../interface/UserInterface";

export const GlobalWatcher = async () => {
const dispatch = useDispatch();
try {
Expand All @@ -12,6 +13,7 @@ export const GlobalWatcher = async () => {

if(!data.isUserApproved)throw new Error("User is not approved yet!")
dispatch(authUserSuccess({ data:data.tokens.access_token, user: data.user }));

} catch (error: any) {
dispatch(authUserFailed());
}
Expand Down
8 changes: 2 additions & 6 deletions server/dist/gateway/gateway.controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/// <reference types="mongoose/types/pipelinestage" />
/// <reference types="mongoose/types/error" />
/// <reference types="mongoose/types/connection" />
/// <reference types="mongoose" />
import { BadRequestException } from '@nestjs/common';
import { createGateWayDto, GatewaySaveHumidityDto, GatewaySaveTemperatureDto } from './dto';
import { GatewayService } from './gateway.service';
Expand All @@ -14,9 +10,9 @@ export declare class GatewayController {
saveTemperature(body: GatewaySaveTemperatureDto[], gateway: any): Promise<import("@nestjs/common").InternalServerErrorException | (import("../schemas").Temperature & import("mongoose").Document<any, any, any> & {
_id: any;
})[]>;
createGateWay(dto: createGateWayDto, user: any): Promise<BadRequestException | (import("../schemas").Gateway & import("mongoose").Document<any, any, any> & {
createGateWay(dto: createGateWayDto, user: any): Promise<(import("../schemas").Gateway & import("mongoose").Document<any, any, any> & {
_id: any;
})>;
}) | BadRequestException>;
getAllGateways(): Promise<(import("../schemas").Gateway & import("mongoose").Document<any, any, any> & {
_id: any;
})[]>;
Expand Down
7 changes: 2 additions & 5 deletions server/dist/gateway/gateway.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/// <reference types="mongoose/types/pipelinestage" />
/// <reference types="mongoose/types/error" />
/// <reference types="mongoose/types/connection" />
import { BadRequestException, InternalServerErrorException } from '@nestjs/common';
import { Gateway, GatewayDocument, Humidity, HumidityDocument, Temperature, TemperatureDocument } from 'src/schemas';
import { Model } from 'mongoose';
Expand All @@ -10,9 +7,9 @@ export declare class GatewayService {
private humidityModel;
private temperatureModel;
constructor(gatewayModel: Model<GatewayDocument>, humidityModel: Model<HumidityDocument>, temperatureModel: Model<TemperatureDocument>);
createGateway(dto: createGateWayDto): Promise<BadRequestException | (Gateway & import("mongoose").Document<any, any, any> & {
createGateway(dto: createGateWayDto): Promise<(Gateway & import("mongoose").Document<any, any, any> & {
_id: any;
})>;
}) | BadRequestException>;
getAllGateways(): Promise<(Gateway & import("mongoose").Document<any, any, any> & {
_id: any;
})[]>;
Expand Down
2 changes: 1 addition & 1 deletion server/dist/gateway/gateway.service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f88178e

Please sign in to comment.