Skip to content

Commit

Permalink
(#225) adiciona soma hidratacao
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueAmorim20 committed Dec 12, 2023
1 parent 0add917 commit 01941df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/app/private/pages/visualizarMetrica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { FlatList } from "react-native-gesture-handler";
import ModalMetrica from "../../components/ModalMetrica";
import ModalMeta from "../../components/ModalMeta";
import CardValorMetrica from "../../components/CardValorMetrica";
import { getAllMetrica, updateMetrica } from "../../services/metrica.service";
import {
getAllMetrica,
getSomaHidratacao,
updateMetrica,
} from "../../services/metrica.service";

export default function VisualizarMetrica() {
const params = useLocalSearchParams() as unknown as IMetrica;
Expand All @@ -50,6 +54,7 @@ export default function VisualizarMetrica() {

AsyncStorage.getItem("token").then((response) => {
setToken(response as string);
getHidratacao(response as string);
});
};

Expand Down Expand Up @@ -225,8 +230,14 @@ export default function VisualizarMetrica() {
}
};

const limparValorHidratacao = () => {
console.log("LIMPOU");
const getHidratacao = (token: string) => {
if (params.categoria !== EMetricas.HIDRATACAO) return;

getSomaHidratacao(params.id, token)
.then((response) => {
setSomaMeta(response);
})
.catch((err) => console.log(err));
};

useEffect(() => {
Expand Down Expand Up @@ -283,12 +294,6 @@ export default function VisualizarMetrica() {
]}
>{`${somaMeta} ml/${meta} ml`}</Text>
</View>
<Pressable
style={styles.botaoLimpar}
onPress={limparValorHidratacao}
>
<Text style={styles.textoBotaoLimpar}>Limpar</Text>
</Pressable>
</View>
)}
</View>
Expand Down
22 changes: 22 additions & 0 deletions src/app/services/metrica.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,25 @@ export const updateMetrica = async (

return json;
};

export const getSomaHidratacao = async (
id: number,
token: string,
): Promise<number> => {
const response = await fetch(`${BASE_URL}/soma-hidratacao/${id}`, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});

const json = await response.json();

if (response.status !== 200) {
throw new Error(json.message as string);
}

return json.data;
};

0 comments on commit 01941df

Please sign in to comment.