11const { Model } = require ( 'sequelize' ) ;
22
33class Guild extends Model {
4- static async getGuild ( id ) {
5- return await this . findOne ( {
6- where : {
7- id : id
8- }
9- } ) ;
10- }
4+ static async getGuild ( id ) {
5+ return await this . findOne ( {
6+ where : {
7+ id : id
8+ }
9+ } ) ;
10+ }
1111
12- static async createGuild ( id ) {
13- return await this . create ( {
14- id : id
15- } ) ;
16- }
12+ static async createGuild ( id ) {
13+ return await this . create ( {
14+ id : id
15+ } ) ;
16+ }
1717
18- // gets the guilds leaderboard
19- async getLeaderboard ( ) {
20- return await this . sequelize . models . Score . findAll ( {
21- where : { GuildId : this . id } ,
22- order : [ [ 'score' , 'DESC' ] ] ,
23- limit : 10 ,
24- include : [ this . sequelize . models . User ]
25- } ) ;
26- }
18+ // gets the guilds leaderboard
19+ async getLeaderboard ( ) {
20+ return await this . sequelize . models . Score . findAll ( {
21+ where : { GuildId : this . id } ,
22+ order : [ [ 'score' , 'DESC' ] ] ,
23+ limit : 10 ,
24+ include : [ this . sequelize . models . User ]
25+ } ) ;
26+ }
2727
28- // retrieve user score
29- async getScore ( userId ) {
30- const score = await this . sequelize . models . Score . findOne ( {
31- attributes : [ 'score' ] ,
32- where : {
33- GuildId : this . id ,
34- UserId : userId
35- }
36- } ) ;
28+ // retrieve user score
29+ async getScore ( userId ) {
30+ const score = await this . sequelize . models . Score . findOne ( {
31+ attributes : [ 'score' ] ,
32+ where : {
33+ GuildId : this . id ,
34+ UserId : userId
35+ }
36+ } ) ;
3737
38- return score . score ;
39- }
38+ return score . score ;
39+ }
4040
41- /**
42- * Adds 2 to the users score within the specified guild.
43- *
44- * @param {* } user discord user object
45- * @returns {model }}
46- */
47- async plusTwo ( userId ) {
48- return await this . sequelize . models . Score . increment ( 'score' , {
49- by : 2 ,
50- where : {
51- GuildId : this . id ,
52- UserId : userId
53- }
54- } ) ;
55- }
41+ /**
42+ * Adds 2 to the users score within the specified guild.
43+ *
44+ * @param {* } user discord user object
45+ * @returns {model }}
46+ */
47+ async plusTwo ( userId ) {
48+ return await this . sequelize . models . Score . increment ( 'score' , {
49+ by : 2 ,
50+ where : {
51+ GuildId : this . id ,
52+ UserId : userId
53+ }
54+ } ) ;
55+ }
5656
57- // subtracts 2 from the users score. takes in a user object
58- async minusTwo ( userId ) {
59- return await this . sequelize . models . Score . decrement ( 'score' , {
60- by : 2 ,
61- where : {
62- GuildId : this . id ,
63- UserId : userId
64- }
65- } ) ;
66- }
57+ // subtracts 2 from the users score. takes in a user object
58+ async minusTwo ( userId ) {
59+ return await this . sequelize . models . Score . decrement ( 'score' , {
60+ by : 2 ,
61+ where : {
62+ GuildId : this . id ,
63+ UserId : userId
64+ }
65+ } ) ;
66+ }
6767}
6868
6969/**
@@ -93,4 +93,4 @@ module.exports = (sequelize, DataTypes) => {
9393 timestamps : false ,
9494 modelName : 'Guild'
9595 } ) ;
96- } ;
96+ } ;
0 commit comments