Created the Achievement.ts controller
This commit is contained in:
parent
b6d96121c0
commit
5851d74798
25
controller/achievement.ts
Normal file
25
controller/achievement.ts
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user