mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-23 04:30:11 +09:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
// React
|
|
import { format } from 'date-fns'
|
|
|
|
const {
|
|
FITBIT_TOKEN: bearer
|
|
} = process.env;
|
|
|
|
const today = format(new Date(), 'yyyy-MM-dd')
|
|
|
|
export const getName = async (props) => {
|
|
const uuid = props;
|
|
return fetch(
|
|
'https://api.fitbit.com/1/user/-/activities/heart/date/today/1d/1sec/time/00:00/23:59.json',
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${bearer}`,
|
|
},
|
|
}
|
|
);
|
|
};
|
|
|
|
const FitbitHeartrate = async (req, res) => {
|
|
const { uuid } = req.query
|
|
const response = await getName(uuid);
|
|
const data = await response.json();
|
|
if (response.status === 204 || response.status > 400) {
|
|
return res.status(200).send("404");
|
|
}
|
|
// const heartrate = data.map((item, i) => {
|
|
// if (item.dateTime = today) {
|
|
// return item
|
|
// } else {
|
|
// return "Failed to retrieve data."
|
|
// }
|
|
// }
|
|
// )
|
|
const array = data["activities-heart-intraday"].dataset
|
|
const heartrate = array[array.length - 1]
|
|
return res.status(200).json({
|
|
heartrate,
|
|
});
|
|
};
|
|
|
|
export default FitbitHeartrate |