@icytrigun/achievementpackage
Version:
create and manage Achievements for gamification
271 lines (244 loc) • 9.16 kB
JavaScript
const staticAchievementUrl = "http://localhost:8081/";
async function getAchievementById(id) {
axios.get(staticAchievementUrl+"achievement/get/"+id)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call Achievement Function");
});
}
async function createAchievement(name,description,imagePath,toFullFillDescription,rewardImagePath,rewardDescription,toFullFillValue=1,timeLimit=null) {
axios.post(staticAchievementUrl+"achievement/set/",{
name: name,
description: description,
imagePath: imagePath,
toFullFillDescription: toFullFillDescription,
toFullFillValue: toFullFillValue,
rewardImagePath: rewardImagePath,
rewardDescription: rewardDescription,
timeLimit: timeLimit,
})
.then(response => {
console.log(response.data.toString())
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call setAchievementFunction Function");
});
}
async function deleteAchievement(id){
axios.delete(staticAchievementUrl+"achievement/delete"+id)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call deleteAchievement Function");
});
}
async function updateAchievement(id,achievement){
axios.put(staticAchievementUrl+"achievement/update"+id,{
id: id,
name: achievement.name,
description: achievement.description,
imagePath: achievement.imagePath,
toFullFillDescription: achievement.toFullFillDescription,
toFullFillValue: achievement.toFullFillValue,
timeLimit: achievement.timeLimit
})
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call updateAchievement Function");
});
}
//AchievementByUserCode
async function getAllAchievementsOfUserHTML(entryId,userId){
axios.get(staticAchievementUrl+"achievementByUser/getAllAchievementsOfUserHTML/"+userId)
.then(response => {
console.log(response)
document.getElementById(entryId).innerHTML = response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call getAllAchievementHTML Function")
});
}
async function getAchievementOfUserHTML(entryId,userId,achievementId){
axios.get(staticAchievementUrl+"achievementByUser/getAllAchievementsOfUserHTML/"+userId+"/"+achievementId)
.then(response => {
console.log(response)
document.getElementById(entryId).innerHTML = response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call getAchievementHTML Function")
});
}
async function setNewAchievementByUser(achievementId,userId,currentFullFilledValue,fulfilled) {
axios.post(staticAchievementUrl+"achievementByUser/set",{
achievementId: achievementId,
userId: userId,
currentFullFilledValue: currentFullFilledValue,
fulfilled: fulfilled,
})
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call AddUsersToLeaderBoard Function");
});
}
async function setNewAchievementByUserByAchievementAndUserId(achievementId,userId) {
axios.post(staticAchievementUrl+"achievementByUser/setByAchievementAndUserId/"+achievementId+"/"+userId)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call setAchievementByUserAndAchievementId Function");
});
}
async function getAllAchievementByUsers() {
axios.get(staticAchievementUrl+"achievementByUser/getAll")
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call AchievementByUser Function")
});
}
async function getAchievementByUserById(id) {
axios.get(staticAchievementUrl+"achievementByUser/get/"+id)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call getAchievementByUserById Function");
});
}
async function updateAchievementWIthAchievementIdByUserPoints(achievementByUserId,points) {
axios.put(staticAchievementUrl+"achievementByUser/updateProgressByAchievementByUserId/"+ achievementByUserId + "/" + points )
.then(response => {
console.log(response.data)
if(response.data.newlyFinished){
toastr.success("Errungenschaft "+response.data.achievementName +" ist abgeschlossen", "Neue Errungenschaft");
}
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call updateAchievementPoints Function");
});
}
async function updateAchievementByUserPoints(achievementId,userId,points) {
axios.put(staticAchievementUrl+"achievementByUser/updateProgressByUserAndAchievementId/"+ achievementId + "/"+userId+"/" + points )
.then(response => {
console.log(response.data)
if(response.data.newlyFinished){
toastr.success("Errungenschaft "+response.data.achievementName +" ist abgeschlossen", "Neue Errungenschaft");
}
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call updateAchievementPoints Function");
});
}
async function deleteAchievementByUser(id){
axios.delete(staticAchievementUrl+"achievementByUser/delete"+id)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call deleteAchievementByUser Function");
});
}
async function updateAchievementByUser(id,achievementByUser){
axios.put(staticAchievementUrl+"achievementByUser/update"+id,{
id: id,
achievementId: achievementByUser.achievementId,
userId: achievementByUser.userId,
currentFullFilledValue: achievementByUser.currentFullFilledValue,
fulfilled: achievementByUser.fulfilled,
})
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call updateAchievementByUser Function");
});
}
async function getAllAchievementsOfUser(userId) {
axios.get(staticAchievementUrl+"/achievementByUser/getAllAchievementsOfUser/"+ userId)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call getAchievementOfUser Function");
});
}
async function getAchievementByUserByUserIdAndAchievementId(userId,achievementId) {
axios.get(staticAchievementUrl+"/achievementByUser/getAllAchievementsOfUser/"+ userId+"/"+achievementId)
.then(response => {
console.log(response.data)
return response.data;
})
.catch(function (error) {
console.log(error);
})
.finally(() => {
console.log("i did try to call getAchievementByUserByUserIdAndAchievementId Function");
});
}