Skip to content

Commit

Permalink
Add all interaction routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrea committed Jan 6, 2024
1 parent 68e4b2d commit 7bcf278
Show file tree
Hide file tree
Showing 65 changed files with 6,596 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -24,4 +24,4 @@ const getRandomKissu = async (req, res, next) => {
}
};

export default getRandomKissu;
export default getRandomKiss;
103 changes: 103 additions & 0 deletions src/routes/v4/interactions/angry.js
Original file line number Diff line number Diff line change
@@ -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;
103 changes: 103 additions & 0 deletions src/routes/v4/interactions/baka.js
Original file line number Diff line number Diff line change
@@ -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;
103 changes: 103 additions & 0 deletions src/routes/v4/interactions/bite.js
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 7bcf278

Please sign in to comment.