Skip to content

Commit

Permalink
Refactor updating server panel on new vote
Browse files Browse the repository at this point in the history
  • Loading branch information
chimpdev committed Mar 31, 2024
1 parent d2eb631 commit e43f716
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 1 addition & 11 deletions server/src/schemas/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const keywordsValidation = require('@/validations/servers/keywords');
const updatePanelMessage = require('@/utils/servers/updatePanelMessage');

const ServerSchema = new Schema({
id: {
Expand Down Expand Up @@ -104,13 +103,4 @@ const ServerSchema = new Schema({
}
});

const Model = mongoose.model('Server', ServerSchema);

Model.watch().on('change', async data => {
if (data.operationType === 'update' && data.updateDescription.updatedFields.votes) {
const server = await Model.findOne({ _id: data.documentKey._id });
await updatePanelMessage(server.id);
}
});

module.exports = Model;
module.exports = mongoose.model('Server', ServerSchema);
3 changes: 3 additions & 0 deletions server/src/utils/servers/incrementVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Server = require('@/schemas/Server');
const VoteTimeout = require('@/schemas/Server/Vote/Timeout');
const Premium = require('@/schemas/Premium');
const Discord = require('discord.js');
const updatePanelMessage = require('@/utils/servers/updatePanelMessage');

async function incrementVote(guildId, userId) {
const guild = client.guilds.cache.get(guildId);
Expand Down Expand Up @@ -71,6 +72,8 @@ async function incrementVote(guildId, userId) {
}
}).save();

updatePanelMessage(guild.id);

const user = client.users.cache.get(userId) || await client.users.fetch(userId);
const embed = new Discord.EmbedBuilder()
.setColor(Discord.Colors.Purple)
Expand Down

0 comments on commit e43f716

Please sign in to comment.