Skip to content

Commit

Permalink
Fix issue with new subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Dec 1, 2020
1 parent 1d9bc7d commit 2c90822
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/models/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ class Subscription extends Model {
if (subscription && subscription.id > 0) {
return subscription.id;
}
return await this.createUserSubscription(guildId, userId);
const newSubscription = await this.createUserSubscription(guildId, userId);
return newSubscription.id;
}

static async createUserSubscription(guildId, userId) {
const subscription = Subscription.build({
id: 0,
guildId: guildId,
userId: userId,
enabled: 1,
distance: 0,
latitude: 0,
longitude: 0,
iconStyle: 'Default',
});
const results = await subscription.save();
return results.id;
return results;
}

static updateSubscription(guildId, userId, enabled, distance, latitude, longitude, iconStyle, phoneNumber) {
Expand All @@ -53,13 +49,17 @@ class Subscription extends Model {
});
}

static getSubscription(guildId, userId) {
return Subscription.findOne({
static async getSubscription(guildId, userId) {
const existing = await Subscription.findOne({
where: {
guildId: guildId,
userId: userId,
}
});
if (!existing) {
return await this.createUserSubscription(guildId, userId);
}
return existing;
}
}

Expand Down

0 comments on commit 2c90822

Please sign in to comment.