25 lines
767 B
TypeScript
25 lines
767 B
TypeScript
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;
|
|
} |