From 5851d747987ee2cc54b2aa83891405f960cbf8b1 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 12 Nov 2023 16:17:58 +0100 Subject: [PATCH] Created the Achievement.ts controller --- controller/achievement.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 controller/achievement.ts diff --git a/controller/achievement.ts b/controller/achievement.ts new file mode 100644 index 0000000..600fc2a --- /dev/null +++ b/controller/achievement.ts @@ -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; +} \ No newline at end of file