-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add check for user in guild after voting and return it in response * Add set reminder route for servers * Rename Reminder to VoteReminder, remove date field from newReminder object * Add can_set_reminder field to get server route * Remove date field from new vote reminder object * Refactor voteServer to return response data * Add createReminder function * Add create reminder button and functionality to Actions component
- Loading branch information
Showing
7 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import config from '@/config'; | ||
import axios from 'axios'; | ||
|
||
export default function createReminder(id) { | ||
// eslint-disable-next-line no-async-promise-executor | ||
return new Promise(async (resolve, reject) => { | ||
const url = `${config.api.url}/servers/${id}/reminder`; | ||
|
||
try { | ||
await axios.post(url, {}, { withCredentials: true }); | ||
resolve(); | ||
} catch (error) { | ||
reject(error instanceof axios.AxiosError ? (error.response?.data?.error || error.message) : error.message); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const checkAuthentication = require('@/utils/middlewares/checkAuthentication'); | ||
const useRateLimiter = require('@/utils/useRateLimiter'); | ||
const { param, matchedData } = require('express-validator'); | ||
const Server = require('@/schemas/Server'); | ||
const VoteTimeout = require('@/schemas/Server/Vote/Timeout'); | ||
const VoteReminder = require('@/schemas/Server/Vote/Reminder'); | ||
const bodyParser = require('body-parser'); | ||
|
||
module.exports = { | ||
post: [ | ||
useRateLimiter({ maxRequests: 5, perMinutes: 1 }), | ||
bodyParser.json(), | ||
checkAuthentication, | ||
param('id'), | ||
async (request, response) => { | ||
const { id } = matchedData(request); | ||
|
||
const guild = client.guilds.cache.get(id); | ||
if (!guild) return response.sendError('Guild not found.', 404); | ||
|
||
const server = await Server.findOne({ id }); | ||
if (!server) return response.sendError('Server not found.', 404); | ||
|
||
const timeout = await VoteTimeout.findOne({ 'user.id': request.user.id, 'guild.id': id }); | ||
if (!timeout) return response.sendError('You can\'t set a reminder for a server you haven\'t voted for.', 400); | ||
|
||
const reminder = await VoteReminder.findOne({ 'user.id': request.user.id, 'guild.id': id }); | ||
if (reminder) return response.sendError('You already set a reminder for this server.', 400); | ||
|
||
const newReminder = new VoteReminder({ | ||
user: { | ||
id: request.user.id | ||
}, | ||
guild: { | ||
id | ||
} | ||
}); | ||
|
||
const validationErrors = newReminder.validateSync(); | ||
if (validationErrors) return response.sendError('An unknown error occurred.', 400); | ||
|
||
await newReminder.save(); | ||
|
||
return response.sendStatus(204).end(); | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters