Created the Achievement.ts controller

This commit is contained in:
Mathias Wagner 2023-11-12 16:17:58 +01:00
parent b6d96121c0
commit 5851d74798
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

25
controller/achievement.ts Normal file
View File

@ -0,0 +1,25 @@
import {Achievement} from "../models/Achievement";
/**
* Get all achievements of a guild
* @param guildId The id of the guild
* @param category The category of the achievements
*/
export const getAchievements = async (guildId: string, category: number) => {
return Achievement.findAll({where: {guildId: guildId, categoryId: category}});
}
/**
* Get the statistics of a guild
* @param guildId The id of the guild
*/
export const getStatistics = async (guildId: string) => {
let achievements = await Achievement.findAll({where: {guildId: guildId}});
let statistics: number[] = [];
for (let i = 1; i <= 5; i++) {
statistics.push(achievements.filter((achievement) => achievement.categoryId === i).length);
}
return statistics;
}