Add quest, sideQuest models

This commit is contained in:
Ceda EI 2019-04-01 17:34:48 +05:30
parent 78e217043b
commit 36df5f230a
2 changed files with 37 additions and 0 deletions

View File

@ -1,5 +1,8 @@
import player from "./player";
import quest from "./quest";
export default (config, axios) => { return {
player: player(config, axios),
quest: quest(config, axios, "quest"),
sideQuest: quest(config, axios, "sideQuest")
};};

34
src/models/quest.js Normal file
View File

@ -0,0 +1,34 @@
const getQuests = (config, axios, type) => (token) => {
const endpoint = type === "quest" ? "get_quests" : "get_side_quests";
const url = `${config.apiUrl}/${endpoint}?token=${encodeURIComponent(token)}`;
return axios.get(url)
.then((res) => {
if (res.status !== 200)
return false;
else
return res.data;
});
};
const getQuest = (config, axios, type) => (token, id) => {
const endpoint = type === "quest" ? "get_quest" : "get_side_quest";
const url = `${config.apiUrl}/${endpoint}?token=${encodeURIComponent(token)}&id=${encodeURIComponent(id)}`;
return axios.get(url)
.then((res) => {
if (res.status !== 200)
return false;
else
return res.data;
});
};
export default (config, axios, type) => {
const quest = {};
const keys = {
"quest": ["getQuests", "getQuest", ],
"sideQuest": ["getSideQuests", "getSideQuest"]
}[type];
quest[keys[0]] = getQuests(config, axios, type);
quest[keys[1]] = getQuest(config, axios, type);
return quest;
};