diff --git a/src/controllers/v4/interactions/kissu.js b/src/controllers/v4/interactions/kiss.js similarity index 77% rename from src/controllers/v4/interactions/kissu.js rename to src/controllers/v4/interactions/kiss.js index 18d0560..d2e1b2a 100644 --- a/src/controllers/v4/interactions/kissu.js +++ b/src/controllers/v4/interactions/kiss.js @@ -2,8 +2,8 @@ import createError from 'http-errors'; import Kissu from '../../../models/schemas/Kissu.js'; import Stats from '../../../models/schemas/Stat.js'; -// Get random Anime Kissu -const getRandomKissu = async (req, res, next) => { +// Get random Anime Kiss +const getRandomKiss = async (req, res, next) => { try { const [result] = await Kissu.aggregate([ // Select a random document from the results @@ -12,7 +12,7 @@ const getRandomKissu = async (req, res, next) => { ]); if (!result) { - return next(createError(404, 'Could not find any Kissu Gif')); + return next(createError(404, 'Could not find any Kiss Gif')); } res.status(200).json(result); @@ -24,4 +24,4 @@ const getRandomKissu = async (req, res, next) => { } }; -export default getRandomKissu; +export default getRandomKiss; diff --git a/src/routes/v4/interactions/angry.js b/src/routes/v4/interactions/angry.js new file mode 100644 index 0000000..24618d9 --- /dev/null +++ b/src/routes/v4/interactions/angry.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomAngry from '../../../controllers/v4/interactions/angry.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/angry Get a Random Angry + * @apiDescription Retrieve a random angry. + * @apiName GetRandomAngry + * @apiGroup Angry + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomAngry) + /** + * @api {post} v4/angry Increment Angry Data + * @apiDescription Increment data related to angrys (only accessible by database moderators). + * @apiName IncrementAngryData + * @apiGroup Angry + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Angry')); + +router + .route('/:id') + /** + * @api {patch} v4/angry/:id Update Angry Data + * @apiDescription Update data related to angrys with a specific ID (only accessible by database moderators). + * @apiName UpdateAngryData + * @apiGroup Angry + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Angry')) + /** + * @api {delete} v4/angry/:id Delete Angry Data + * @apiDescription Delete data related to angry with a specific ID (only accessible by admins). + * @apiName DeleteAngryData + * @apiGroup Angry + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Angry')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/baka.js b/src/routes/v4/interactions/baka.js new file mode 100644 index 0000000..659f5c2 --- /dev/null +++ b/src/routes/v4/interactions/baka.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBaka from '../../../controllers/v4/interactions/baka.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/baka Get a Random Baka + * @apiDescription Retrieve a random baka. + * @apiName GetRandomBaka + * @apiGroup Baka + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBaka) + /** + * @api {post} v4/baka Increment Baka Data + * @apiDescription Increment data related to bakas (only accessible by database moderators). + * @apiName IncrementBakaData + * @apiGroup Baka + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Baka')); + +router + .route('/:id') + /** + * @api {patch} v4/baka/:id Update Baka Data + * @apiDescription Update data related to bakas with a specific ID (only accessible by database moderators). + * @apiName UpdateBakaData + * @apiGroup Baka + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Baka')) + /** + * @api {delete} v4/baka/:id Delete Baka Data + * @apiDescription Delete data related to baka with a specific ID (only accessible by admins). + * @apiName DeleteBakaData + * @apiGroup Baka + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Baka')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/bite.js b/src/routes/v4/interactions/bite.js new file mode 100644 index 0000000..0abc283 --- /dev/null +++ b/src/routes/v4/interactions/bite.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBite from '../../../controllers/v4/interactions/bite.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/bite Get a Random Bite + * @apiDescription Retrieve a random bite. + * @apiName GetRandomBite + * @apiGroup Bite + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBite) + /** + * @api {post} v4/bite Increment Bite Data + * @apiDescription Increment data related to bites (only accessible by database moderators). + * @apiName IncrementBiteData + * @apiGroup Bite + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Bite')); + +router + .route('/:id') + /** + * @api {patch} v4/bite/:id Update Bite Data + * @apiDescription Update data related to bites with a specific ID (only accessible by database moderators). + * @apiName UpdateBiteData + * @apiGroup Bite + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Bite')) + /** + * @api {delete} v4/bite/:id Delete Bite Data + * @apiDescription Delete data related to bite with a specific ID (only accessible by admins). + * @apiName DeleteBiteData + * @apiGroup Bite + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Bite')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/blush.js b/src/routes/v4/interactions/blush.js new file mode 100644 index 0000000..6eeed35 --- /dev/null +++ b/src/routes/v4/interactions/blush.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBlush from '../../../controllers/v4/interactions/blush.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/blush Get a Random Blush + * @apiDescription Retrieve a random blush. + * @apiName GetRandomBlush + * @apiGroup Blush + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBlush) + /** + * @api {post} v4/blush Increment Blush Data + * @apiDescription Increment data related to blushs (only accessible by database moderators). + * @apiName IncrementBlushData + * @apiGroup Blush + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Blush')); + +router + .route('/:id') + /** + * @api {patch} v4/blush/:id Update Blush Data + * @apiDescription Update data related to blushs with a specific ID (only accessible by database moderators). + * @apiName UpdateBlushData + * @apiGroup Blush + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Blush')) + /** + * @api {delete} v4/blush/:id Delete Blush Data + * @apiDescription Delete data related to blush with a specific ID (only accessible by admins). + * @apiName DeleteBlushData + * @apiGroup Blush + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Blush')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/bonk.js b/src/routes/v4/interactions/bonk.js new file mode 100644 index 0000000..f1fea63 --- /dev/null +++ b/src/routes/v4/interactions/bonk.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBonk from '../../../controllers/v4/interactions/bonk.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/bonk Get a Random Bonk + * @apiDescription Retrieve a random bonk. + * @apiName GetRandomBonk + * @apiGroup Bonk + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBonk) + /** + * @api {post} v4/bonk Increment Bonk Data + * @apiDescription Increment data related to bonks (only accessible by database moderators). + * @apiName IncrementBonkData + * @apiGroup Bonk + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Bonk')); + +router + .route('/:id') + /** + * @api {patch} v4/bonk/:id Update Bonk Data + * @apiDescription Update data related to bonks with a specific ID (only accessible by database moderators). + * @apiName UpdateBonkData + * @apiGroup Bonk + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Bonk')) + /** + * @api {delete} v4/bonk/:id Delete Bonk Data + * @apiDescription Delete data related to bonk with a specific ID (only accessible by admins). + * @apiName DeleteBonkData + * @apiGroup Bonk + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Bonk')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/bored.js b/src/routes/v4/interactions/bored.js new file mode 100644 index 0000000..9713d3a --- /dev/null +++ b/src/routes/v4/interactions/bored.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBored from '../../../controllers/v4/interactions/bored.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/bored Get a Random Bored + * @apiDescription Retrieve a random bored. + * @apiName GetRandomBored + * @apiGroup Bored + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBored) + /** + * @api {post} v4/bored Increment Bored Data + * @apiDescription Increment data related to boreds (only accessible by database moderators). + * @apiName IncrementBoredData + * @apiGroup Bored + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Bored')); + +router + .route('/:id') + /** + * @api {patch} v4/bored/:id Update Bored Data + * @apiDescription Update data related to boreds with a specific ID (only accessible by database moderators). + * @apiName UpdateBoredData + * @apiGroup Bored + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Bored')) + /** + * @api {delete} v4/bored/:id Delete Bored Data + * @apiDescription Delete data related to bored with a specific ID (only accessible by admins). + * @apiName DeleteBoredData + * @apiGroup Bored + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Bored')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/bully.js b/src/routes/v4/interactions/bully.js new file mode 100644 index 0000000..23e16bc --- /dev/null +++ b/src/routes/v4/interactions/bully.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBully from '../../../controllers/v4/interactions/bully.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/bully Get a Random Bully + * @apiDescription Retrieve a random bully. + * @apiName GetRandomBully + * @apiGroup Bully + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBully) + /** + * @api {post} v4/bully Increment Bully Data + * @apiDescription Increment data related to bullys (only accessible by database moderators). + * @apiName IncrementBullyData + * @apiGroup Bully + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Bully')); + +router + .route('/:id') + /** + * @api {patch} v4/bully/:id Update Bully Data + * @apiDescription Update data related to bullys with a specific ID (only accessible by database moderators). + * @apiName UpdateBullyData + * @apiGroup Bully + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Bully')) + /** + * @api {delete} v4/bully/:id Delete Bully Data + * @apiDescription Delete data related to bully with a specific ID (only accessible by admins). + * @apiName DeleteBullyData + * @apiGroup Bully + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Bully')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/bye.js b/src/routes/v4/interactions/bye.js new file mode 100644 index 0000000..5008c8c --- /dev/null +++ b/src/routes/v4/interactions/bye.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomBye from '../../../controllers/v4/interactions/bye.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/bye Get a Random Bye + * @apiDescription Retrieve a random bye. + * @apiName GetRandomBye + * @apiGroup Bye + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomBye) + /** + * @api {post} v4/bye Increment Bye Data + * @apiDescription Increment data related to byes (only accessible by database moderators). + * @apiName IncrementByeData + * @apiGroup Bye + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Bye')); + +router + .route('/:id') + /** + * @api {patch} v4/bye/:id Update Bye Data + * @apiDescription Update data related to byes with a specific ID (only accessible by database moderators). + * @apiName UpdateByeData + * @apiGroup Bye + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Bye')) + /** + * @api {delete} v4/bye/:id Delete Bye Data + * @apiDescription Delete data related to bye with a specific ID (only accessible by admins). + * @apiName DeleteByeData + * @apiGroup Bye + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Bye')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/chase.js b/src/routes/v4/interactions/chase.js new file mode 100644 index 0000000..685cbd6 --- /dev/null +++ b/src/routes/v4/interactions/chase.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomChase from '../../../controllers/v4/interactions/chase.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/chase Get a Random Chase + * @apiDescription Retrieve a random chase. + * @apiName GetRandomChase + * @apiGroup Chase + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomChase) + /** + * @api {post} v4/chase Increment Chase Data + * @apiDescription Increment data related to chases (only accessible by database moderators). + * @apiName IncrementChaseData + * @apiGroup Chase + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Chase')); + +router + .route('/:id') + /** + * @api {patch} v4/chase/:id Update Chase Data + * @apiDescription Update data related to chases with a specific ID (only accessible by database moderators). + * @apiName UpdateChaseData + * @apiGroup Chase + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Chase')) + /** + * @api {delete} v4/chase/:id Delete Chase Data + * @apiDescription Delete data related to chase with a specific ID (only accessible by admins). + * @apiName DeleteChaseData + * @apiGroup Chase + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Chase')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/cheer.js b/src/routes/v4/interactions/cheer.js new file mode 100644 index 0000000..094085f --- /dev/null +++ b/src/routes/v4/interactions/cheer.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomCheer from '../../../controllers/v4/interactions/cheer.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/cheer Get a Random Cheer + * @apiDescription Retrieve a random cheer. + * @apiName GetRandomCheer + * @apiGroup Cheer + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomCheer) + /** + * @api {post} v4/cheer Increment Cheer Data + * @apiDescription Increment data related to cheers (only accessible by database moderators). + * @apiName IncrementCheerData + * @apiGroup Cheer + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Cheer')); + +router + .route('/:id') + /** + * @api {patch} v4/cheer/:id Update Cheer Data + * @apiDescription Update data related to cheers with a specific ID (only accessible by database moderators). + * @apiName UpdateCheerData + * @apiGroup Cheer + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Cheer')) + /** + * @api {delete} v4/cheer/:id Delete Cheer Data + * @apiDescription Delete data related to cheer with a specific ID (only accessible by admins). + * @apiName DeleteCheerData + * @apiGroup Cheer + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Cheer')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/cringe.js b/src/routes/v4/interactions/cringe.js new file mode 100644 index 0000000..f2a67fe --- /dev/null +++ b/src/routes/v4/interactions/cringe.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomCringe from '../../../controllers/v4/interactions/cringe.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/cringe Get a Random Cringe + * @apiDescription Retrieve a random cringe. + * @apiName GetRandomCringe + * @apiGroup Cringe + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomCringe) + /** + * @api {post} v4/cringe Increment Cringe Data + * @apiDescription Increment data related to cringes (only accessible by database moderators). + * @apiName IncrementCringeData + * @apiGroup Cringe + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Cringe')); + +router + .route('/:id') + /** + * @api {patch} v4/cringe/:id Update Cringe Data + * @apiDescription Update data related to cringes with a specific ID (only accessible by database moderators). + * @apiName UpdateCringeData + * @apiGroup Cringe + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Cringe')) + /** + * @api {delete} v4/cringe/:id Delete Cringe Data + * @apiDescription Delete data related to cringe with a specific ID (only accessible by admins). + * @apiName DeleteCringeData + * @apiGroup Cringe + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Cringe')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/cry.js b/src/routes/v4/interactions/cry.js new file mode 100644 index 0000000..86e8331 --- /dev/null +++ b/src/routes/v4/interactions/cry.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomCry from '../../../controllers/v4/interactions/cry.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/cry Get a Random Cry + * @apiDescription Retrieve a random cry. + * @apiName GetRandomCry + * @apiGroup Cry + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomCry) + /** + * @api {post} v4/cry Increment Cry Data + * @apiDescription Increment data related to crys (only accessible by database moderators). + * @apiName IncrementCryData + * @apiGroup Cry + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Cry')); + +router + .route('/:id') + /** + * @api {patch} v4/cry/:id Update Cry Data + * @apiDescription Update data related to crys with a specific ID (only accessible by database moderators). + * @apiName UpdateCryData + * @apiGroup Cry + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Cry')) + /** + * @api {delete} v4/cry/:id Delete Cry Data + * @apiDescription Delete data related to cry with a specific ID (only accessible by admins). + * @apiName DeleteCryData + * @apiGroup Cry + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Cry')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/cuddle.js b/src/routes/v4/interactions/cuddle.js new file mode 100644 index 0000000..319be14 --- /dev/null +++ b/src/routes/v4/interactions/cuddle.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomCuddle from '../../../controllers/v4/interactions/cuddle.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/cuddle Get a Random Cuddle + * @apiDescription Retrieve a random cuddle. + * @apiName GetRandomCuddle + * @apiGroup Cuddle + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomCuddle) + /** + * @api {post} v4/cuddle Increment Cuddle Data + * @apiDescription Increment data related to cuddles (only accessible by database moderators). + * @apiName IncrementCuddleData + * @apiGroup Cuddle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Cuddle')); + +router + .route('/:id') + /** + * @api {patch} v4/cuddle/:id Update Cuddle Data + * @apiDescription Update data related to cuddles with a specific ID (only accessible by database moderators). + * @apiName UpdateCuddleData + * @apiGroup Cuddle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Cuddle')) + /** + * @api {delete} v4/cuddle/:id Delete Cuddle Data + * @apiDescription Delete data related to cuddle with a specific ID (only accessible by admins). + * @apiName DeleteCuddleData + * @apiGroup Cuddle + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Cuddle')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/dab.js b/src/routes/v4/interactions/dab.js new file mode 100644 index 0000000..400d251 --- /dev/null +++ b/src/routes/v4/interactions/dab.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomDab from '../../../controllers/v4/interactions/dab.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/dab Get a Random Dab + * @apiDescription Retrieve a random dab. + * @apiName GetRandomDab + * @apiGroup Dab + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomDab) + /** + * @api {post} v4/dab Increment Dab Data + * @apiDescription Increment data related to dabs (only accessible by database moderators). + * @apiName IncrementDabData + * @apiGroup Dab + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Dab')); + +router + .route('/:id') + /** + * @api {patch} v4/dab/:id Update Dab Data + * @apiDescription Update data related to dabs with a specific ID (only accessible by database moderators). + * @apiName UpdateDabData + * @apiGroup Dab + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Dab')) + /** + * @api {delete} v4/dab/:id Delete Dab Data + * @apiDescription Delete data related to dab with a specific ID (only accessible by admins). + * @apiName DeleteDabData + * @apiGroup Dab + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Dab')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/dance.js b/src/routes/v4/interactions/dance.js new file mode 100644 index 0000000..14ca559 --- /dev/null +++ b/src/routes/v4/interactions/dance.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomDance from '../../../controllers/v4/interactions/dance.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/dance Get a Random Dance + * @apiDescription Retrieve a random dance. + * @apiName GetRandomDance + * @apiGroup Dance + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomDance) + /** + * @api {post} v4/dance Increment Dance Data + * @apiDescription Increment data related to dances (only accessible by database moderators). + * @apiName IncrementDanceData + * @apiGroup Dance + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Dance')); + +router + .route('/:id') + /** + * @api {patch} v4/dance/:id Update Dance Data + * @apiDescription Update data related to dances with a specific ID (only accessible by database moderators). + * @apiName UpdateDanceData + * @apiGroup Dance + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Dance')) + /** + * @api {delete} v4/dance/:id Delete Dance Data + * @apiDescription Delete data related to dance with a specific ID (only accessible by admins). + * @apiName DeleteDanceData + * @apiGroup Dance + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Dance')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/die.js b/src/routes/v4/interactions/die.js new file mode 100644 index 0000000..ec09301 --- /dev/null +++ b/src/routes/v4/interactions/die.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomDie from '../../../controllers/v4/interactions/die.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/die Get a Random Die + * @apiDescription Retrieve a random die. + * @apiName GetRandomDie + * @apiGroup Die + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomDie) + /** + * @api {post} v4/die Increment Die Data + * @apiDescription Increment data related to dies (only accessible by database moderators). + * @apiName IncrementDieData + * @apiGroup Die + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Die')); + +router + .route('/:id') + /** + * @api {patch} v4/die/:id Update Die Data + * @apiDescription Update data related to dies with a specific ID (only accessible by database moderators). + * @apiName UpdateDieData + * @apiGroup Die + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Die')) + /** + * @api {delete} v4/die/:id Delete Die Data + * @apiDescription Delete data related to die with a specific ID (only accessible by admins). + * @apiName DeleteDieData + * @apiGroup Die + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Die')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/disgust.js b/src/routes/v4/interactions/disgust.js new file mode 100644 index 0000000..c088f2c --- /dev/null +++ b/src/routes/v4/interactions/disgust.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomDisgust from '../../../controllers/v4/interactions/disgust.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/disgust Get a Random Disgust + * @apiDescription Retrieve a random disgust. + * @apiName GetRandomDisgust + * @apiGroup Disgust + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomDisgust) + /** + * @api {post} v4/disgust Increment Disgust Data + * @apiDescription Increment data related to disgusts (only accessible by database moderators). + * @apiName IncrementDisgustData + * @apiGroup Disgust + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Disgust')); + +router + .route('/:id') + /** + * @api {patch} v4/disgust/:id Update Disgust Data + * @apiDescription Update data related to disgusts with a specific ID (only accessible by database moderators). + * @apiName UpdateDisgustData + * @apiGroup Disgust + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Disgust')) + /** + * @api {delete} v4/disgust/:id Delete Disgust Data + * @apiDescription Delete data related to disgust with a specific ID (only accessible by admins). + * @apiName DeleteDisgustData + * @apiGroup Disgust + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Disgust')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/facepalm.js b/src/routes/v4/interactions/facepalm.js new file mode 100644 index 0000000..c2a1542 --- /dev/null +++ b/src/routes/v4/interactions/facepalm.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomFacepalm from '../../../controllers/v4/interactions/facepalm.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/facepalm Get a Random Facepalm + * @apiDescription Retrieve a random facepalm. + * @apiName GetRandomFacepalm + * @apiGroup Facepalm + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomFacepalm) + /** + * @api {post} v4/facepalm Increment Facepalm Data + * @apiDescription Increment data related to facepalms (only accessible by database moderators). + * @apiName IncrementFacepalmData + * @apiGroup Facepalm + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Facepalm')); + +router + .route('/:id') + /** + * @api {patch} v4/facepalm/:id Update Facepalm Data + * @apiDescription Update data related to facepalms with a specific ID (only accessible by database moderators). + * @apiName UpdateFacepalmData + * @apiGroup Facepalm + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Facepalm')) + /** + * @api {delete} v4/facepalm/:id Delete Facepalm Data + * @apiDescription Delete data related to facepalm with a specific ID (only accessible by admins). + * @apiName DeleteFacepalmData + * @apiGroup Facepalm + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Facepalm')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/feed.js b/src/routes/v4/interactions/feed.js new file mode 100644 index 0000000..bedb7eb --- /dev/null +++ b/src/routes/v4/interactions/feed.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomFeed from '../../../controllers/v4/interactions/feed.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/feed Get a Random Feed + * @apiDescription Retrieve a random feed. + * @apiName GetRandomFeed + * @apiGroup Feed + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomFeed) + /** + * @api {post} v4/feed Increment Feed Data + * @apiDescription Increment data related to feeds (only accessible by database moderators). + * @apiName IncrementFeedData + * @apiGroup Feed + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Feed')); + +router + .route('/:id') + /** + * @api {patch} v4/feed/:id Update Feed Data + * @apiDescription Update data related to feeds with a specific ID (only accessible by database moderators). + * @apiName UpdateFeedData + * @apiGroup Feed + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Feed')) + /** + * @api {delete} v4/feed/:id Delete Feed Data + * @apiDescription Delete data related to feed with a specific ID (only accessible by admins). + * @apiName DeleteFeedData + * @apiGroup Feed + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Feed')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/glomp.js b/src/routes/v4/interactions/glomp.js new file mode 100644 index 0000000..39100ba --- /dev/null +++ b/src/routes/v4/interactions/glomp.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomGlomp from '../../../controllers/v4/interactions/glomp.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/glomp Get a Random Glomp + * @apiDescription Retrieve a random glomp. + * @apiName GetRandomGlomp + * @apiGroup Glomp + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomGlomp) + /** + * @api {post} v4/glomp Increment Glomp Data + * @apiDescription Increment data related to glomps (only accessible by database moderators). + * @apiName IncrementGlompData + * @apiGroup Glomp + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Glomp')); + +router + .route('/:id') + /** + * @api {patch} v4/glomp/:id Update Glomp Data + * @apiDescription Update data related to glomps with a specific ID (only accessible by database moderators). + * @apiName UpdateGlompData + * @apiGroup Glomp + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Glomp')) + /** + * @api {delete} v4/glomp/:id Delete Glomp Data + * @apiDescription Delete data related to glomp with a specific ID (only accessible by admins). + * @apiName DeleteGlompData + * @apiGroup Glomp + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Glomp')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/happy.js b/src/routes/v4/interactions/happy.js new file mode 100644 index 0000000..c2e8522 --- /dev/null +++ b/src/routes/v4/interactions/happy.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomHappy from '../../../controllers/v4/interactions/happy.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/happy Get a Random Happy + * @apiDescription Retrieve a random happy. + * @apiName GetRandomHappy + * @apiGroup Happy + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomHappy) + /** + * @api {post} v4/happy Increment Happy Data + * @apiDescription Increment data related to happys (only accessible by database moderators). + * @apiName IncrementHappyData + * @apiGroup Happy + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Happy')); + +router + .route('/:id') + /** + * @api {patch} v4/happy/:id Update Happy Data + * @apiDescription Update data related to happys with a specific ID (only accessible by database moderators). + * @apiName UpdateHappyData + * @apiGroup Happy + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Happy')) + /** + * @api {delete} v4/happy/:id Delete Happy Data + * @apiDescription Delete data related to happy with a specific ID (only accessible by admins). + * @apiName DeleteHappyData + * @apiGroup Happy + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Happy')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/hi.js b/src/routes/v4/interactions/hi.js new file mode 100644 index 0000000..6c2681c --- /dev/null +++ b/src/routes/v4/interactions/hi.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomHi from '../../../controllers/v4/interactions/hi.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/hi Get a Random Hi + * @apiDescription Retrieve a random hi. + * @apiName GetRandomHi + * @apiGroup Hi + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomHi) + /** + * @api {post} v4/hi Increment Hi Data + * @apiDescription Increment data related to his (only accessible by database moderators). + * @apiName IncrementHiData + * @apiGroup Hi + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Hi')); + +router + .route('/:id') + /** + * @api {patch} v4/hi/:id Update Hi Data + * @apiDescription Update data related to his with a specific ID (only accessible by database moderators). + * @apiName UpdateHiData + * @apiGroup Hi + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Hi')) + /** + * @api {delete} v4/hi/:id Delete Hi Data + * @apiDescription Delete data related to hi with a specific ID (only accessible by admins). + * @apiName DeleteHiData + * @apiGroup Hi + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Hi')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/highfive.js b/src/routes/v4/interactions/highfive.js new file mode 100644 index 0000000..b433f54 --- /dev/null +++ b/src/routes/v4/interactions/highfive.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomHighfive from '../../../controllers/v4/interactions/highfive.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/highfive Get a Random Highfive + * @apiDescription Retrieve a random highfive. + * @apiName GetRandomHighfive + * @apiGroup Highfive + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomHighfive) + /** + * @api {post} v4/highfive Increment Highfive Data + * @apiDescription Increment data related to highfives (only accessible by database moderators). + * @apiName IncrementHighfiveData + * @apiGroup Highfive + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Highfive')); + +router + .route('/:id') + /** + * @api {patch} v4/highfive/:id Update Highfive Data + * @apiDescription Update data related to highfives with a specific ID (only accessible by database moderators). + * @apiName UpdateHighfiveData + * @apiGroup Highfive + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Highfive')) + /** + * @api {delete} v4/highfive/:id Delete Highfive Data + * @apiDescription Delete data related to highfive with a specific ID (only accessible by admins). + * @apiName DeleteHighfiveData + * @apiGroup Highfive + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Highfive')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/hold.js b/src/routes/v4/interactions/hold.js new file mode 100644 index 0000000..7474337 --- /dev/null +++ b/src/routes/v4/interactions/hold.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomHold from '../../../controllers/v4/interactions/hold.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/hold Get a Random Hold + * @apiDescription Retrieve a random hold. + * @apiName GetRandomHold + * @apiGroup Hold + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomHold) + /** + * @api {post} v4/hold Increment Hold Data + * @apiDescription Increment data related to holds (only accessible by database moderators). + * @apiName IncrementHoldData + * @apiGroup Hold + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Hold')); + +router + .route('/:id') + /** + * @api {patch} v4/hold/:id Update Hold Data + * @apiDescription Update data related to holds with a specific ID (only accessible by database moderators). + * @apiName UpdateHoldData + * @apiGroup Hold + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Hold')) + /** + * @api {delete} v4/hold/:id Delete Hold Data + * @apiDescription Delete data related to hold with a specific ID (only accessible by admins). + * @apiName DeleteHoldData + * @apiGroup Hold + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Hold')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/hug.js b/src/routes/v4/interactions/hug.js new file mode 100644 index 0000000..1adf44c --- /dev/null +++ b/src/routes/v4/interactions/hug.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomHug from '../../../controllers/v4/interactions/hug.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/hug Get a Random Hug + * @apiDescription Retrieve a random hug. + * @apiName GetRandomHug + * @apiGroup Hug + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomHug) + /** + * @api {post} v4/hug Increment Hug Data + * @apiDescription Increment data related to hugs (only accessible by database moderators). + * @apiName IncrementHugData + * @apiGroup Hug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Hug')); + +router + .route('/:id') + /** + * @api {patch} v4/hug/:id Update Hug Data + * @apiDescription Update data related to hugs with a specific ID (only accessible by database moderators). + * @apiName UpdateHugData + * @apiGroup Hug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Hug')) + /** + * @api {delete} v4/hug/:id Delete Hug Data + * @apiDescription Delete data related to hug with a specific ID (only accessible by admins). + * @apiName DeleteHugData + * @apiGroup Hug + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Hug')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/kick.js b/src/routes/v4/interactions/kick.js new file mode 100644 index 0000000..790cd2f --- /dev/null +++ b/src/routes/v4/interactions/kick.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomKick from '../../../controllers/v4/interactions/kick.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/kick Get a Random Kick + * @apiDescription Retrieve a random kick. + * @apiName GetRandomKick + * @apiGroup Kick + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomKick) + /** + * @api {post} v4/kick Increment Kick Data + * @apiDescription Increment data related to kicks (only accessible by database moderators). + * @apiName IncrementKickData + * @apiGroup Kick + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Kick')); + +router + .route('/:id') + /** + * @api {patch} v4/kick/:id Update Kick Data + * @apiDescription Update data related to kicks with a specific ID (only accessible by database moderators). + * @apiName UpdateKickData + * @apiGroup Kick + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Kick')) + /** + * @api {delete} v4/kick/:id Delete Kick Data + * @apiDescription Delete data related to kick with a specific ID (only accessible by admins). + * @apiName DeleteKickData + * @apiGroup Kick + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Kick')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/kill.js b/src/routes/v4/interactions/kill.js new file mode 100644 index 0000000..99c6e79 --- /dev/null +++ b/src/routes/v4/interactions/kill.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomKill from '../../../controllers/v4/interactions/kill.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/kill Get a Random Kill + * @apiDescription Retrieve a random kill. + * @apiName GetRandomKill + * @apiGroup Kill + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomKill) + /** + * @api {post} v4/kill Increment Kill Data + * @apiDescription Increment data related to kills (only accessible by database moderators). + * @apiName IncrementKillData + * @apiGroup Kill + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Kill')); + +router + .route('/:id') + /** + * @api {patch} v4/kill/:id Update Kill Data + * @apiDescription Update data related to kills with a specific ID (only accessible by database moderators). + * @apiName UpdateKillData + * @apiGroup Kill + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Kill')) + /** + * @api {delete} v4/kill/:id Delete Kill Data + * @apiDescription Delete data related to kill with a specific ID (only accessible by admins). + * @apiName DeleteKillData + * @apiGroup Kill + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Kill')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/kiss.js b/src/routes/v4/interactions/kiss.js new file mode 100644 index 0000000..ed25f76 --- /dev/null +++ b/src/routes/v4/interactions/kiss.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomKiss from '../../../controllers/v4/interactions/kiss.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/kiss Get a Random Kiss + * @apiDescription Retrieve a random kiss. + * @apiName GetRandomKiss + * @apiGroup Kiss + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomKiss) + /** + * @api {post} v4/kiss Increment Kiss Data + * @apiDescription Increment data related to kisss (only accessible by database moderators). + * @apiName IncrementKissData + * @apiGroup Kiss + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Kissu')); + +router + .route('/:id') + /** + * @api {patch} v4/kiss/:id Update Kiss Data + * @apiDescription Update data related to kisss with a specific ID (only accessible by database moderators). + * @apiName UpdateKissData + * @apiGroup Kiss + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Kissu')) + /** + * @api {delete} v4/kiss/:id Delete Kiss Data + * @apiDescription Delete data related to kiss with a specific ID (only accessible by admins). + * @apiName DeleteKissData + * @apiGroup Kiss + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Kissu')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/laugh.js b/src/routes/v4/interactions/laugh.js new file mode 100644 index 0000000..bc26e68 --- /dev/null +++ b/src/routes/v4/interactions/laugh.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomLaugh from '../../../controllers/v4/interactions/laugh.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/laugh Get a Random Laugh + * @apiDescription Retrieve a random laugh. + * @apiName GetRandomLaugh + * @apiGroup Laugh + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomLaugh) + /** + * @api {post} v4/laugh Increment Laugh Data + * @apiDescription Increment data related to laughs (only accessible by database moderators). + * @apiName IncrementLaughData + * @apiGroup Laugh + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Laugh')); + +router + .route('/:id') + /** + * @api {patch} v4/laugh/:id Update Laugh Data + * @apiDescription Update data related to laughs with a specific ID (only accessible by database moderators). + * @apiName UpdateLaughData + * @apiGroup Laugh + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Laugh')) + /** + * @api {delete} v4/laugh/:id Delete Laugh Data + * @apiDescription Delete data related to laugh with a specific ID (only accessible by admins). + * @apiName DeleteLaughData + * @apiGroup Laugh + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Laugh')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/lick.js b/src/routes/v4/interactions/lick.js new file mode 100644 index 0000000..8466d25 --- /dev/null +++ b/src/routes/v4/interactions/lick.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomLick from '../../../controllers/v4/interactions/lick.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/lick Get a Random Lick + * @apiDescription Retrieve a random lick. + * @apiName GetRandomLick + * @apiGroup Lick + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomLick) + /** + * @api {post} v4/lick Increment Lick Data + * @apiDescription Increment data related to licks (only accessible by database moderators). + * @apiName IncrementLickData + * @apiGroup Lick + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Lick')); + +router + .route('/:id') + /** + * @api {patch} v4/lick/:id Update Lick Data + * @apiDescription Update data related to licks with a specific ID (only accessible by database moderators). + * @apiName UpdateLickData + * @apiGroup Lick + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Lick')) + /** + * @api {delete} v4/lick/:id Delete Lick Data + * @apiDescription Delete data related to lick with a specific ID (only accessible by admins). + * @apiName DeleteLickData + * @apiGroup Lick + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Lick')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/love.js b/src/routes/v4/interactions/love.js new file mode 100644 index 0000000..c250159 --- /dev/null +++ b/src/routes/v4/interactions/love.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomLove from '../../../controllers/v4/interactions/love.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/love Get a Random Love + * @apiDescription Retrieve a random love. + * @apiName GetRandomLove + * @apiGroup Love + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomLove) + /** + * @api {post} v4/love Increment Love Data + * @apiDescription Increment data related to loves (only accessible by database moderators). + * @apiName IncrementLoveData + * @apiGroup Love + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Love')); + +router + .route('/:id') + /** + * @api {patch} v4/love/:id Update Love Data + * @apiDescription Update data related to loves with a specific ID (only accessible by database moderators). + * @apiName UpdateLoveData + * @apiGroup Love + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Love')) + /** + * @api {delete} v4/love/:id Delete Love Data + * @apiDescription Delete data related to love with a specific ID (only accessible by admins). + * @apiName DeleteLoveData + * @apiGroup Love + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Love')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/lurk.js b/src/routes/v4/interactions/lurk.js new file mode 100644 index 0000000..826d28b --- /dev/null +++ b/src/routes/v4/interactions/lurk.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomLurk from '../../../controllers/v4/interactions/lurk.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/lurk Get a Random Lurk + * @apiDescription Retrieve a random lurk. + * @apiName GetRandomLurk + * @apiGroup Lurk + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomLurk) + /** + * @api {post} v4/lurk Increment Lurk Data + * @apiDescription Increment data related to lurks (only accessible by database moderators). + * @apiName IncrementLurkData + * @apiGroup Lurk + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Lurk')); + +router + .route('/:id') + /** + * @api {patch} v4/lurk/:id Update Lurk Data + * @apiDescription Update data related to lurks with a specific ID (only accessible by database moderators). + * @apiName UpdateLurkData + * @apiGroup Lurk + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Lurk')) + /** + * @api {delete} v4/lurk/:id Delete Lurk Data + * @apiDescription Delete data related to lurk with a specific ID (only accessible by admins). + * @apiName DeleteLurkData + * @apiGroup Lurk + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Lurk')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/midfing.js b/src/routes/v4/interactions/midfing.js new file mode 100644 index 0000000..a97aebe --- /dev/null +++ b/src/routes/v4/interactions/midfing.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomMidfing from '../../../controllers/v4/interactions/midfing.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/midfing Get a Random Midfing + * @apiDescription Retrieve a random midfing. + * @apiName GetRandomMidfing + * @apiGroup Midfing + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomMidfing) + /** + * @api {post} v4/midfing Increment Midfing Data + * @apiDescription Increment data related to midfings (only accessible by database moderators). + * @apiName IncrementMidfingData + * @apiGroup Midfing + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Midfing')); + +router + .route('/:id') + /** + * @api {patch} v4/midfing/:id Update Midfing Data + * @apiDescription Update data related to midfings with a specific ID (only accessible by database moderators). + * @apiName UpdateMidfingData + * @apiGroup Midfing + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Midfing')) + /** + * @api {delete} v4/midfing/:id Delete Midfing Data + * @apiDescription Delete data related to midfing with a specific ID (only accessible by admins). + * @apiName DeleteMidfingData + * @apiGroup Midfing + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Midfing')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/nervous.js b/src/routes/v4/interactions/nervous.js new file mode 100644 index 0000000..a6e283b --- /dev/null +++ b/src/routes/v4/interactions/nervous.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomNervous from '../../../controllers/v4/interactions/nervous.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/nervous Get a Random Nervous + * @apiDescription Retrieve a random nervous. + * @apiName GetRandomNervous + * @apiGroup Nervous + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomNervous) + /** + * @api {post} v4/nervous Increment Nervous Data + * @apiDescription Increment data related to nervouss (only accessible by database moderators). + * @apiName IncrementNervousData + * @apiGroup Nervous + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Nervous')); + +router + .route('/:id') + /** + * @api {patch} v4/nervous/:id Update Nervous Data + * @apiDescription Update data related to nervouss with a specific ID (only accessible by database moderators). + * @apiName UpdateNervousData + * @apiGroup Nervous + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Nervous')) + /** + * @api {delete} v4/nervous/:id Delete Nervous Data + * @apiDescription Delete data related to nervous with a specific ID (only accessible by admins). + * @apiName DeleteNervousData + * @apiGroup Nervous + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Nervous')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/nom.js b/src/routes/v4/interactions/nom.js new file mode 100644 index 0000000..3cdd7b0 --- /dev/null +++ b/src/routes/v4/interactions/nom.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomNom from '../../../controllers/v4/interactions/nom.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/nom Get a Random Nom + * @apiDescription Retrieve a random nom. + * @apiName GetRandomNom + * @apiGroup Nom + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomNom) + /** + * @api {post} v4/nom Increment Nom Data + * @apiDescription Increment data related to noms (only accessible by database moderators). + * @apiName IncrementNomData + * @apiGroup Nom + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Nom')); + +router + .route('/:id') + /** + * @api {patch} v4/nom/:id Update Nom Data + * @apiDescription Update data related to noms with a specific ID (only accessible by database moderators). + * @apiName UpdateNomData + * @apiGroup Nom + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Nom')) + /** + * @api {delete} v4/nom/:id Delete Nom Data + * @apiDescription Delete data related to nom with a specific ID (only accessible by admins). + * @apiName DeleteNomData + * @apiGroup Nom + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Nom')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/nope.js b/src/routes/v4/interactions/nope.js new file mode 100644 index 0000000..9d6fd20 --- /dev/null +++ b/src/routes/v4/interactions/nope.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomNope from '../../../controllers/v4/interactions/nope.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/nope Get a Random Nope + * @apiDescription Retrieve a random nope. + * @apiName GetRandomNope + * @apiGroup Nope + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomNope) + /** + * @api {post} v4/nope Increment Nope Data + * @apiDescription Increment data related to nopes (only accessible by database moderators). + * @apiName IncrementNopeData + * @apiGroup Nope + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Nope')); + +router + .route('/:id') + /** + * @api {patch} v4/nope/:id Update Nope Data + * @apiDescription Update data related to nopes with a specific ID (only accessible by database moderators). + * @apiName UpdateNopeData + * @apiGroup Nope + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Nope')) + /** + * @api {delete} v4/nope/:id Delete Nope Data + * @apiDescription Delete data related to nope with a specific ID (only accessible by admins). + * @apiName DeleteNopeData + * @apiGroup Nope + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Nope')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/nuzzle.js b/src/routes/v4/interactions/nuzzle.js new file mode 100644 index 0000000..8c8dcd4 --- /dev/null +++ b/src/routes/v4/interactions/nuzzle.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomNuzzle from '../../../controllers/v4/interactions/nuzzle.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/nuzzle Get a Random Nuzzle + * @apiDescription Retrieve a random nuzzle. + * @apiName GetRandomNuzzle + * @apiGroup Nuzzle + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomNuzzle) + /** + * @api {post} v4/nuzzle Increment Nuzzle Data + * @apiDescription Increment data related to nuzzles (only accessible by database moderators). + * @apiName IncrementNuzzleData + * @apiGroup Nuzzle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Nuzzle')); + +router + .route('/:id') + /** + * @api {patch} v4/nuzzle/:id Update Nuzzle Data + * @apiDescription Update data related to nuzzles with a specific ID (only accessible by database moderators). + * @apiName UpdateNuzzleData + * @apiGroup Nuzzle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Nuzzle')) + /** + * @api {delete} v4/nuzzle/:id Delete Nuzzle Data + * @apiDescription Delete data related to nuzzle with a specific ID (only accessible by admins). + * @apiName DeleteNuzzleData + * @apiGroup Nuzzle + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Nuzzle')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/panic.js b/src/routes/v4/interactions/panic.js new file mode 100644 index 0000000..6cca173 --- /dev/null +++ b/src/routes/v4/interactions/panic.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPanic from '../../../controllers/v4/interactions/panic.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/panic Get a Random Panic + * @apiDescription Retrieve a random panic. + * @apiName GetRandomPanic + * @apiGroup Panic + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPanic) + /** + * @api {post} v4/panic Increment Panic Data + * @apiDescription Increment data related to panics (only accessible by database moderators). + * @apiName IncrementPanicData + * @apiGroup Panic + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Panic')); + +router + .route('/:id') + /** + * @api {patch} v4/panic/:id Update Panic Data + * @apiDescription Update data related to panics with a specific ID (only accessible by database moderators). + * @apiName UpdatePanicData + * @apiGroup Panic + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Panic')) + /** + * @api {delete} v4/panic/:id Delete Panic Data + * @apiDescription Delete data related to panic with a specific ID (only accessible by admins). + * @apiName DeletePanicData + * @apiGroup Panic + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Panic')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/pat.js b/src/routes/v4/interactions/pat.js new file mode 100644 index 0000000..8b9d6a0 --- /dev/null +++ b/src/routes/v4/interactions/pat.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPat from '../../../controllers/v4/interactions/pat.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/pat Get a Random Pat + * @apiDescription Retrieve a random pat. + * @apiName GetRandomPat + * @apiGroup Pat + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPat) + /** + * @api {post} v4/pat Increment Pat Data + * @apiDescription Increment data related to pats (only accessible by database moderators). + * @apiName IncrementPatData + * @apiGroup Pat + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Pat')); + +router + .route('/:id') + /** + * @api {patch} v4/pat/:id Update Pat Data + * @apiDescription Update data related to pats with a specific ID (only accessible by database moderators). + * @apiName UpdatePatData + * @apiGroup Pat + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Pat')) + /** + * @api {delete} v4/pat/:id Delete Pat Data + * @apiDescription Delete data related to pat with a specific ID (only accessible by admins). + * @apiName DeletePatData + * @apiGroup Pat + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Pat')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/peck.js b/src/routes/v4/interactions/peck.js new file mode 100644 index 0000000..34d8cf3 --- /dev/null +++ b/src/routes/v4/interactions/peck.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPeck from '../../../controllers/v4/interactions/peck.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/peck Get a Random Peck + * @apiDescription Retrieve a random peck. + * @apiName GetRandomPeck + * @apiGroup Peck + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPeck) + /** + * @api {post} v4/peck Increment Peck Data + * @apiDescription Increment data related to pecks (only accessible by database moderators). + * @apiName IncrementPeckData + * @apiGroup Peck + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Peck')); + +router + .route('/:id') + /** + * @api {patch} v4/peck/:id Update Peck Data + * @apiDescription Update data related to pecks with a specific ID (only accessible by database moderators). + * @apiName UpdatePeckData + * @apiGroup Peck + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Peck')) + /** + * @api {delete} v4/peck/:id Delete Peck Data + * @apiDescription Delete data related to peck with a specific ID (only accessible by admins). + * @apiName DeletePeckData + * @apiGroup Peck + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Peck')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/poke.js b/src/routes/v4/interactions/poke.js new file mode 100644 index 0000000..f96f487 --- /dev/null +++ b/src/routes/v4/interactions/poke.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPoke from '../../../controllers/v4/interactions/poke.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/poke Get a Random Poke + * @apiDescription Retrieve a random poke. + * @apiName GetRandomPoke + * @apiGroup Poke + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPoke) + /** + * @api {post} v4/poke Increment Poke Data + * @apiDescription Increment data related to pokes (only accessible by database moderators). + * @apiName IncrementPokeData + * @apiGroup Poke + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Poke')); + +router + .route('/:id') + /** + * @api {patch} v4/poke/:id Update Poke Data + * @apiDescription Update data related to pokes with a specific ID (only accessible by database moderators). + * @apiName UpdatePokeData + * @apiGroup Poke + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Poke')) + /** + * @api {delete} v4/poke/:id Delete Poke Data + * @apiDescription Delete data related to poke with a specific ID (only accessible by admins). + * @apiName DeletePokeData + * @apiGroup Poke + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Poke')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/pout.js b/src/routes/v4/interactions/pout.js new file mode 100644 index 0000000..8b05de1 --- /dev/null +++ b/src/routes/v4/interactions/pout.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPout from '../../../controllers/v4/interactions/pout.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/pout Get a Random Pout + * @apiDescription Retrieve a random pout. + * @apiName GetRandomPout + * @apiGroup Pout + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPout) + /** + * @api {post} v4/pout Increment Pout Data + * @apiDescription Increment data related to pouts (only accessible by database moderators). + * @apiName IncrementPoutData + * @apiGroup Pout + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Pout')); + +router + .route('/:id') + /** + * @api {patch} v4/pout/:id Update Pout Data + * @apiDescription Update data related to pouts with a specific ID (only accessible by database moderators). + * @apiName UpdatePoutData + * @apiGroup Pout + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Pout')) + /** + * @api {delete} v4/pout/:id Delete Pout Data + * @apiDescription Delete data related to pout with a specific ID (only accessible by admins). + * @apiName DeletePoutData + * @apiGroup Pout + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Pout')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/punch.js b/src/routes/v4/interactions/punch.js new file mode 100644 index 0000000..23e0f5d --- /dev/null +++ b/src/routes/v4/interactions/punch.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomPunch from '../../../controllers/v4/interactions/punch.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/punch Get a Random Punch + * @apiDescription Retrieve a random punch. + * @apiName GetRandomPunch + * @apiGroup Punch + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomPunch) + /** + * @api {post} v4/punch Increment Punch Data + * @apiDescription Increment data related to punchs (only accessible by database moderators). + * @apiName IncrementPunchData + * @apiGroup Punch + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Punch')); + +router + .route('/:id') + /** + * @api {patch} v4/punch/:id Update Punch Data + * @apiDescription Update data related to punchs with a specific ID (only accessible by database moderators). + * @apiName UpdatePunchData + * @apiGroup Punch + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Punch')) + /** + * @api {delete} v4/punch/:id Delete Punch Data + * @apiDescription Delete data related to punch with a specific ID (only accessible by admins). + * @apiName DeletePunchData + * @apiGroup Punch + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Punch')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/run.js b/src/routes/v4/interactions/run.js new file mode 100644 index 0000000..f2bc8c6 --- /dev/null +++ b/src/routes/v4/interactions/run.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomRun from '../../../controllers/v4/interactions/run.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/run Get a Random Run + * @apiDescription Retrieve a random run. + * @apiName GetRandomRun + * @apiGroup Run + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomRun) + /** + * @api {post} v4/run Increment Run Data + * @apiDescription Increment data related to runs (only accessible by database moderators). + * @apiName IncrementRunData + * @apiGroup Run + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Run')); + +router + .route('/:id') + /** + * @api {patch} v4/run/:id Update Run Data + * @apiDescription Update data related to runs with a specific ID (only accessible by database moderators). + * @apiName UpdateRunData + * @apiGroup Run + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Run')) + /** + * @api {delete} v4/run/:id Delete Run Data + * @apiDescription Delete data related to run with a specific ID (only accessible by admins). + * @apiName DeleteRunData + * @apiGroup Run + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Run')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/sad.js b/src/routes/v4/interactions/sad.js new file mode 100644 index 0000000..e532388 --- /dev/null +++ b/src/routes/v4/interactions/sad.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSad from '../../../controllers/v4/interactions/sad.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/sad Get a Random Sad + * @apiDescription Retrieve a random sad. + * @apiName GetRandomSad + * @apiGroup Sad + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSad) + /** + * @api {post} v4/sad Increment Sad Data + * @apiDescription Increment data related to sads (only accessible by database moderators). + * @apiName IncrementSadData + * @apiGroup Sad + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Sad')); + +router + .route('/:id') + /** + * @api {patch} v4/sad/:id Update Sad Data + * @apiDescription Update data related to sads with a specific ID (only accessible by database moderators). + * @apiName UpdateSadData + * @apiGroup Sad + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Sad')) + /** + * @api {delete} v4/sad/:id Delete Sad Data + * @apiDescription Delete data related to sad with a specific ID (only accessible by admins). + * @apiName DeleteSadData + * @apiGroup Sad + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Sad')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/shoot.js b/src/routes/v4/interactions/shoot.js new file mode 100644 index 0000000..c388cea --- /dev/null +++ b/src/routes/v4/interactions/shoot.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomShoot from '../../../controllers/v4/interactions/shoot.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/shoot Get a Random Shoot + * @apiDescription Retrieve a random shoot. + * @apiName GetRandomShoot + * @apiGroup Shoot + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomShoot) + /** + * @api {post} v4/shoot Increment Shoot Data + * @apiDescription Increment data related to shoots (only accessible by database moderators). + * @apiName IncrementShootData + * @apiGroup Shoot + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Shoot')); + +router + .route('/:id') + /** + * @api {patch} v4/shoot/:id Update Shoot Data + * @apiDescription Update data related to shoots with a specific ID (only accessible by database moderators). + * @apiName UpdateShootData + * @apiGroup Shoot + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Shoot')) + /** + * @api {delete} v4/shoot/:id Delete Shoot Data + * @apiDescription Delete data related to shoot with a specific ID (only accessible by admins). + * @apiName DeleteShootData + * @apiGroup Shoot + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Shoot')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/shrug.js b/src/routes/v4/interactions/shrug.js new file mode 100644 index 0000000..c2ffc3a --- /dev/null +++ b/src/routes/v4/interactions/shrug.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomShrug from '../../../controllers/v4/interactions/shrug.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/shrug Get a Random Shrug + * @apiDescription Retrieve a random shrug. + * @apiName GetRandomShrug + * @apiGroup Shrug + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomShrug) + /** + * @api {post} v4/shrug Increment Shrug Data + * @apiDescription Increment data related to shrugs (only accessible by database moderators). + * @apiName IncrementShrugData + * @apiGroup Shrug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Shrug')); + +router + .route('/:id') + /** + * @api {patch} v4/shrug/:id Update Shrug Data + * @apiDescription Update data related to shrugs with a specific ID (only accessible by database moderators). + * @apiName UpdateShrugData + * @apiGroup Shrug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Shrug')) + /** + * @api {delete} v4/shrug/:id Delete Shrug Data + * @apiDescription Delete data related to shrug with a specific ID (only accessible by admins). + * @apiName DeleteShrugData + * @apiGroup Shrug + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Shrug')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/sip.js b/src/routes/v4/interactions/sip.js new file mode 100644 index 0000000..8153bed --- /dev/null +++ b/src/routes/v4/interactions/sip.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSip from '../../../controllers/v4/interactions/sip.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/sip Get a Random Sip + * @apiDescription Retrieve a random sip. + * @apiName GetRandomSip + * @apiGroup Sip + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSip) + /** + * @api {post} v4/sip Increment Sip Data + * @apiDescription Increment data related to sips (only accessible by database moderators). + * @apiName IncrementSipData + * @apiGroup Sip + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Sip')); + +router + .route('/:id') + /** + * @api {patch} v4/sip/:id Update Sip Data + * @apiDescription Update data related to sips with a specific ID (only accessible by database moderators). + * @apiName UpdateSipData + * @apiGroup Sip + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Sip')) + /** + * @api {delete} v4/sip/:id Delete Sip Data + * @apiDescription Delete data related to sip with a specific ID (only accessible by admins). + * @apiName DeleteSipData + * @apiGroup Sip + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Sip')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/slap.js b/src/routes/v4/interactions/slap.js new file mode 100644 index 0000000..223d689 --- /dev/null +++ b/src/routes/v4/interactions/slap.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSlap from '../../../controllers/v4/interactions/slap.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/slap Get a Random Slap + * @apiDescription Retrieve a random slap. + * @apiName GetRandomSlap + * @apiGroup Slap + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSlap) + /** + * @api {post} v4/slap Increment Slap Data + * @apiDescription Increment data related to slaps (only accessible by database moderators). + * @apiName IncrementSlapData + * @apiGroup Slap + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Slap')); + +router + .route('/:id') + /** + * @api {patch} v4/slap/:id Update Slap Data + * @apiDescription Update data related to slaps with a specific ID (only accessible by database moderators). + * @apiName UpdateSlapData + * @apiGroup Slap + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Slap')) + /** + * @api {delete} v4/slap/:id Delete Slap Data + * @apiDescription Delete data related to slap with a specific ID (only accessible by admins). + * @apiName DeleteSlapData + * @apiGroup Slap + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Slap')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/sleepy.js b/src/routes/v4/interactions/sleepy.js new file mode 100644 index 0000000..9404c7c --- /dev/null +++ b/src/routes/v4/interactions/sleepy.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSleepy from '../../../controllers/v4/interactions/sleepy.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/sleepy Get a Random Sleepy + * @apiDescription Retrieve a random sleepy. + * @apiName GetRandomSleepy + * @apiGroup Sleepy + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSleepy) + /** + * @api {post} v4/sleepy Increment Sleepy Data + * @apiDescription Increment data related to sleepys (only accessible by database moderators). + * @apiName IncrementSleepyData + * @apiGroup Sleepy + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Sleepy')); + +router + .route('/:id') + /** + * @api {patch} v4/sleepy/:id Update Sleepy Data + * @apiDescription Update data related to sleepys with a specific ID (only accessible by database moderators). + * @apiName UpdateSleepyData + * @apiGroup Sleepy + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Sleepy')) + /** + * @api {delete} v4/sleepy/:id Delete Sleepy Data + * @apiDescription Delete data related to sleepy with a specific ID (only accessible by admins). + * @apiName DeleteSleepyData + * @apiGroup Sleepy + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Sleepy')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/smile.js b/src/routes/v4/interactions/smile.js new file mode 100644 index 0000000..ab3af33 --- /dev/null +++ b/src/routes/v4/interactions/smile.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSmile from '../../../controllers/v4/interactions/smile.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/smile Get a Random Smile + * @apiDescription Retrieve a random smile. + * @apiName GetRandomSmile + * @apiGroup Smile + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSmile) + /** + * @api {post} v4/smile Increment Smile Data + * @apiDescription Increment data related to smiles (only accessible by database moderators). + * @apiName IncrementSmileData + * @apiGroup Smile + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Smile')); + +router + .route('/:id') + /** + * @api {patch} v4/smile/:id Update Smile Data + * @apiDescription Update data related to smiles with a specific ID (only accessible by database moderators). + * @apiName UpdateSmileData + * @apiGroup Smile + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Smile')) + /** + * @api {delete} v4/smile/:id Delete Smile Data + * @apiDescription Delete data related to smile with a specific ID (only accessible by admins). + * @apiName DeleteSmileData + * @apiGroup Smile + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Smile')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/smug.js b/src/routes/v4/interactions/smug.js new file mode 100644 index 0000000..343ef95 --- /dev/null +++ b/src/routes/v4/interactions/smug.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSmug from '../../../controllers/v4/interactions/smug.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/smug Get a Random Smug + * @apiDescription Retrieve a random smug. + * @apiName GetRandomSmug + * @apiGroup Smug + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSmug) + /** + * @api {post} v4/smug Increment Smug Data + * @apiDescription Increment data related to smugs (only accessible by database moderators). + * @apiName IncrementSmugData + * @apiGroup Smug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Smug')); + +router + .route('/:id') + /** + * @api {patch} v4/smug/:id Update Smug Data + * @apiDescription Update data related to smugs with a specific ID (only accessible by database moderators). + * @apiName UpdateSmugData + * @apiGroup Smug + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Smug')) + /** + * @api {delete} v4/smug/:id Delete Smug Data + * @apiDescription Delete data related to smug with a specific ID (only accessible by admins). + * @apiName DeleteSmugData + * @apiGroup Smug + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Smug')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/stab.js b/src/routes/v4/interactions/stab.js new file mode 100644 index 0000000..5767990 --- /dev/null +++ b/src/routes/v4/interactions/stab.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomStab from '../../../controllers/v4/interactions/stab.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/stab Get a Random Stab + * @apiDescription Retrieve a random stab. + * @apiName GetRandomStab + * @apiGroup Stab + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomStab) + /** + * @api {post} v4/stab Increment Stab Data + * @apiDescription Increment data related to stabs (only accessible by database moderators). + * @apiName IncrementStabData + * @apiGroup Stab + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Stab')); + +router + .route('/:id') + /** + * @api {patch} v4/stab/:id Update Stab Data + * @apiDescription Update data related to stabs with a specific ID (only accessible by database moderators). + * @apiName UpdateStabData + * @apiGroup Stab + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Stab')) + /** + * @api {delete} v4/stab/:id Delete Stab Data + * @apiDescription Delete data related to stab with a specific ID (only accessible by admins). + * @apiName DeleteStabData + * @apiGroup Stab + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Stab')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/stare.js b/src/routes/v4/interactions/stare.js new file mode 100644 index 0000000..bae4c00 --- /dev/null +++ b/src/routes/v4/interactions/stare.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomStare from '../../../controllers/v4/interactions/stare.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/stare Get a Random Stare + * @apiDescription Retrieve a random stare. + * @apiName GetRandomStare + * @apiGroup Stare + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomStare) + /** + * @api {post} v4/stare Increment Stare Data + * @apiDescription Increment data related to stares (only accessible by database moderators). + * @apiName IncrementStareData + * @apiGroup Stare + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Stare')); + +router + .route('/:id') + /** + * @api {patch} v4/stare/:id Update Stare Data + * @apiDescription Update data related to stares with a specific ID (only accessible by database moderators). + * @apiName UpdateStareData + * @apiGroup Stare + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Stare')) + /** + * @api {delete} v4/stare/:id Delete Stare Data + * @apiDescription Delete data related to stare with a specific ID (only accessible by admins). + * @apiName DeleteStareData + * @apiGroup Stare + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Stare')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/suicide.js b/src/routes/v4/interactions/suicide.js new file mode 100644 index 0000000..fd5a81b --- /dev/null +++ b/src/routes/v4/interactions/suicide.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomSuicide from '../../../controllers/v4/interactions/suicide.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/suicide Get a Random Suicide + * @apiDescription Retrieve a random suicide. + * @apiName GetRandomSuicide + * @apiGroup Suicide + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomSuicide) + /** + * @api {post} v4/suicide Increment Suicide Data + * @apiDescription Increment data related to suicides (only accessible by database moderators). + * @apiName IncrementSuicideData + * @apiGroup Suicide + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Suicide')); + +router + .route('/:id') + /** + * @api {patch} v4/suicide/:id Update Suicide Data + * @apiDescription Update data related to suicides with a specific ID (only accessible by database moderators). + * @apiName UpdateSuicideData + * @apiGroup Suicide + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Suicide')) + /** + * @api {delete} v4/suicide/:id Delete Suicide Data + * @apiDescription Delete data related to suicide with a specific ID (only accessible by admins). + * @apiName DeleteSuicideData + * @apiGroup Suicide + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Suicide')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/tease.js b/src/routes/v4/interactions/tease.js new file mode 100644 index 0000000..861ae1c --- /dev/null +++ b/src/routes/v4/interactions/tease.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomTease from '../../../controllers/v4/interactions/tease.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/tease Get a Random Tease + * @apiDescription Retrieve a random tease. + * @apiName GetRandomTease + * @apiGroup Tease + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomTease) + /** + * @api {post} v4/tease Increment Tease Data + * @apiDescription Increment data related to teases (only accessible by database moderators). + * @apiName IncrementTeaseData + * @apiGroup Tease + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Tease')); + +router + .route('/:id') + /** + * @api {patch} v4/tease/:id Update Tease Data + * @apiDescription Update data related to teases with a specific ID (only accessible by database moderators). + * @apiName UpdateTeaseData + * @apiGroup Tease + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Tease')) + /** + * @api {delete} v4/tease/:id Delete Tease Data + * @apiDescription Delete data related to tease with a specific ID (only accessible by admins). + * @apiName DeleteTeaseData + * @apiGroup Tease + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Tease')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/think.js b/src/routes/v4/interactions/think.js new file mode 100644 index 0000000..40088b3 --- /dev/null +++ b/src/routes/v4/interactions/think.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomThink from '../../../controllers/v4/interactions/think.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/think Get a Random Think + * @apiDescription Retrieve a random think. + * @apiName GetRandomThink + * @apiGroup Think + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomThink) + /** + * @api {post} v4/think Increment Think Data + * @apiDescription Increment data related to thinks (only accessible by database moderators). + * @apiName IncrementThinkData + * @apiGroup Think + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Think')); + +router + .route('/:id') + /** + * @api {patch} v4/think/:id Update Think Data + * @apiDescription Update data related to thinks with a specific ID (only accessible by database moderators). + * @apiName UpdateThinkData + * @apiGroup Think + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Think')) + /** + * @api {delete} v4/think/:id Delete Think Data + * @apiDescription Delete data related to think with a specific ID (only accessible by admins). + * @apiName DeleteThinkData + * @apiGroup Think + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Think')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/thumbsup.js b/src/routes/v4/interactions/thumbsup.js new file mode 100644 index 0000000..0c25c75 --- /dev/null +++ b/src/routes/v4/interactions/thumbsup.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomThumbsup from '../../../controllers/v4/interactions/thumbsup.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/thumbsup Get a Random Thumbsup + * @apiDescription Retrieve a random thumbsup. + * @apiName GetRandomThumbsup + * @apiGroup Thumbsup + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomThumbsup) + /** + * @api {post} v4/thumbsup Increment Thumbsup Data + * @apiDescription Increment data related to thumbsups (only accessible by database moderators). + * @apiName IncrementThumbsupData + * @apiGroup Thumbsup + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Thumbsup')); + +router + .route('/:id') + /** + * @api {patch} v4/thumbsup/:id Update Thumbsup Data + * @apiDescription Update data related to thumbsups with a specific ID (only accessible by database moderators). + * @apiName UpdateThumbsupData + * @apiGroup Thumbsup + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Thumbsup')) + /** + * @api {delete} v4/thumbsup/:id Delete Thumbsup Data + * @apiDescription Delete data related to thumbsup with a specific ID (only accessible by admins). + * @apiName DeleteThumbsupData + * @apiGroup Thumbsup + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Thumbsup')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/tickle.js b/src/routes/v4/interactions/tickle.js new file mode 100644 index 0000000..576b67a --- /dev/null +++ b/src/routes/v4/interactions/tickle.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomTickle from '../../../controllers/v4/interactions/tickle.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/tickle Get a Random Tickle + * @apiDescription Retrieve a random tickle. + * @apiName GetRandomTickle + * @apiGroup Tickle + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomTickle) + /** + * @api {post} v4/tickle Increment Tickle Data + * @apiDescription Increment data related to tickles (only accessible by database moderators). + * @apiName IncrementTickleData + * @apiGroup Tickle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Tickle')); + +router + .route('/:id') + /** + * @api {patch} v4/tickle/:id Update Tickle Data + * @apiDescription Update data related to tickles with a specific ID (only accessible by database moderators). + * @apiName UpdateTickleData + * @apiGroup Tickle + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Tickle')) + /** + * @api {delete} v4/tickle/:id Delete Tickle Data + * @apiDescription Delete data related to tickle with a specific ID (only accessible by admins). + * @apiName DeleteTickleData + * @apiGroup Tickle + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Tickle')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/triggered.js b/src/routes/v4/interactions/triggered.js new file mode 100644 index 0000000..5825bd9 --- /dev/null +++ b/src/routes/v4/interactions/triggered.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomTriggered from '../../../controllers/v4/interactions/triggered.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/triggered Get a Random Triggered + * @apiDescription Retrieve a random triggered. + * @apiName GetRandomTriggered + * @apiGroup Triggered + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomTriggered) + /** + * @api {post} v4/triggered Increment Triggered Data + * @apiDescription Increment data related to triggereds (only accessible by database moderators). + * @apiName IncrementTriggeredData + * @apiGroup Triggered + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Triggered')); + +router + .route('/:id') + /** + * @api {patch} v4/triggered/:id Update Triggered Data + * @apiDescription Update data related to triggereds with a specific ID (only accessible by database moderators). + * @apiName UpdateTriggeredData + * @apiGroup Triggered + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Triggered')) + /** + * @api {delete} v4/triggered/:id Delete Triggered Data + * @apiDescription Delete data related to triggered with a specific ID (only accessible by admins). + * @apiName DeleteTriggeredData + * @apiGroup Triggered + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Triggered')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/wag.js b/src/routes/v4/interactions/wag.js new file mode 100644 index 0000000..92d38bc --- /dev/null +++ b/src/routes/v4/interactions/wag.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomWag from '../../../controllers/v4/interactions/wag.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/wag Get a Random Wag + * @apiDescription Retrieve a random wag. + * @apiName GetRandomWag + * @apiGroup Wag + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomWag) + /** + * @api {post} v4/wag Increment Wag Data + * @apiDescription Increment data related to wags (only accessible by database moderators). + * @apiName IncrementWagData + * @apiGroup Wag + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Wag')); + +router + .route('/:id') + /** + * @api {patch} v4/wag/:id Update Wag Data + * @apiDescription Update data related to wags with a specific ID (only accessible by database moderators). + * @apiName UpdateWagData + * @apiGroup Wag + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Wag')) + /** + * @api {delete} v4/wag/:id Delete Wag Data + * @apiDescription Delete data related to wag with a specific ID (only accessible by admins). + * @apiName DeleteWagData + * @apiGroup Wag + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Wag')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/wave.js b/src/routes/v4/interactions/wave.js new file mode 100644 index 0000000..a7a4f16 --- /dev/null +++ b/src/routes/v4/interactions/wave.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomWave from '../../../controllers/v4/interactions/wave.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/wave Get a Random Wave + * @apiDescription Retrieve a random wave. + * @apiName GetRandomWave + * @apiGroup Wave + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomWave) + /** + * @api {post} v4/wave Increment Wave Data + * @apiDescription Increment data related to waves (only accessible by database moderators). + * @apiName IncrementWaveData + * @apiGroup Wave + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Wave')); + +router + .route('/:id') + /** + * @api {patch} v4/wave/:id Update Wave Data + * @apiDescription Update data related to waves with a specific ID (only accessible by database moderators). + * @apiName UpdateWaveData + * @apiGroup Wave + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Wave')) + /** + * @api {delete} v4/wave/:id Delete Wave Data + * @apiDescription Delete data related to wave with a specific ID (only accessible by admins). + * @apiName DeleteWaveData + * @apiGroup Wave + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Wave')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/wink.js b/src/routes/v4/interactions/wink.js new file mode 100644 index 0000000..d5c19b1 --- /dev/null +++ b/src/routes/v4/interactions/wink.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomWink from '../../../controllers/v4/interactions/wink.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/wink Get a Random Wink + * @apiDescription Retrieve a random wink. + * @apiName GetRandomWink + * @apiGroup Wink + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomWink) + /** + * @api {post} v4/wink Increment Wink Data + * @apiDescription Increment data related to winks (only accessible by database moderators). + * @apiName IncrementWinkData + * @apiGroup Wink + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Wink')); + +router + .route('/:id') + /** + * @api {patch} v4/wink/:id Update Wink Data + * @apiDescription Update data related to winks with a specific ID (only accessible by database moderators). + * @apiName UpdateWinkData + * @apiGroup Wink + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Wink')) + /** + * @api {delete} v4/wink/:id Delete Wink Data + * @apiDescription Delete data related to wink with a specific ID (only accessible by admins). + * @apiName DeleteWinkData + * @apiGroup Wink + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Wink')); +// Export the router +export default router; diff --git a/src/routes/v4/interactions/yes.js b/src/routes/v4/interactions/yes.js new file mode 100644 index 0000000..457ca17 --- /dev/null +++ b/src/routes/v4/interactions/yes.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getRandomYes from '../../../controllers/v4/interactions/yes.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../middlewares/database/add.js'; +import updateData from '../../../middlewares/database/update.js'; +import deleteData from '../../../middlewares/database/delete.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/yes Get a Random Yes + * @apiDescription Retrieve a random yes. + * @apiName GetRandomYes + * @apiGroup Yes + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object[]} users List of users. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getRandomYes) + /** + * @api {post} v4/yes Increment Yes Data + * @apiDescription Increment data related to yess (only accessible by database moderators). + * @apiName IncrementYesData + * @apiGroup Yes + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization Database Moderator's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + * + */ + .post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Yesh')); + +router + .route('/:id') + /** + * @api {patch} v4/yes/:id Update Yes Data + * @apiDescription Update data related to yess with a specific ID (only accessible by database moderators). + * @apiName UpdateYesData + * @apiGroup Yes + * @apiPermission database_moderator + * + * @apiHeader {String} Authorization database moderator access token. + * + * @apiSuccess {Object} result Result of the data update. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Yesh')) + /** + * @api {delete} v4/yes/:id Delete Yes Data + * @apiDescription Delete data related to yes with a specific ID (only accessible by admins). + * @apiName DeleteYesData + * @apiGroup Yes + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data deletion. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @function createRateLimit + * @description Creates a rate limiter middleware to control the frequency of requests. + * @returns {function} Express middleware function that handles rate limiting. + */ + .delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Yesh')); +// Export the router +export default router;