-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperiodicMedicalDataFetch.js
More file actions
43 lines (37 loc) · 919 Bytes
/
Copy pathperiodicMedicalDataFetch.js
File metadata and controls
43 lines (37 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const cron = require("node-cron");
const axios = require("axios");
const prisma = require("./prismaClient");
const MEDICAL_DATA_PROVIDER_URL = "http://localhost:4000/medical-data";
const fetchMedicalData = async (email) => {
const response = await axios.get(
`${MEDICAL_DATA_PROVIDER_URL}?email=${email}`
);
return response.data;
};
async function main() {
try {
const users = await prisma.user.findMany({
select: {
email: true,
},
});
for (const user of users) {
const dieticianData = await fetchMedicalData(user.email);
if (dieticianData) {
await prisma.user.update({
where: {
email: user.email,
},
data: {
dieticianData,
},
});
}
}
} catch (error) {
console.error("Error updating medical data:", error);
}
}
cron.schedule("* * * * *", () => {
main();
});