fix: remove all export const method and replace it with ScheduleJob method to specific third-party endpoint data
This commit is contained in:
1 parent
67e122db34
commit
eb6f789b08
1 file changed
+34
-61
+34
-61
@@ -17,84 +17,57 @@ import TravelData from "../models/TravelData.js";
|
|||||||
import TravelPreventionData from "../models/TravelPreventionData.js";
|
import TravelPreventionData from "../models/TravelPreventionData.js";
|
||||||
|
|
||||||
// Get China Data method
|
// Get China Data method
|
||||||
export const getChinaData = async (req, res) => {
|
schedule.scheduleJob('fetchChinaData', '0 0 * * *', () => {
|
||||||
// 导入环境变量
|
// 导入环境变量
|
||||||
const { tianapiKey } = process.env;
|
const { tianapiKey } = process.env;
|
||||||
const ncovChinaUrl = `https://api.tianapi.com/ncov/index?key=${tianapiKey}`;
|
const ncovChinaUrl = `https://api.tianapi.com/ncov/index?key=${tianapiKey}`;
|
||||||
schedule.scheduleJob('fetch', '0 0 * * *', () => {
|
axios.get(ncovChinaUrl).then((result) => {
|
||||||
try {
|
const { data } = result;
|
||||||
axios.get(ncovChinaUrl).then((result) => {
|
let parseData = data;
|
||||||
const { data } = result;
|
ncovChinaData.insertMany(parseData);
|
||||||
let parseData = data;
|
|
||||||
ncovChinaData.insertMany(parseData);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(404).json({ message: error });
|
|
||||||
}
|
|
||||||
schedule.cancelJob('fetch');
|
|
||||||
});
|
});
|
||||||
};
|
schedule.cancelJob('fetchChinaData');
|
||||||
|
});
|
||||||
|
|
||||||
// Get Abroad Data method
|
// Get Abroad Data method
|
||||||
export const getAbroadData = async (req, res) => {
|
schedule.scheduleJob('fetchAbroadData', '0 0 * * *', () => {
|
||||||
// 导入环境变量
|
// 导入环境变量
|
||||||
const { tianapiKey } = process.env;
|
const {tianapiKey} = process.env;
|
||||||
const ncovAbroadUrl = `https://api.tianapi.com/ncovabroad/index?key=${tianapiKey}`;
|
const ncovAbroadUrl = `https://api.tianapi.com/ncovabroad/index?key=${tianapiKey}`;
|
||||||
schedule.scheduleJob('fetch', '0 0 * * *', () => {
|
axios.get(ncovAbroadUrl).then((result) => {
|
||||||
try {
|
const {data} = result;
|
||||||
axios.get(ncovAbroadUrl).then((result) => {
|
let parseData = data;
|
||||||
const { data } = result;
|
// 写入获取数据到数据库
|
||||||
let parseData = data;
|
ncovAbroadData.insertMany(parseData);
|
||||||
res.status(200).json(data);
|
|
||||||
// 写入获取数据到数据库
|
|
||||||
ncovAbroadData.insertMany(parseData);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(404).json({ message: error });
|
|
||||||
}
|
|
||||||
schedule.cancelJob('fetch');
|
|
||||||
})
|
})
|
||||||
};
|
schedule.cancelJob('fetchAbroadData');
|
||||||
|
});
|
||||||
|
|
||||||
// Get China Data method
|
// Get China Data method
|
||||||
export const ChinaData = async (req, res) => {
|
schedule.scheduleJob('ChinaData', '0 0 * * *', () => {
|
||||||
const { wapiAppid, wapiSign } = process.env;
|
const { wapiAppid, wapiSign } = process.env;
|
||||||
const ChinaNcovUrl = `https://yupn.api.storeapi.net/api/94/219?format=json&appid=${wapiAppid}&sign=${wapiSign}`;
|
const ChinaNcovUrl = `https://yupn.api.storeapi.net/api/94/219?format=json&appid=${wapiAppid}&sign=${wapiSign}`;
|
||||||
schedule.scheduleJob('fetch', '0 0 * * *', () => {
|
axios.get(ChinaNcovUrl).then((result) => {
|
||||||
try {
|
const { data } = result;
|
||||||
axios.get(ChinaNcovUrl).then((result) => {
|
let parseData = data;
|
||||||
const { data } = result;
|
// 写入获取数据到数据库
|
||||||
let parseData = data;
|
ChinaNcovData.insertMany(parseData);
|
||||||
res.status(200).json(data);
|
});
|
||||||
// 写入获取数据到数据库
|
schedule.cancelJob('ChinaData');
|
||||||
ChinaNcovData.insertMany(parseData);
|
})
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(404).json({ message: error });
|
|
||||||
}
|
|
||||||
schedule.cancelJob('fetch');
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get World Data method
|
// Get World Data method
|
||||||
export const WorldData = async (req, res) => {
|
schedule.scheduleJob('WorldData', '0 0 * * *', () => {
|
||||||
const { wapiAppid, wapiSign } = process.env;
|
const { wapiAppid, wapiSign } = process.env;
|
||||||
const worldNcovUrl = `https://yupn.api.storeapi.net/api/94/220?format=json&appid=${wapiAppid}&sign=${wapiSign}`;
|
const worldNcovUrl = `https://yupn.api.storeapi.net/api/94/220?format=json&appid=${wapiAppid}&sign=${wapiSign}`;
|
||||||
schedule.scheduleJob('fetch', '0 0 * * *', () => {
|
axios.get(worldNcovUrl).then((result) => {
|
||||||
try {
|
const { data } = result;
|
||||||
axios.get(worldNcovUrl).then((result) => {
|
let parseData = data;
|
||||||
const { data } = result;
|
// 写入获取数据到数据库
|
||||||
let parseData = data;
|
WorldNcovData.insertMany(parseData);
|
||||||
res.status(200).json(data);
|
});
|
||||||
// 写入获取数据到数据库
|
schedule.scheduleJob('WorldData');
|
||||||
WorldNcovData.insertMany(parseData);
|
})
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(404).json({ message: error });
|
|
||||||
}
|
|
||||||
schedule.scheduleJob('fetch');
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get Image Data method
|
// Get Image Data method
|
||||||
export const getImage = async (req, res) => {
|
export const getImage = async (req, res) => {
|
||||||
|
|||||||
Reference in new issue
Block a user