diff --git a/.env_example b/.env_example index 695e11d..50822d1 100644 --- a/.env_example +++ b/.env_example @@ -1,10 +1,33 @@ -## Create a file name with .env, then copy this file and paste over there and fill the details. - -# Get the Mongodb URL from their site -MONGODB_URI= -# Your PORT for the API to work on -PORT= -# Node Environment [ production or development ], use development to log errors. -NODE_ENV= -# Creates Log -DISCORD_WEBHOOK_URL= \ No newline at end of file +# Example .env file for configuring environment variables + +# MongoDB connection URI + +MONGODB_URI= # Specify the URI for MongoDB connection + +# Port for the server + +PORT= # Define the server port + +# Node environment ('development', 'production', etc.) + +NODE_ENV= # Set the Node environment + +# Logger configuration ('true' or 'false') + +LOGGER= # Enable or disable the logger + +# Webhook URL for chatbot logger + +CHATBOT_LOGGER_WEBHOOK= # Provide the URL for the chatbot logger webhook + +# Discord webhook URL + +DISCORD_WEBHOOK_URL= # Input the URL for Discord webhook + +# Access key for authentication + +ACCESS_KEY= # Assign the access key for authentication + +# HMAC key for generating secure tokens + +HMAC_KEY= # Set the HMAC key for secure token generation diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 478689b..1d97971 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ ko_fi: Aeryk +github: kyrea diff --git a/.gitignore b/.gitignore index 3872dd1..014d771 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,20 @@ -# Environment variables +# Ignore environment variables file .env - -# dependencies +# Ignore dependencies /node_modules -# Private files +# Ignore private files /private - -# jetbrains +# JetBrains IDE files .idea/ -# vscode +# Visual Studio Code settings .vscode/ -# Logs +# Ignore log files /logs -# Data Files +# Ignore data files /data \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json index 3b8e0d9..0bbdaa2 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,10 +1,10 @@ { - "useTabs": false, - "tabWidth": 2, - "semi": false, - "trailingComma": "es5", - "proseWrap": "preserve", - "printWidth": 80, + "semi": true, + "singleQuote": true, "arrowParens": "avoid", - "singleQuote": true -} + "trailingComma": "all", + "printWidth": 120, + "tabWidth": 2, + "useTabs": false, + "proseWrap": "preserve" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 59e7a83..237d521 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,70 +1,81 @@ -# Contributing to Waifu.it +# 🌟 Your Contribution Matters at Waifu.it! 🌟 -We love your input! We want to make contributing to this project as easy as possible, whether it's: +Greetings, and a heartfelt thank you for considering becoming a part of the Waifu.it project! We're thrilled about the prospect of your contribution and have made the process a breeze. Whether you're fixing something, reporting an issue, joining us as a maintainer, suggesting fantastic new features, or just engaging in lively discussions about our code, here's your invitation to dive in: -- Submitting a fix -- Reporting an issue -- Becoming a maintainer -- Proposing new features -- Discussing the current state of the code +## Embrace our Code of Conduct -## Code of Conduct +Before you embark on your journey, take a moment to acquaint yourself with our [Code of Conduct](CODE_OF_CONDUCT.md). It's the cornerstone of our respectful and inclusive community. -The code of conduct is described in [Code of Conduct](CODE_OF_CONDUCT.md). +## FAQs - Your Shortcut to Wisdom 🧠 -## Frequently Asked Questions (FAQs) +To make your initiation smoother, we've compiled a list of Frequently Asked Questions: - +- **Q:** [The Question?] +- **A:** [The Answer!] - - Q: [The Question?] - - A: [The Answer!] +## Dreaming Up Features? πŸš€ -## Feature Request +Crafting a Feature Request? Elevate it with: -Great Feature Requests tend to have: +- A snappy summary of your brilliant idea. +- Unveil the why behind your feature vision. +- Sprinkle in some extra contextβ€”images, resource linksβ€”to paint the full picture. -- A quick idea summary. -- What & why you wanted to add the specific feature. -- Additional context like images, links to resources to implement the feature etc, etc. +## Join Our Dance of Development πŸ’ƒπŸ•Ί -## Development Process +Pull requests are your golden ticket to propose changes! Directly submit your pull requests [here](https://github.com/WaifuAPI/Waifu.it/pulls). After a bit of magic in the review, your changes can become part of our enchanting project. -Pull requests are the best way to propose changes. We actively welcome your pull requests and invite you to submit pull requests directly here, and after review, these can be merged into the project. +## Crafting Pull Requests - Unleash Your Magic ✨ -## Pull Requests +1. Fork the repo and weave your code into the `staging` branch. +2. If your code is a performer, let it showcase with some test examples. +3. Describe your pull request with the elegance it deserves. -1. Fork the repo and pr to `staging` branch only. -2. If you've added code that should be tested, add some test examples. -3. Ensure to describe your pull request. +## Issues - Illuminate the Path πŸ•―οΈ -## Issues +When reporting issues, cast a clear light with your description. Show us how to find the bug by [opening a new issue](https://github.com/WaifuAPI/Waifu.it/issues); it's as simple as that! -Please ensure your description is -clear and has sufficient instructions to be able to reproduce the issue. Report a bug by opening a new issue; it's that easy! - -## Running the API Locally +## Magic Happens Locally - Run the API πŸŽ©πŸ‡ **Requirements** -- Node >= 12.x +- Node.js >=18.x - MongoDB -**1. Create a database** +**1. Create a Database** -Create a MongoDB database. +Craft a MongoDB database. No worries if you don't have MongoDB locally; [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) has a free hosted database waiting for you. -If you don't have MongoDB setup locally, then you can use [MongoDB Atlas][mongodb/atlas] to create a free hosted database. +**2. Enchant with Environment Variables** -**2. Environment Variables** +Craft a `.env` file in the project's magical realm. Copy the contents from `.env_example` and replace `` with your database connection string. Other mystical environment variables are revealed in the file. -You need to set the `MONGODB_URI` environment variable to point to your database. +```shell +MONGODB_URI= +``` -Create a file called `.env` in the root directory of the project. Copy everything from `.env_example` and replace `` with the connection string for your database, _other env variables info are commented in the file itself._ +**3. Cast the Spell of Dependencies** ```shell -MONGODB_URI= +$ npm install +``` + +**4. Begin the Incantation - Start the Server** + +The server dances to your tune, restarting gracefully with every code change. + +```shell +$ npm run dev ``` +**And there you have it!** + +## License - Let's Create a Masterpiece Together 🎨 + +By contributing to Waifu.it, you're authoring a chapter in our story. Your contributions will be elegantly licensed under the terms specified in the [LICENSE file](LICENSE.md). + +Let the adventure begin! Explore the realms of Waifu.it, and let's co-create something truly magical! πŸš€βœ¨ + **3. Installing dependencies** ```shell diff --git a/DOCS.md b/DOCS.md index c06bfa1..4d468c9 100644 --- a/DOCS.md +++ b/DOCS.md @@ -1 +1 @@ -## [Click here](https://github.com/WaifuAPI/Documentation) for API Documentaion. +## [Click here](https://docs.waifu.it) for API Documentaion. diff --git a/README.md b/README.md index 178fffe..1bffcb4 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,22 @@ -## Announcements +## πŸš€ Exciting News! -###### πŸ•› 23 May, 2023 -### πŸ“’ Migration from Private to Public -This repository will continue being as open-source while strictly following the [LICENCE](LICENCE.md). +### πŸ“… May 23, 2023 -###### πŸ•› 01 Feb, 2022 -### ~~πŸ“’ Migration from Public to Private~~ -~~This repository will no longer be updated with the latest versions of code. Our hosted version of this API, [__Waifu.it__](https://waifu.it/) **does not run the code in this repository anymore**. The official API's source code has been made private. We will still maintain this repository over time with patches and so but it will depend on the circumstances. And we will only be providing limited, non-obligatory support to self-hosting users **who have not made changes to the code we deem to be significant**.~~ +We're thrilled to announce a major transformation! Our repository is now fully open-source, embracing a new era of collaboration. Dive into the code, explore its possibilities, and contribute to the future of this amazing project. All within the bounds of our [LICENSE](LICENCE.md). ---
-

Waifu.it

+

πŸŽ‰ Waifu.it Unleashed!



-

A Random API Serving Anime Stuffs

+

🌟 A Random API Serving Anime Wonders +

GitHub issues @@ -31,44 +28,31 @@ This repository will continue being as open-source while strictly following the
-# Contributing +# How You Can Contribute -All contributions are greatly appreciated, but I recommend creating an issue or replying in a comment to let me know what you are working on first that way we don't overwrite each other. +Your input is invaluable! Before diving in, let's sync up to avoid overlapping efforts. -Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on this project. +## 🌈 Contribution Categories -## Issues +1. **Feature Requests/Enhancements** +2. **Bug Reports** +3. **Questions/Feedback** -- Feature requests/enhancements -- Bug reports -- Questions/feedback +## 🌿 Branching Strategy -## Branches +- **production:** The live, running version. Please refrain from direct changes. +- **staging:** All proposed changes go here. Submit a [pull request](https://help.github.com/en/articles/about-pull-requests) for review. -- production -> don't touch, this is what's running in production +## πŸš€ Submitting Your Changes -- staging -> [pull request][pr] this branch for everything +1. **Fork** the repository on GitHub. +2. **Clone** your forked repo locally. +3. Make your changes and **commit** them. +4. **Push** your changes back to your fork. +5. When ready, create a [pull request](https://help.github.com/en/articles/about-pull-requests) for our review. -## Pull Requests - -All pull requests are welcome! - -- [Fork][fork] the repository on GitHub. - -- [Clone][cloning] the forked repo to your local machine. - -- Do you changes - -- Commit your changes - -- Push your changes back up to your fork. - -- When you're ready, submit a [pull request][pr] so that we can review your changes. - -## Documentation +--- -[DOCS.md](DOCS.md) +Explore the [DOCS](DOCS.md) for detailed information. -[fork]: https://help.github.com/en/articles/fork-a-repo -[cloning]: https://help.github.com/en/articles/cloning-a-repository -[pr]: https://help.github.com/en/articles/about-pull-requests +Let's make Waifu.it even more fantastic together! 🌟 diff --git a/config.js b/config.js new file mode 100644 index 0000000..0d89fef --- /dev/null +++ b/config.js @@ -0,0 +1,76 @@ +/** + * Configuration module for managing environment-specific settings. + * @module config + * @type {Object} + */ + +import dotenv from 'dotenv'; + +/** + * Loads environment variables from a .env file into process.env. + * @type {Function} + */ +dotenv.config(); + +/** + * Application configuration settings. + * @type {Object} + * @property {string} database - Name of the database. + * @property {number} serverPort - Port for the server. + * @property {string} serverHost - Host for the server. + * @property {Object} roles - User roles. + * @property {string} roles.DEVELOPER - Developer role. + * @property {string} roles.ADMIN - Admin role. + * @property {string} roles.MOD - Moderator role. + * @property {string} roles.DB_MOD - Database Moderator role. + * @property {string} roles.PREMIUM - Premium role. + * @property {string} roles.USER - User role. + */ +const config = { + /** + * Name of the database. + * @type {string} + * @default 'mydatabase' + */ + database: process.env.MONGODB_URI || 'mydatabase', + + /** + * Port for the server. + * @type {number} + * @default 3000 + */ + serverPort: process.env.PORT || 3000, + + /** + * Host for the server. + * @type {string} + * @default '127.0.0.1' + */ + serverHost: process.env.HOST || 'http://localhost', + + /** + * User roles. + * @type {Object} + * @property {string} DEVELOPER - Developer role. + * @property {string} ADMIN - Admin role. + * @property {string} MOD - Moderator role. + * @property {string} DB_MOD - Database Moderator role. + * @property {string} PREMIUM - Premium role. + * @property {string} USER - User role. + */ + roles: { + DEVELOPER: 'developer', + ADMIN: 'admin', + MOD: 'moderator', + DB_MOD: 'database_moderator', + PREMIUM: 'premium', + USER: 'user', + }, +}; + +/** + * Global configuration object based on the current environment. + * @global + * @type {Object} + */ +global.config = config; diff --git a/nixpacks.toml b/nixpacks.toml deleted file mode 100644 index ef582f8..0000000 --- a/nixpacks.toml +++ /dev/null @@ -1,9 +0,0 @@ -[phases.setup] -nixPkgs = ['nodejs'] - -[phases.install] - cmd = "npm install --omit=dev" - -[start] - cmd = "npm start" - diff --git a/package-lock.json b/package-lock.json index fe7bb16..80a16f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "waifu.it", - "version": "3.4.14", + "version": "4.4.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "waifu.it", - "version": "3.4.14", + "version": "4.4.14", "license": "AGPLv3", "dependencies": { "chalk": "^4.1.2", @@ -26,22 +26,36 @@ "ora": "^5.4.1", "owoify-js": "^2.0.0", "path": "^0.12.7", - "request-ip": "^2.2.0", + "request-ip": "^3.3.0", "winston": "^3.10.0", "winston-daily-rotate-file": "^4.7.1" }, "devDependencies": { - "nodemon": "^2.0.22", + "concurrently": "^8.2.0", + "nodemon": "^3.0.2", "prettier": "^2.8.8" }, "engines": { "node": ">=18.x" } }, + "node_modules/@babel/runtime": { + "version": "7.23.8", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.8.tgz", + "integrity": "sha512-Y7KbAP984rn1VGMbGqKmBLio9V7y5Je9GvU4rQPCPinCyNfUcToxIXl06d59URp/F3LwinvODxab5N/G6qggkw==", + "dev": true, + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "optional": true, "engines": { "node": ">=0.1.90" } @@ -74,14 +88,17 @@ } }, "node_modules/@types/node": { - "version": "20.4.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", - "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" + "version": "20.10.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.8.tgz", + "integrity": "sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==", + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/triple-beam": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz", - "integrity": "sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==" + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", + "integrity": "sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==" }, "node_modules/abbrev": { "version": "1.1.1", @@ -142,9 +159,9 @@ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, "node_modules/async": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", - "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" }, "node_modules/asynckit": { "version": "0.4.0", @@ -299,12 +316,13 @@ } }, "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", + "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.1", + "set-function-length": "^1.1.1" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -364,9 +382,9 @@ } }, "node_modules/cli-spinners": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz", - "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==", + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", "engines": { "node": ">=6" }, @@ -388,6 +406,20 @@ "@colors/colors": "1.5.0" } }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/clone": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", @@ -469,6 +501,48 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "node_modules/concurrently": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.2.tgz", + "integrity": "sha512-1dP4gpXFhei8IOtlXRE/T/4H88ElHgTiUzh71YUmtjTEHMSRS2Z/fgOxHSxxusGHogsRfxNq1vyAwxSC+EVyDg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "date-fns": "^2.30.0", + "lodash": "^4.17.21", + "rxjs": "^7.8.1", + "shell-quote": "^1.8.1", + "spawn-command": "0.0.2", + "supports-color": "^8.1.1", + "tree-kill": "^1.2.2", + "yargs": "^17.7.2" + }, + "bin": { + "conc": "dist/bin/concurrently.js", + "concurrently": "dist/bin/concurrently.js" + }, + "engines": { + "node": "^14.13.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" + } + }, + "node_modules/concurrently/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -518,6 +592,22 @@ "node": ">= 0.10" } }, + "node_modules/date-fns": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "dev": true, + "dependencies": { + "@babel/runtime": "^7.21.0" + }, + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -537,6 +627,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/define-data-property": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", + "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "dependencies": { + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -610,6 +713,15 @@ "node": ">= 0.8" } }, + "node_modules/escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -840,9 +952,9 @@ } }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -854,24 +966,36 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/generate-password": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.7.0.tgz", - "integrity": "sha512-WPCtlfy0jexf7W5IbwxGUgpIDvsZIohbI2DAq2Q6TSlKKis+G4GT9sxvPxrZUGL8kP6WUXMWNqYnxY6DDKAdFA==" + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.7.1.tgz", + "integrity": "sha512-9bVYY+16m7W7GczRBDqXE+VVuCX+bWNrfYKC/2p2JkZukFb2sKxT6E3zZ3mJGz7GMe5iRK0A/WawSL3jQfJuNQ==" + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "engines": { + "node": "6.* || 8.* || >= 10.*" + } }, "node_modules/get-intrinsic": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", - "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", + "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", + "function-bind": "^1.1.2", "has-proto": "^1.0.1", - "has-symbols": "^1.0.3" + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -889,15 +1013,15 @@ "node": ">= 6" } }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", "dependencies": { - "function-bind": "^1.1.1" + "get-intrinsic": "^1.1.3" }, - "engines": { - "node": ">= 0.4.0" + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/has-flag": { @@ -908,6 +1032,17 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", + "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "dependencies": { + "get-intrinsic": "^1.2.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", @@ -930,6 +1065,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", @@ -1010,11 +1156,6 @@ "node": ">= 0.10" } }, - "node_modules/is_js": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/is_js/-/is_js-0.9.0.tgz", - "integrity": "sha512-8Y5EHSH+TonfUHX2g3pMJljdbGavg55q4jmHzghJCdqYDbdNROC8uw/YFQwIRCRqRJT1EY3pJefz+kglw+o7sg==" - }, "node_modules/is-arrayish": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", @@ -1136,16 +1277,27 @@ } }, "node_modules/logform": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.5.1.tgz", - "integrity": "sha512-9FyqAm9o9NKKfiAKfZoYo9bGXXuwMkxQiQttkT4YjjVtQVIQtK6LmVtlxmCaFswo6N4AfEkHqZTV0taDtPotNg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "1.6.0", "@types/triple-beam": "^1.3.2", "fecha": "^4.2.0", "ms": "^2.1.1", "safe-stable-stringify": "^2.3.1", "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, + "node_modules/logform/node_modules/@colors/colors": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", + "engines": { + "node": ">=0.1.90" } }, "node_modules/logform/node_modules/ms": { @@ -1153,6 +1305,18 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -1231,9 +1395,9 @@ } }, "node_modules/moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", "engines": { "node": "*" } @@ -1277,9 +1441,9 @@ } }, "node_modules/mongoose": { - "version": "5.13.20", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.20.tgz", - "integrity": "sha512-TjGFa/XnJYt+wLmn8y9ssjyO2OhBMeEBtOHb9iJM16EWu2Du6L1Q6zSiEK2ziyYQM8agb4tumNIQFzqbxId7MA==", + "version": "5.13.22", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.22.tgz", + "integrity": "sha512-p51k/c4X/MfqeQ3I1ranlDiggLzNumZrTDD9CeezHwZxt2/btf+YZD7MCe07RAY2NgFYVMayq6jMamw02Jmf9w==", "dependencies": { "@types/bson": "1.x || 4.0.x", "@types/mongodb": "^3.5.27", @@ -1375,9 +1539,9 @@ } }, "node_modules/node-fetch": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", - "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -1394,18 +1558,18 @@ } }, "node_modules/nodemon": { - "version": "2.0.22", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", - "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.2.tgz", + "integrity": "sha512-9qIN2LNTrEzpOPBaWHTm4Asy1LxXLSickZStAQ4IZe7zsoIpD/A7LWxhZV3t4Zu352uBcqVnRsDXSMR2Sc3lTA==", "dev": true, "dependencies": { "chokidar": "^3.5.2", - "debug": "^3.2.7", + "debug": "^4", "ignore-by-default": "^1.0.1", "minimatch": "^3.1.2", "pstree.remy": "^1.1.8", - "semver": "^5.7.1", - "simple-update-notifier": "^1.0.7", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", "supports-color": "^5.5.0", "touch": "^3.1.0", "undefsafe": "^2.0.5" @@ -1414,7 +1578,7 @@ "nodemon": "bin/nodemon.js" }, "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "funding": { "type": "opencollective", @@ -1422,12 +1586,20 @@ } }, "node_modules/nodemon/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "dependencies": { - "ms": "^2.1.1" + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, "node_modules/nodemon/node_modules/has-flag": { @@ -1440,9 +1612,9 @@ } }, "node_modules/nodemon/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "node_modules/nodemon/node_modules/supports-color": { @@ -1498,9 +1670,9 @@ } }, "node_modules/object-inspect": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -1761,18 +1933,21 @@ "node": ">=8.10.0" } }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true + }, "node_modules/regexp-clone": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" }, "node_modules/request-ip": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-2.2.0.tgz", - "integrity": "sha512-Hn4zUAr+XHbUs2RrfHur62t7+UhvtevqK32ordFewguEfNHUkhSdYgbG7PDGmXZEzqEXll9bei0+VMe6gkmuUQ==", - "dependencies": { - "is_js": "^0.9.0" - } + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/request-ip/-/request-ip-3.3.0.tgz", + "integrity": "sha512-cA6Xh6e0fDBBBwH77SLJaJPBmD3nWVAcF9/XAcsrIHdjhFzFiB5aNQFytdjCGPezU3ROwrR11IddKAM08vohxA==" }, "node_modules/require-at": { "version": "1.0.6", @@ -1782,6 +1957,15 @@ "node": ">=4" } }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/restore-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", @@ -1794,6 +1978,15 @@ "node": ">=8" } }, + "node_modules/rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "dev": true, + "dependencies": { + "tslib": "^2.1.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1839,12 +2032,18 @@ } }, "node_modules/semver": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", - "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, "bin": { - "semver": "bin/semver" + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/send": { @@ -1904,11 +2103,34 @@ "node": ">= 0.8.0" } }, + "node_modules/set-function-length": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", + "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "dependencies": { + "define-data-property": "^1.1.1", + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "node_modules/shell-quote": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", + "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -1941,24 +2163,15 @@ } }, "node_modules/simple-update-notifier": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", - "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", "dev": true, "dependencies": { - "semver": "~7.0.0" + "semver": "^7.5.3" }, "engines": { - "node": ">=8.10.0" - } - }, - "node_modules/simple-update-notifier/node_modules/semver": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", - "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==", - "dev": true, - "bin": { - "semver": "bin/semver.js" + "node": ">=10" } }, "node_modules/sliced": { @@ -1975,6 +2188,12 @@ "memory-pager": "^1.0.2" } }, + "node_modules/spawn-command": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", + "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==", + "dev": true + }, "node_modules/stack-trace": { "version": "0.0.10", "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", @@ -2081,6 +2300,15 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "dev": true, + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/triple-beam": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", @@ -2089,6 +2317,12 @@ "node": ">= 14.0.0" } }, + "node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -2107,6 +2341,11 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -2172,11 +2411,11 @@ } }, "node_modules/winston": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.10.0.tgz", - "integrity": "sha512-nT6SIDaE9B7ZRO0u3UvdrimG0HkB7dSTAgInQnNR2SOPJ4bvq5q79+pXLftKmP52lJGW15+H5MCK0nM9D3KB/g==", + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.11.0.tgz", + "integrity": "sha512-L3yR6/MzZAOl0DsysUXHVjOwv8mKZ71TrA/41EIduGpOOV5LQVodqN+QdQ6BS6PJ/RdIshZhq84P/fStEZkk7g==", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", "async": "^3.2.3", "is-stream": "^2.0.0", @@ -2210,16 +2449,16 @@ } }, "node_modules/winston-transport": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.5.0.tgz", - "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.6.0.tgz", + "integrity": "sha512-wbBA9PbPAHxKiygo7ub7BYRiKxms0tpfU2ljtWzb3SjRjv5yl6Ozuy/TkXf00HTAt+Uylo3gSkNwzc4ME0wiIg==", "dependencies": { "logform": "^2.3.2", "readable-stream": "^3.6.0", "triple-beam": "^1.3.0" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 12.0.0" } }, "node_modules/winston-transport/node_modules/readable-stream": { @@ -2235,6 +2474,14 @@ "node": ">= 6" } }, + "node_modules/winston/node_modules/@colors/colors": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/winston/node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -2247,6 +2494,65 @@ "engines": { "node": ">= 6" } + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } } } } diff --git a/package.json b/package.json index 305f3b9..0cdba54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waifu.it", - "version": "3.4.14", + "version": "4.4.14", "description": "Random API Serving Anime stuff", "author": "Aeryk", "private": true, @@ -9,6 +9,7 @@ "engines": { "node": ">=18.x" }, + "type": "module", "scripts": { "start": "node src/index.js", "dev": "nodemon src/index.js" @@ -31,12 +32,13 @@ "ora": "^5.4.1", "owoify-js": "^2.0.0", "path": "^0.12.7", - "request-ip": "^2.2.0", + "request-ip": "^3.3.0", "winston": "^3.10.0", "winston-daily-rotate-file": "^4.7.1" }, "devDependencies": { - "nodemon": "^2.0.22", + "concurrently": "^8.2.0", + "nodemon": "^3.0.2", "prettier": "^2.8.8" }, "keywords": [ diff --git a/src/app.js b/src/app.js index ee17c3c..e14f801 100644 --- a/src/app.js +++ b/src/app.js @@ -1,32 +1,90 @@ -const express = require('express') -const cors = require('cors') -// const winston = require('winston') -// const expressWinston = require('express-winston') -// const requestIp = require('request-ip'); -const routes = require('./routes') -const { - handler404, - errorsLogger, - errorsHandler, -} = require('./handlers/errors/index') -require('winston-daily-rotate-file') -const { ipLogger } = require('./handlers/logger/ip') -const path = require('path') - -// Express APP -const app = express() -app.use(cors()) -app.set('trust proxy', 1) - -// Logger +/*** Importing necessary modules ***/ +import express from 'express'; +import bodyParser from 'body-parser'; +import cors from 'cors'; +import pkg from '../package.json' assert { type: 'json' }; +/*** Importing custom error handlers and logger middleware ***/ +import { + handle404 /*** @params: req, res, next ***/, + logErrors /*** @params: err, req, res, next ***/, + errorHandler /*** @params: err, req, res, next ***/, +} from './middlewares/errors.js'; +import { logIP } from './middlewares/logger.js'; +import routesV3 from './routes/v3/index.js'; +import routesV4 from './routes/v4/index.js'; + +/*** Creating an instance of Express ***/ +const app = express(); + +/*** Enabling CORS for all routes ***/ +app.use(cors()); + +/*** Trusting the first proxy (when running behind a reverse proxy like Nginx) ***/ +app.set('trust proxy', 1); + +/*** Middleware to parse JSON-encoded bodies ***/ +app.use(express.json()); + +/*** Middleware to parse URL-encoded bodies ***/ +app.use(express.urlencoded({ extended: true })); + +/*** Logger middleware ***/ +/** + * @middleware + * @description Enables IP logging for incoming requests. + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ if (process.env.LOGGER === 'true') { - app.use(ipLogger) + app.use(logIP); } -// Main website (waifu.it) -app.use('/', express.static(path.join(__dirname, 'frontend'))) +/*** Middleware to parse the request body ***/ +app.use(bodyParser.json()); + +/*** Custom API routes ***/ +/** + * Route: GET /api/v3 + * @returns {void} + */ +app.use(routesV3); +/** + * Route: GET /api/v4 + * Description: Endpoint to verify the basic functionality of the API. Returns a success message if the API is working as expected. + * @name VerifyAPI + * @function + * @memberof routes + * @inner + * @param {express.Request} req - Express request object. + * @param {express.Response} res - Express response object. + * @returns {void} + */ +app.get('/api/v4', (req, res) => { + res.status(200).json({ + version: pkg.version, + message: 'API is functioning correctly.', + }); +}); +app.use('/api/v4', routesV4); -app.use(routes) -app.use(handler404, errorsLogger, errorsHandler) +/** + * @apiMiddleware + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @apiSuccess {Object[]} response - Response data. + * + * @apiError {BadRequest} BadRequest - Invalid request parameters. + * @apiError {Unauthorized} Unauthorized - Only authenticated users can access the data. + * @apiError {Forbidden} Forbidden - Only authorized users can access the data. + * @apiError {NotFound} NotFound - The requested resource was not found. + * @apiError {InternalServerError} InternalServerError - Something went wrong on the server. + */ +app.use(handle404, logErrors, errorHandler); -module.exports = app +/*** Exporting the Express app instance ***/ +export default app; diff --git a/src/controllers/facts/randomFacts.js b/src/controllers/facts/randomFacts.js deleted file mode 100644 index 9cbb4d8..0000000 --- a/src/controllers/facts/randomFacts.js +++ /dev/null @@ -1,44 +0,0 @@ -const createError = require('http-errors') -const Facts = require('../../models/schemas/Facts') -const tagsFilter = require('../../utils/tagsFilter') -const lengthFilter = require('../../utils/lengthFilter') -const Stats = require('../../models/schemas/Stat') - -// Get random Anime Fact -module.exports = async function getRandomFact(req, res, next) { - try { - const { minLength, maxLength, tags } = req.query - - const filter = {} - - if (minLength || maxLength) { - filter.length = lengthFilter(minLength, maxLength) - } - - if (tags) { - filter.tags = tagsFilter(tags) - } - - const [result] = await Facts.aggregate([ - // Apply filters (if any) - { $match: filter }, - // Select a random document from the results - { $sample: { size: 1 } }, - { $project: { __v: 0 } }, - ]) - - if (!result) { - return next(createError(404, 'Could not find any matching fact')) - } - - res.status(200).json(result) - - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facts: 1 } }) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/gifs/randomMidfing.js b/src/controllers/gifs/randomMidfing.js deleted file mode 100644 index b1bb31c..0000000 --- a/src/controllers/gifs/randomMidfing.js +++ /dev/null @@ -1,31 +0,0 @@ -const createError = require('http-errors') -const Midfinger = require('../../models/schemas/Midfing') -const Stats = require('../../models/schemas/Stat') - -// Get random Anime Midfinger -module.exports = async function getRandomMidfinger(req, res, next) { - try { - const [result] = await Midfinger.aggregate([ - // Select a random document from the results - { $sample: { size: 1 } }, - { $project: { __v: 0, _id: 0 } }, - ]) - - if (!result) { - return next(createError(404, 'Could not find any Midfinger Gif')) - } - - res.status(200).json(result) - - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { midfing: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/gifs/randomNervous.js b/src/controllers/gifs/randomNervous.js deleted file mode 100644 index a33acef..0000000 --- a/src/controllers/gifs/randomNervous.js +++ /dev/null @@ -1,31 +0,0 @@ -const createError = require('http-errors') -const Nervouse = require('../../models/schemas/Nervouse') -const Stats = require('../../models/schemas/Stat') - -// Get random Anime Nervous -module.exports = async function getRandomNervous(req, res, next) { - try { - const [result] = await Nervouse.aggregate([ - // Select a random document from the results - { $sample: { size: 1 } }, - { $project: { __v: 0, _id: 0 } }, - ]) - - if (!result) { - return next(createError(404, 'Could not find any Nervous Gif')) - } - - res.status(200).json(result) - - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { nervous: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/quotes/randomQuotes.js b/src/controllers/quotes/randomQuotes.js deleted file mode 100644 index 455dbcf..0000000 --- a/src/controllers/quotes/randomQuotes.js +++ /dev/null @@ -1,41 +0,0 @@ -const createError = require('http-errors') -const Quotes = require('../../models/schemas/Quotes') -const Stats = require('../../models/schemas/Stat') - -// Get random Anime Quote -module.exports = async function getRandomQuote(req, res, next) { - try { - const { character } = req.query - - const filter = {} - - if (character) { - filter.author = character - } - - const [result] = await Quotes.aggregate([ - // Apply filters (if any) - { $match: filter }, - // Select a random document from the results - { $sample: { size: 1 } }, - { $project: { __v: 0 } }, - ]) - - if (!result) { - return next(createError(404, 'Could not find any matching Quote')) - } - - res.status(200).json(result) - - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { quotes: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/utils/listTags.js b/src/controllers/utils/listTags.js deleted file mode 100644 index 21334ec..0000000 --- a/src/controllers/utils/listTags.js +++ /dev/null @@ -1,43 +0,0 @@ -const Tags = require('../../models/schemas/Tags') -const parseOrder = require('../../utils/parseOrder') -const Stats = require('../../models/schemas/Stat') - -module.exports = async function listTags(req, res, next) { - try { - let { sortBy, sortOrder } = req.query - - // Supported parameter values - const Values = { sortBy: ['name', 'usedCount'] } - // The default sort order depends on the `sortBy` field - const defaultSortOrder = { name: 1, usedCount: -1 } - - sortBy = Values.sortBy.includes(sortBy) ? sortBy : 'name' - sortOrder = parseOrder(sortOrder) || defaultSortOrder[sortBy] || 1 - - const results = await Tags.aggregate([ - { - $lookup: { - from: 'facts', - localField: 'name', - foreignField: 'tags', - as: 'usedCount', - }, - }, - { $addFields: { usedCount: { $size: '$usedCount' } } }, - { $sort: { [sortBy]: sortOrder } }, - { $project: { __v: 0 } }, - ]) - res.json(results) - - await Stats.findOneAndUpdate ( - { _id: "systemstats" }, - { $inc: { tags: 1 } }, - ) - } catch (error) { - await Stats.findOneAndUpdate ( - { _id: "systemstats" }, - { $inc: { failed_requests: 1 } }, - ) - return next(error) - } -} diff --git a/src/controllers/utils/owoify.js b/src/controllers/utils/owoify.js deleted file mode 100644 index 276629b..0000000 --- a/src/controllers/utils/owoify.js +++ /dev/null @@ -1,27 +0,0 @@ -const createError = require('http-errors') -const owoify = require('owoify-js').default -const Stats = require('../../models/schemas/Stat') - -module.exports = async function getOwofiyText(req, res, next) { - try { - const { text } = req.query - - if (!text) { - return next(createError(404, 'Invalid text input.')) - } - res.status(200).json({ - text: owoify(text), - }) - - return await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { owoify: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/utils/randomPassword.js b/src/controllers/utils/randomPassword.js deleted file mode 100644 index c312187..0000000 --- a/src/controllers/utils/randomPassword.js +++ /dev/null @@ -1,33 +0,0 @@ -const pass = require('generate-password') -const Stats = require('../../models/schemas/Stat') - -// Get random Password -module.exports = async function getRandomPassword(req, res, next) { - try { - const { charLength } = req.query - - const password = pass.generate({ - length: charLength || 50, - uppercase: true, - numbers: true, - symbols: true, - lowercase: true, - strict: true, - }) - - res.status(200).json({ - pass: password, - }) - - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { password: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/controllers/utils/uvuify.js b/src/controllers/utils/uvuify.js deleted file mode 100644 index 2245ac8..0000000 --- a/src/controllers/utils/uvuify.js +++ /dev/null @@ -1,27 +0,0 @@ -const createError = require('http-errors') -const uwuify = require('owoify-js') -const Stats = require('../../models/schemas/Stat') - -module.exports = async function getOwofiyText(req, res, next) { - try { - const { text } = req.query - - if (!text) { - return next(createError(404, 'Invalid text input.')) - } - res.status(200).json({ - text: uwuify(text), - }) - - return await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { uwuify: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} \ No newline at end of file diff --git a/src/controllers/utils/uwuify.js b/src/controllers/utils/uwuify.js deleted file mode 100644 index 9e5f9e2..0000000 --- a/src/controllers/utils/uwuify.js +++ /dev/null @@ -1,27 +0,0 @@ -const createError = require('http-errors') -const uvuify = require('owoify-js') -const Stats = require('../../models/schemas/Stat') - -module.exports = async function getOwofiyText(req, res, next) { - try { - const { text } = req.query - - if (!text) { - return next(createError(404, 'Invalid text input.')) - } - res.status(200).json({ - text: uvuify(text), - }) - - return await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { uvuify: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} \ No newline at end of file diff --git a/src/controllers/v3/facts/randomFacts.js b/src/controllers/v3/facts/randomFacts.js new file mode 100644 index 0000000..b64a767 --- /dev/null +++ b/src/controllers/v3/facts/randomFacts.js @@ -0,0 +1,58 @@ +import createError from 'http-errors'; +import Facts from '../../../models/schemas/Fact.js'; +import tagsFilter from '../../../modules/tagsFilter.js'; +import lengthFilter from '../../../modules/lengthFilter.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime fact with optional length and tags filters and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomFact = async (req, res, next) => { + try { + const { minLength, maxLength, tags } = req.query; + + // Create a filter object based on the optional length and tags parameters + const filter = {}; + + // Apply length filter (if minLength or maxLength is provided) + if (minLength || maxLength) { + filter.length = lengthFilter(minLength, maxLength); + } + + // Apply tags filter (if tags are provided) + if (tags) { + filter.tags = tagsFilter(tags); + } + + // Aggregate to match the filter, select a random fact, and project excluding version field + const [result] = await Facts.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + // If no fact is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching fact')); + } + + // Respond with the random fact + res.status(200).json(result); + + // Update system statistics for facts + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facts: 1 } }); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomFact; \ No newline at end of file diff --git a/src/controllers/gifs/randomAngry.js b/src/controllers/v3/gifs/randomAngry.js similarity index 59% rename from src/controllers/gifs/randomAngry.js rename to src/controllers/v3/gifs/randomAngry.js index c336680..6156cb9 100644 --- a/src/controllers/gifs/randomAngry.js +++ b/src/controllers/v3/gifs/randomAngry.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Angry = require('../../models/schemas/Angry') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Angry from '../../../models/schemas/Angry.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Angry -module.exports = async function getRandomAngry(req, res, next) { +const getRandomAngry = async (req, res, next) => { try { const [result] = await Angry.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Angry Gif')) + return next(createError(404, 'Could not find any Angry Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { angry: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { angry: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomAngry; diff --git a/src/controllers/gifs/randomBaka.js b/src/controllers/v3/gifs/randomBaka.js similarity index 59% rename from src/controllers/gifs/randomBaka.js rename to src/controllers/v3/gifs/randomBaka.js index f04d74a..746b3b6 100644 --- a/src/controllers/gifs/randomBaka.js +++ b/src/controllers/v3/gifs/randomBaka.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Baka = require('../../models/schemas/Baka') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Baka from '../../../models/schemas/Baka.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Baka -module.exports = async function getRandomBaka(req, res, next) { +const getRandomBaka = async (req, res, next) => { try { const [result] = await Baka.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Baka Gif')) + return next(createError(404, 'Could not find any Baka Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { baka: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { baka: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBaka; diff --git a/src/controllers/gifs/randomBite.js b/src/controllers/v3/gifs/randomBite.js similarity index 59% rename from src/controllers/gifs/randomBite.js rename to src/controllers/v3/gifs/randomBite.js index d2aad16..ddf9bf1 100644 --- a/src/controllers/gifs/randomBite.js +++ b/src/controllers/v3/gifs/randomBite.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Bite = require('../../models/schemas/Bite') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Bite from '../../../models/schemas/Bite.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bite -module.exports = async function getRandomBite(req, res, next) { +const getRandomBite = async (req, res, next) => { try { const [result] = await Bite.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Bite Gif')) + return next(createError(404, 'Could not find any Bite Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bite: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bite: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBite; diff --git a/src/controllers/gifs/randomBlush.js b/src/controllers/v3/gifs/randomBlush.js similarity index 59% rename from src/controllers/gifs/randomBlush.js rename to src/controllers/v3/gifs/randomBlush.js index 924f942..1a90820 100644 --- a/src/controllers/gifs/randomBlush.js +++ b/src/controllers/v3/gifs/randomBlush.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Blush = require('../../models/schemas/Blush') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Blush from '../../../models/schemas/Blush.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Blush -module.exports = async function getRandomBlush(req, res, next) { +const getRandomBlush = async (req, res, next) => { try { const [result] = await Blush.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Blush Gif')) + return next(createError(404, 'Could not find any Blush Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { blush: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { blush: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBlush; diff --git a/src/controllers/gifs/randomBonk.js b/src/controllers/v3/gifs/randomBonk.js similarity index 59% rename from src/controllers/gifs/randomBonk.js rename to src/controllers/v3/gifs/randomBonk.js index 003328f..c559823 100644 --- a/src/controllers/gifs/randomBonk.js +++ b/src/controllers/v3/gifs/randomBonk.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Bonk = require('../../models/schemas/Bonk') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Bonk from '../../../models/schemas/Bonk.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bonk -module.exports = async function getRandomBonk(req, res, next) { +const getRandomBonk = async (req, res, next) => { try { const [result] = await Bonk.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Bonk Gif')) + return next(createError(404, 'Could not find any Bonk Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bonk: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bonk: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBonk; diff --git a/src/controllers/gifs/randomBored.js b/src/controllers/v3/gifs/randomBored.js similarity index 59% rename from src/controllers/gifs/randomBored.js rename to src/controllers/v3/gifs/randomBored.js index a1d8b31..2caedfb 100644 --- a/src/controllers/gifs/randomBored.js +++ b/src/controllers/v3/gifs/randomBored.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Bored = require('../../models/schemas/Bored') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Bored from '../../../models/schemas/Bored.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bored -module.exports = async function getRandomBored(req, res, next) { +const getRandomBored = async (req, res, next) => { try { const [result] = await Bored.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Bored Gif')) + return next(createError(404, 'Could not find any Bored Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bored: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bored: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBored; diff --git a/src/controllers/gifs/randomBully.js b/src/controllers/v3/gifs/randomBully.js similarity index 59% rename from src/controllers/gifs/randomBully.js rename to src/controllers/v3/gifs/randomBully.js index 3e70dc1..ede6578 100644 --- a/src/controllers/gifs/randomBully.js +++ b/src/controllers/v3/gifs/randomBully.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Bully = require('../../models/schemas/Bully') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Bully from '../../../models/schemas/Bully.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bully -module.exports = async function getRandomBully(req, res, next) { +const getRandomBully = async (req, res, next) => { try { const [result] = await Bully.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Bully Gif')) + return next(createError(404, 'Could not find any Bully Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bully: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bully: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBully; diff --git a/src/controllers/gifs/randomBye.js b/src/controllers/v3/gifs/randomBye.js similarity index 60% rename from src/controllers/gifs/randomBye.js rename to src/controllers/v3/gifs/randomBye.js index 2cb2dd7..873468b 100644 --- a/src/controllers/gifs/randomBye.js +++ b/src/controllers/v3/gifs/randomBye.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Bye = require('../../models/schemas/Bye') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Bye from '../../../models/schemas/Bye.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bye -module.exports = async function getRandomBye(req, res, next) { +const getRandomBye = async (req, res, next) => { try { const [result] = await Bye.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Bye Gif')) + return next(createError(404, 'Could not find any Bye Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bye: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bye: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomBye; diff --git a/src/controllers/gifs/randomChase.js b/src/controllers/v3/gifs/randomChase.js similarity index 59% rename from src/controllers/gifs/randomChase.js rename to src/controllers/v3/gifs/randomChase.js index 661e16f..a16f38b 100644 --- a/src/controllers/gifs/randomChase.js +++ b/src/controllers/v3/gifs/randomChase.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Chase = require('../../models/schemas/Chase') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Chase from '../../../models/schemas/Chase.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Chase -module.exports = async function getRandomChase(req, res, next) { +const getRandomChase = async (req, res, next) => { try { const [result] = await Chase.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Chase Gif')) + return next(createError(404, 'Could not find any Chase Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { chase: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { chase: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomChase; diff --git a/src/controllers/gifs/randomCheer.js b/src/controllers/v3/gifs/randomCheer.js similarity index 59% rename from src/controllers/gifs/randomCheer.js rename to src/controllers/v3/gifs/randomCheer.js index cfc4371..21447b8 100644 --- a/src/controllers/gifs/randomCheer.js +++ b/src/controllers/v3/gifs/randomCheer.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Cheer = require('../../models/schemas/Cheer') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Cheer from '../../../models/schemas/Cheer.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cheer -module.exports = async function getRandomCheer(req, res, next) { +const getRandomCheer = async (req, res, next) => { try { const [result] = await Cheer.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Cheer Gif')) + return next(createError(404, 'Could not find any Cheer Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cheer: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cheer: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomCheer; diff --git a/src/controllers/gifs/randomCringe.js b/src/controllers/v3/gifs/randomCringe.js similarity index 51% rename from src/controllers/gifs/randomCringe.js rename to src/controllers/v3/gifs/randomCringe.js index d4242c9..3551842 100644 --- a/src/controllers/gifs/randomCringe.js +++ b/src/controllers/v3/gifs/randomCringe.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Cringe = require('../../models/schemas/Cringe') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Cringe from '../../../models/schemas/Cringe.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cringe -module.exports = async function getRandomCringe(req, res, next) { +const getRandomCringe = async (req, res, next) => { try { const [result] = await Cringe.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Cringe Gif')) + return next(createError(404, 'Could not find any Cringe Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { cringe: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cringe: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomCringe; diff --git a/src/controllers/gifs/randomCry.js b/src/controllers/v3/gifs/randomCry.js similarity index 60% rename from src/controllers/gifs/randomCry.js rename to src/controllers/v3/gifs/randomCry.js index 0dcd213..80d80e5 100644 --- a/src/controllers/gifs/randomCry.js +++ b/src/controllers/v3/gifs/randomCry.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Cry = require('../../models/schemas/Cry') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Cry from '../../../models/schemas/Cry.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cry -module.exports = async function getRandomCry(req, res, next) { +const getRandomCry = async (req, res, next) => { try { const [result] = await Cry.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Cry Gif')) + return next(createError(404, 'Could not find any Cry Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cry: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cry: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomCry; diff --git a/src/controllers/gifs/randomCuddle.js b/src/controllers/v3/gifs/randomCuddle.js similarity index 51% rename from src/controllers/gifs/randomCuddle.js rename to src/controllers/v3/gifs/randomCuddle.js index 5d567f9..f5f5314 100644 --- a/src/controllers/gifs/randomCuddle.js +++ b/src/controllers/v3/gifs/randomCuddle.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Cuddle = require('../../models/schemas/Cuddle') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Cuddle from '../../../models/schemas/Cuddle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cuddle -module.exports = async function getRandomCuddle(req, res, next) { +const getRandomCuddle = async (req, res, next) => { try { const [result] = await Cuddle.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Cuddle Gif')) + return next(createError(404, 'Could not find any Cuddle Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { cuddle: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cuddle: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomCuddle; diff --git a/src/controllers/gifs/randomDab.js b/src/controllers/v3/gifs/randomDab.js similarity index 60% rename from src/controllers/gifs/randomDab.js rename to src/controllers/v3/gifs/randomDab.js index 15d34c8..d95f2df 100644 --- a/src/controllers/gifs/randomDab.js +++ b/src/controllers/v3/gifs/randomDab.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Dab = require('../../models/schemas/Dab') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Dab from '../../../models/schemas/Dab.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Dab -module.exports = async function getRandomDab(req, res, next) { +const getRandomDab = async (req, res, next) => { try { const [result] = await Dab.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Dab Gif')) + return next(createError(404, 'Could not find any Dab Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dab: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dab: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomDab; diff --git a/src/controllers/gifs/randomDance.js b/src/controllers/v3/gifs/randomDance.js similarity index 59% rename from src/controllers/gifs/randomDance.js rename to src/controllers/v3/gifs/randomDance.js index cab5b04..922e5e3 100644 --- a/src/controllers/gifs/randomDance.js +++ b/src/controllers/v3/gifs/randomDance.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Dance = require('../../models/schemas/Dance') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Dance from '../../../models/schemas/Dance.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Dance -module.exports = async function getRandomDance(req, res, next) { +const getRandomDance = async (req, res, next) => { try { const [result] = await Dance.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Dance Gif')) + return next(createError(404, 'Could not find any Dance Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dance: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dance: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomDance; diff --git a/src/controllers/gifs/randomDie.js b/src/controllers/v3/gifs/randomDie.js similarity index 60% rename from src/controllers/gifs/randomDie.js rename to src/controllers/v3/gifs/randomDie.js index e93091a..da8936c 100644 --- a/src/controllers/gifs/randomDie.js +++ b/src/controllers/v3/gifs/randomDie.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Die = require('../../models/schemas/Die') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Die from '../../../models/schemas/Die.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Die -module.exports = async function getRandomDie(req, res, next) { +const getRandomDie = async (req, res, next) => { try { const [result] = await Die.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Die Gif')) + return next(createError(404, 'Could not find any Die Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { die: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { die: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomDie; diff --git a/src/controllers/gifs/randomDisgust.js b/src/controllers/v3/gifs/randomDisgust.js similarity index 51% rename from src/controllers/gifs/randomDisgust.js rename to src/controllers/v3/gifs/randomDisgust.js index da0d794..f52edbe 100644 --- a/src/controllers/gifs/randomDisgust.js +++ b/src/controllers/v3/gifs/randomDisgust.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Disgust = require('../../models/schemas/Disgust') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Disgust from '../../../models/schemas/Disgust.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Disgust -module.exports = async function getRandomDisgust(req, res, next) { +const getRandomDisgust = async (req, res, next) => { try { const [result] = await Disgust.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Disgust Gif')) + return next(createError(404, 'Could not find any Disgust Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { disgust: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { disgust: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomDisgust; diff --git a/src/controllers/gifs/randomFacepalm.js b/src/controllers/v3/gifs/randomFacepalm.js similarity index 51% rename from src/controllers/gifs/randomFacepalm.js rename to src/controllers/v3/gifs/randomFacepalm.js index 3b975c1..4d1751b 100644 --- a/src/controllers/gifs/randomFacepalm.js +++ b/src/controllers/v3/gifs/randomFacepalm.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Facepalm = require('../../models/schemas/Facepalm') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Facepalm from '../../../models/schemas/Facepalm.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Facepalm -module.exports = async function getRandomFacepalm(req, res, next) { +const getRandomFacepalm = async (req, res, next) => { try { const [result] = await Facepalm.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Facepalm Gif')) + return next(createError(404, 'Could not find any Facepalm Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { facepalm: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facepalm: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomFacepalm; diff --git a/src/controllers/gifs/randomFeed.js b/src/controllers/v3/gifs/randomFeed.js similarity index 59% rename from src/controllers/gifs/randomFeed.js rename to src/controllers/v3/gifs/randomFeed.js index 2abc733..930e163 100644 --- a/src/controllers/gifs/randomFeed.js +++ b/src/controllers/v3/gifs/randomFeed.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Feed = require('../../models/schemas/Feed') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Feed from '../../../models/schemas/Feed.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Feed -module.exports = async function getRandomFeed(req, res, next) { +const getRandomFeed = async (req, res, next) => { try { const [result] = await Feed.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Feed Gif')) + return next(createError(404, 'Could not find any Feed Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { feed: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { feed: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomFeed; diff --git a/src/controllers/gifs/randomGlomp.js b/src/controllers/v3/gifs/randomGlomp.js similarity index 59% rename from src/controllers/gifs/randomGlomp.js rename to src/controllers/v3/gifs/randomGlomp.js index e9cfc85..2fd4029 100644 --- a/src/controllers/gifs/randomGlomp.js +++ b/src/controllers/v3/gifs/randomGlomp.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Glomp = require('../../models/schemas/Glomp') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Glomp from '../../../models/schemas/Glomp.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Glomp -module.exports = async function getRandomGlomp(req, res, next) { +const getRandomGlomp = async (req, res, next) => { try { const [result] = await Glomp.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Glomp Gif')) + return next(createError(404, 'Could not find any Glomp Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { glomp: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { glomp: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomGlomp; diff --git a/src/controllers/gifs/randomHappy.js b/src/controllers/v3/gifs/randomHappy.js similarity index 59% rename from src/controllers/gifs/randomHappy.js rename to src/controllers/v3/gifs/randomHappy.js index d5e45f9..59de724 100644 --- a/src/controllers/gifs/randomHappy.js +++ b/src/controllers/v3/gifs/randomHappy.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Happy = require('../../models/schemas/Happy') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Happy from '../../../models/schemas/Happy.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Happy -module.exports = async function getRandomHappy(req, res, next) { +const getRandomHappy = async (req, res, next) => { try { const [result] = await Happy.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Happy Gif')) + return next(createError(404, 'Could not find any Happy Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { happy: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { happy: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomHappy; diff --git a/src/controllers/gifs/randomHi.js b/src/controllers/v3/gifs/randomHi.js similarity index 60% rename from src/controllers/gifs/randomHi.js rename to src/controllers/v3/gifs/randomHi.js index 942a0ab..d2614d7 100644 --- a/src/controllers/gifs/randomHi.js +++ b/src/controllers/v3/gifs/randomHi.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Hi = require('../../models/schemas/Hi') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Hi from '../../../models/schemas/Hi.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hi -module.exports = async function getRandomHi(req, res, next) { +const getRandomHi = async (req, res, next) => { try { const [result] = await Hi.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Hi Gif')) + return next(createError(404, 'Could not find any Hi Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hi: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hi: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomHi; diff --git a/src/controllers/gifs/randomHighfive.js b/src/controllers/v3/gifs/randomHighfive.js similarity index 51% rename from src/controllers/gifs/randomHighfive.js rename to src/controllers/v3/gifs/randomHighfive.js index 44e0ba6..c290116 100644 --- a/src/controllers/gifs/randomHighfive.js +++ b/src/controllers/v3/gifs/randomHighfive.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Highfive = require('../../models/schemas/Highfive') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Highfive from '../../../models/schemas/Highfive.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Highfive -module.exports = async function getRandomHighfive(req, res, next) { +const getRandomHighfive = async (req, res, next) => { try { const [result] = await Highfive.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Highfive Gif')) + return next(createError(404, 'Could not find any Highfive Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { highfive: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { highfive: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomHighfive; diff --git a/src/controllers/gifs/randomHold.js b/src/controllers/v3/gifs/randomHold.js similarity index 59% rename from src/controllers/gifs/randomHold.js rename to src/controllers/v3/gifs/randomHold.js index 7537186..9640b64 100644 --- a/src/controllers/gifs/randomHold.js +++ b/src/controllers/v3/gifs/randomHold.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Hold = require('../../models/schemas/Hold') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Hold from '../../../models/schemas/Hold.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hold -module.exports = async function getRandomHold(req, res, next) { +const getRandomHold = async (req, res, next) => { try { const [result] = await Hold.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Hold Gif')) + return next(createError(404, 'Could not find any Hold Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hold: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hold: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomHold; diff --git a/src/controllers/gifs/randomHug.js b/src/controllers/v3/gifs/randomHug.js similarity index 60% rename from src/controllers/gifs/randomHug.js rename to src/controllers/v3/gifs/randomHug.js index 02bf136..8d3432f 100644 --- a/src/controllers/gifs/randomHug.js +++ b/src/controllers/v3/gifs/randomHug.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Hug = require('../../models/schemas/Hug') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Hug from '../../../models/schemas/Hug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hug -module.exports = async function getRandomHug(req, res, next) { +const getRandomHug = async (req, res, next) => { try { const [result] = await Hug.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Hug Gif')) + return next(createError(404, 'Could not find any Hug Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hug: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hug: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomHug; diff --git a/src/controllers/gifs/randomKick.js b/src/controllers/v3/gifs/randomKick.js similarity index 59% rename from src/controllers/gifs/randomKick.js rename to src/controllers/v3/gifs/randomKick.js index 6300439..b24d888 100644 --- a/src/controllers/gifs/randomKick.js +++ b/src/controllers/v3/gifs/randomKick.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Kick = require('../../models/schemas/Kick') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Kick from '../../../models/schemas/Kick.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kick -module.exports = async function getRandomKick(req, res, next) { +const getRandomKick = async (req, res, next) => { try { const [result] = await Kick.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Kick Gif')) + return next(createError(404, 'Could not find any Kick Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kick: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kick: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomKick; diff --git a/src/controllers/gifs/randomKill.js b/src/controllers/v3/gifs/randomKill.js similarity index 59% rename from src/controllers/gifs/randomKill.js rename to src/controllers/v3/gifs/randomKill.js index 266ba69..7186102 100644 --- a/src/controllers/gifs/randomKill.js +++ b/src/controllers/v3/gifs/randomKill.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Kill = require('../../models/schemas/Kill') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Kill from '../../../models/schemas/Kill.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kill -module.exports = async function getRandomKill(req, res, next) { +const getRandomKill = async (req, res, next) => { try { const [result] = await Kill.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Kill Gif')) + return next(createError(404, 'Could not find any Kill Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kill: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kill: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomKill; diff --git a/src/controllers/gifs/randomKissu.js b/src/controllers/v3/gifs/randomKissu.js similarity index 59% rename from src/controllers/gifs/randomKissu.js rename to src/controllers/v3/gifs/randomKissu.js index 7d596da..a13ce66 100644 --- a/src/controllers/gifs/randomKissu.js +++ b/src/controllers/v3/gifs/randomKissu.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Kissu = require('../../models/schemas/Kissu') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Kissu from '../../../models/schemas/Kissu.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kissu -module.exports = async function getRandomKissu(req, res, next) { +const getRandomKissu = async (req, res, next) => { try { const [result] = await Kissu.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Kissu Gif')) + return next(createError(404, 'Could not find any Kissu Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kissu: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kissu: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomKissu; diff --git a/src/controllers/gifs/randomLaugh.js b/src/controllers/v3/gifs/randomLaugh.js similarity index 59% rename from src/controllers/gifs/randomLaugh.js rename to src/controllers/v3/gifs/randomLaugh.js index 8e95f98..7450f79 100644 --- a/src/controllers/gifs/randomLaugh.js +++ b/src/controllers/v3/gifs/randomLaugh.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Laugh = require('../../models/schemas/Laugh') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Laugh from '../../../models/schemas/Laugh.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Laugh -module.exports = async function getRandomLaugh(req, res, next) { +const getRandomLaugh = async (req, res, next) => { try { const [result] = await Laugh.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Laugh Gif')) + return next(createError(404, 'Could not find any Laugh Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { laugh: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { laugh: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomLaugh; diff --git a/src/controllers/gifs/randomLick.js b/src/controllers/v3/gifs/randomLick.js similarity index 59% rename from src/controllers/gifs/randomLick.js rename to src/controllers/v3/gifs/randomLick.js index c62ee7e..df87eb8 100644 --- a/src/controllers/gifs/randomLick.js +++ b/src/controllers/v3/gifs/randomLick.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Lick = require('../../models/schemas/Lick') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Lick from '../../../models/schemas/Lick.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Lick -module.exports = async function getRandomLick(req, res, next) { +const getRandomLick = async (req, res, next) => { try { const [result] = await Lick.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Lick Gif')) + return next(createError(404, 'Could not find any Lick Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lick: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lick: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomLick; diff --git a/src/controllers/gifs/randomLove.js b/src/controllers/v3/gifs/randomLove.js similarity index 59% rename from src/controllers/gifs/randomLove.js rename to src/controllers/v3/gifs/randomLove.js index e9f0e74..a0699e5 100644 --- a/src/controllers/gifs/randomLove.js +++ b/src/controllers/v3/gifs/randomLove.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Love = require('../../models/schemas/Love') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Love from '../../../models/schemas/Love.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Love -module.exports = async function getRandomLove(req, res, next) { +const getRandomLove = async (req, res, next) => { try { const [result] = await Love.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Love Gif')) + return next(createError(404, 'Could not find any Love Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { love: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { love: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomLove; diff --git a/src/controllers/gifs/randomLurk.js b/src/controllers/v3/gifs/randomLurk.js similarity index 59% rename from src/controllers/gifs/randomLurk.js rename to src/controllers/v3/gifs/randomLurk.js index 48a5a00..74e36f7 100644 --- a/src/controllers/gifs/randomLurk.js +++ b/src/controllers/v3/gifs/randomLurk.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Lurk = require('../../models/schemas/Lurk') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Lurk from '../../../models/schemas/Lurk.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Lurk -module.exports = async function getRandomLurk(req, res, next) { +const getRandomLurk = async (req, res, next) => { try { const [result] = await Lurk.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Lurk Gif')) + return next(createError(404, 'Could not find any Lurk Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lurk: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lurk: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomLurk; diff --git a/src/controllers/v3/gifs/randomMidfing.js b/src/controllers/v3/gifs/randomMidfing.js new file mode 100644 index 0000000..6290752 --- /dev/null +++ b/src/controllers/v3/gifs/randomMidfing.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Midfing from '../../../models/schemas/Midfing.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Midfing +const getRandomMidfing = async (req, res, next) => { + try { + const [result] = await Midfing.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Midfing Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { midfing: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomMidfing; diff --git a/src/controllers/v3/gifs/randomNervous.js b/src/controllers/v3/gifs/randomNervous.js new file mode 100644 index 0000000..5a2616b --- /dev/null +++ b/src/controllers/v3/gifs/randomNervous.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Nervous from '../../../models/schemas/Nervous.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nervous +const getRandomNervous = async (req, res, next) => { + try { + const [result] = await Nervous.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nervous Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nervous: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNervous; diff --git a/src/controllers/gifs/randomNom.js b/src/controllers/v3/gifs/randomNom.js similarity index 60% rename from src/controllers/gifs/randomNom.js rename to src/controllers/v3/gifs/randomNom.js index f75e8f6..00f9b20 100644 --- a/src/controllers/gifs/randomNom.js +++ b/src/controllers/v3/gifs/randomNom.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Nom = require('../../models/schemas/Nom') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Nom from '../../../models/schemas/Nom.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nom -module.exports = async function getRandomNom(req, res, next) { +const getRandomNom = async (req, res, next) => { try { const [result] = await Nom.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Nom Gif')) + return next(createError(404, 'Could not find any Nom Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nom: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nom: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomNom; diff --git a/src/controllers/gifs/randomNope.js b/src/controllers/v3/gifs/randomNope.js similarity index 59% rename from src/controllers/gifs/randomNope.js rename to src/controllers/v3/gifs/randomNope.js index d4f640b..348aa18 100644 --- a/src/controllers/gifs/randomNope.js +++ b/src/controllers/v3/gifs/randomNope.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Nope = require('../../models/schemas/Nope') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Nope from '../../../models/schemas/Nope.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nope -module.exports = async function getRandomNope(req, res, next) { +const getRandomNope = async (req, res, next) => { try { const [result] = await Nope.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Nope Gif')) + return next(createError(404, 'Could not find any Nope Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nope: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nope: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomNope; diff --git a/src/controllers/gifs/randomNuzzle.js b/src/controllers/v3/gifs/randomNuzzle.js similarity index 51% rename from src/controllers/gifs/randomNuzzle.js rename to src/controllers/v3/gifs/randomNuzzle.js index ad2e471..38e1f7b 100644 --- a/src/controllers/gifs/randomNuzzle.js +++ b/src/controllers/v3/gifs/randomNuzzle.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Nuzzle = require('../../models/schemas/Nuzzle') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Nuzzle from '../../../models/schemas/Nuzzle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nuzzle -module.exports = async function getRandomNuzzle(req, res, next) { +const getRandomNuzzle = async (req, res, next) => { try { const [result] = await Nuzzle.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Nuzzle Gif')) + return next(createError(404, 'Could not find any Nuzzle Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { nuzzle: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nuzzle: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomNuzzle; diff --git a/src/controllers/gifs/randomPanic.js b/src/controllers/v3/gifs/randomPanic.js similarity index 59% rename from src/controllers/gifs/randomPanic.js rename to src/controllers/v3/gifs/randomPanic.js index 167cd10..abf97e0 100644 --- a/src/controllers/gifs/randomPanic.js +++ b/src/controllers/v3/gifs/randomPanic.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Panic = require('../../models/schemas/Panic') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Panic from '../../../models/schemas/Panic.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Panic -module.exports = async function getRandomPanic(req, res, next) { +const getRandomPanic = async (req, res, next) => { try { const [result] = await Panic.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Panic Gif')) + return next(createError(404, 'Could not find any Panic Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { panic: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { panic: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPanic; diff --git a/src/controllers/gifs/randomPat.js b/src/controllers/v3/gifs/randomPat.js similarity index 60% rename from src/controllers/gifs/randomPat.js rename to src/controllers/v3/gifs/randomPat.js index 4749a17..bd683d9 100644 --- a/src/controllers/gifs/randomPat.js +++ b/src/controllers/v3/gifs/randomPat.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Pat = require('../../models/schemas/Pat') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Pat from '../../../models/schemas/Pat.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Pat -module.exports = async function getRandomPat(req, res, next) { +const getRandomPat = async (req, res, next) => { try { const [result] = await Pat.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Pat Gif')) + return next(createError(404, 'Could not find any Pat Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pat: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pat: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPat; diff --git a/src/controllers/gifs/randomPeck.js b/src/controllers/v3/gifs/randomPeck.js similarity index 59% rename from src/controllers/gifs/randomPeck.js rename to src/controllers/v3/gifs/randomPeck.js index 408e512..fb96e43 100644 --- a/src/controllers/gifs/randomPeck.js +++ b/src/controllers/v3/gifs/randomPeck.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Peck = require('../../models/schemas/Peck') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Peck from '../../../models/schemas/Peck.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Peck -module.exports = async function getRandomPeck(req, res, next) { +const getRandomPeck = async (req, res, next) => { try { const [result] = await Peck.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Peck Gif')) + return next(createError(404, 'Could not find any Peck Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { peck: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { peck: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPeck; diff --git a/src/controllers/gifs/randomPoke.js b/src/controllers/v3/gifs/randomPoke.js similarity index 59% rename from src/controllers/gifs/randomPoke.js rename to src/controllers/v3/gifs/randomPoke.js index c817b6c..4b2c428 100644 --- a/src/controllers/gifs/randomPoke.js +++ b/src/controllers/v3/gifs/randomPoke.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Poke = require('../../models/schemas/Poke') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Poke from '../../../models/schemas/Poke.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Poke -module.exports = async function getRandomPoke(req, res, next) { +const getRandomPoke = async (req, res, next) => { try { const [result] = await Poke.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Poke Gif')) + return next(createError(404, 'Could not find any Poke Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { poke: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { poke: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPoke; diff --git a/src/controllers/gifs/randomPout.js b/src/controllers/v3/gifs/randomPout.js similarity index 59% rename from src/controllers/gifs/randomPout.js rename to src/controllers/v3/gifs/randomPout.js index 6babcb2..dc45330 100644 --- a/src/controllers/gifs/randomPout.js +++ b/src/controllers/v3/gifs/randomPout.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Pout = require('../../models/schemas/Pout') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Pout from '../../../models/schemas/Pout.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Pout -module.exports = async function getRandomPout(req, res, next) { +const getRandomPout = async (req, res, next) => { try { const [result] = await Pout.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Pout Gif')) + return next(createError(404, 'Could not find any Pout Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pout: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pout: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPout; diff --git a/src/controllers/gifs/randomPunch.js b/src/controllers/v3/gifs/randomPunch.js similarity index 59% rename from src/controllers/gifs/randomPunch.js rename to src/controllers/v3/gifs/randomPunch.js index fc7a704..dd35b84 100644 --- a/src/controllers/gifs/randomPunch.js +++ b/src/controllers/v3/gifs/randomPunch.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Punch = require('../../models/schemas/Punch') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Punch from '../../../models/schemas/Punch.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Punch -module.exports = async function getRandomPunch(req, res, next) { +const getRandomPunch = async (req, res, next) => { try { const [result] = await Punch.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Punch Gif')) + return next(createError(404, 'Could not find any Punch Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { punch: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { punch: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomPunch; diff --git a/src/controllers/gifs/randomRun.js b/src/controllers/v3/gifs/randomRun.js similarity index 60% rename from src/controllers/gifs/randomRun.js rename to src/controllers/v3/gifs/randomRun.js index 735f7a2..061d36f 100644 --- a/src/controllers/gifs/randomRun.js +++ b/src/controllers/v3/gifs/randomRun.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Run = require('../../models/schemas/Run') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Run from '../../../models/schemas/Run.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Run -module.exports = async function getRandomRun(req, res, next) { +const getRandomRun = async (req, res, next) => { try { const [result] = await Run.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Run Gif')) + return next(createError(404, 'Could not find any Run Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { run: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { run: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomRun; diff --git a/src/controllers/gifs/randomSad.js b/src/controllers/v3/gifs/randomSad.js similarity index 60% rename from src/controllers/gifs/randomSad.js rename to src/controllers/v3/gifs/randomSad.js index 769866c..0af254d 100644 --- a/src/controllers/gifs/randomSad.js +++ b/src/controllers/v3/gifs/randomSad.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Sad = require('../../models/schemas/Sad') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Sad from '../../../models/schemas/Sad.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sad -module.exports = async function getRandomSad(req, res, next) { +const getRandomSad = async (req, res, next) => { try { const [result] = await Sad.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Sad Gif')) + return next(createError(404, 'Could not find any Sad Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sad: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sad: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSad; diff --git a/src/controllers/gifs/randomShoot.js b/src/controllers/v3/gifs/randomShoot.js similarity index 59% rename from src/controllers/gifs/randomShoot.js rename to src/controllers/v3/gifs/randomShoot.js index 0df7c36..cdc8a1b 100644 --- a/src/controllers/gifs/randomShoot.js +++ b/src/controllers/v3/gifs/randomShoot.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Shoot = require('../../models/schemas/Shoot') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Shoot from '../../../models/schemas/Shoot.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Shoot -module.exports = async function getRandomShoot(req, res, next) { +const getRandomShoot = async (req, res, next) => { try { const [result] = await Shoot.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Shoot Gif')) + return next(createError(404, 'Could not find any Shoot Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shoot: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shoot: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomShoot; diff --git a/src/controllers/gifs/randomShrug.js b/src/controllers/v3/gifs/randomShrug.js similarity index 59% rename from src/controllers/gifs/randomShrug.js rename to src/controllers/v3/gifs/randomShrug.js index 51fbb42..9755221 100644 --- a/src/controllers/gifs/randomShrug.js +++ b/src/controllers/v3/gifs/randomShrug.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Shrug = require('../../models/schemas/Shrug') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Shrug from '../../../models/schemas/Shrug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Shrug -module.exports = async function getRandomShrug(req, res, next) { +const getRandomShrug = async (req, res, next) => { try { const [result] = await Shrug.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Shrug Gif')) + return next(createError(404, 'Could not find any Shrug Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shrug: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shrug: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomShrug; diff --git a/src/controllers/gifs/randomSip.js b/src/controllers/v3/gifs/randomSip.js similarity index 60% rename from src/controllers/gifs/randomSip.js rename to src/controllers/v3/gifs/randomSip.js index f2c240f..37fcea4 100644 --- a/src/controllers/gifs/randomSip.js +++ b/src/controllers/v3/gifs/randomSip.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Sip = require('../../models/schemas/Sip') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Sip from '../../../models/schemas/Sip.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sip -module.exports = async function getRandomSip(req, res, next) { +const getRandomSip = async (req, res, next) => { try { const [result] = await Sip.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Sip Gif')) + return next(createError(404, 'Could not find any Sip Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sip: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sip: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSip; diff --git a/src/controllers/gifs/randomSlap.js b/src/controllers/v3/gifs/randomSlap.js similarity index 59% rename from src/controllers/gifs/randomSlap.js rename to src/controllers/v3/gifs/randomSlap.js index db83bbc..89fb3e5 100644 --- a/src/controllers/gifs/randomSlap.js +++ b/src/controllers/v3/gifs/randomSlap.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Slap = require('../../models/schemas/Slap') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Slap from '../../../models/schemas/Slap.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Slap -module.exports = async function getRandomSlap(req, res, next) { +const getRandomSlap = async (req, res, next) => { try { const [result] = await Slap.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Slap Gif')) + return next(createError(404, 'Could not find any Slap Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { slap: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { slap: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSlap; diff --git a/src/controllers/gifs/randomSleepy.js b/src/controllers/v3/gifs/randomSleepy.js similarity index 51% rename from src/controllers/gifs/randomSleepy.js rename to src/controllers/v3/gifs/randomSleepy.js index a8d97b0..a408099 100644 --- a/src/controllers/gifs/randomSleepy.js +++ b/src/controllers/v3/gifs/randomSleepy.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Sleepy = require('../../models/schemas/Sleepy') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Sleepy from '../../../models/schemas/Sleepy.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sleepy -module.exports = async function getRandomSleepy(req, res, next) { +const getRandomSleepy = async (req, res, next) => { try { const [result] = await Sleepy.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Sleepy Gif')) + return next(createError(404, 'Could not find any Sleepy Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { sleepy: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sleepy: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSleepy; diff --git a/src/controllers/gifs/randomSmile.js b/src/controllers/v3/gifs/randomSmile.js similarity index 59% rename from src/controllers/gifs/randomSmile.js rename to src/controllers/v3/gifs/randomSmile.js index 1131008..54983e2 100644 --- a/src/controllers/gifs/randomSmile.js +++ b/src/controllers/v3/gifs/randomSmile.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Smile = require('../../models/schemas/Smile') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Smile from '../../../models/schemas/Smile.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Smile -module.exports = async function getRandomSmile(req, res, next) { +const getRandomSmile = async (req, res, next) => { try { const [result] = await Smile.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Smile Gif')) + return next(createError(404, 'Could not find any Smile Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smile: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smile: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSmile; diff --git a/src/controllers/gifs/randomSmug.js b/src/controllers/v3/gifs/randomSmug.js similarity index 59% rename from src/controllers/gifs/randomSmug.js rename to src/controllers/v3/gifs/randomSmug.js index 55adb87..8861730 100644 --- a/src/controllers/gifs/randomSmug.js +++ b/src/controllers/v3/gifs/randomSmug.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Smug = require('../../models/schemas/Smug') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Smug from '../../../models/schemas/Smug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Smug -module.exports = async function getRandomSmug(req, res, next) { +const getRandomSmug = async (req, res, next) => { try { const [result] = await Smug.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Smug Gif')) + return next(createError(404, 'Could not find any Smug Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smug: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smug: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSmug; diff --git a/src/controllers/gifs/randomStab.js b/src/controllers/v3/gifs/randomStab.js similarity index 59% rename from src/controllers/gifs/randomStab.js rename to src/controllers/v3/gifs/randomStab.js index 93390e5..3b0ce94 100644 --- a/src/controllers/gifs/randomStab.js +++ b/src/controllers/v3/gifs/randomStab.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Stab = require('../../models/schemas/Stab') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Stab from '../../../models/schemas/Stab.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Stab -module.exports = async function getRandomStab(req, res, next) { +const getRandomStab = async (req, res, next) => { try { const [result] = await Stab.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Stab Gif')) + return next(createError(404, 'Could not find any Stab Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stab: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stab: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomStab; diff --git a/src/controllers/gifs/randomStare.js b/src/controllers/v3/gifs/randomStare.js similarity index 59% rename from src/controllers/gifs/randomStare.js rename to src/controllers/v3/gifs/randomStare.js index 221f32d..b1c2979 100644 --- a/src/controllers/gifs/randomStare.js +++ b/src/controllers/v3/gifs/randomStare.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Stare = require('../../models/schemas/Stare') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Stare from '../../../models/schemas/Stare.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Stare -module.exports = async function getRandomStare(req, res, next) { +const getRandomStare = async (req, res, next) => { try { const [result] = await Stare.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Stare Gif')) + return next(createError(404, 'Could not find any Stare Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stare: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stare: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomStare; diff --git a/src/controllers/gifs/randomSuicide.js b/src/controllers/v3/gifs/randomSuicide.js similarity index 51% rename from src/controllers/gifs/randomSuicide.js rename to src/controllers/v3/gifs/randomSuicide.js index 4247bd8..f3d355c 100644 --- a/src/controllers/gifs/randomSuicide.js +++ b/src/controllers/v3/gifs/randomSuicide.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Suicide = require('../../models/schemas/Suicide') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Suicide from '../../../models/schemas/Suicide.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Suicide -module.exports = async function getRandomSuicide(req, res, next) { +const getRandomSuicide = async (req, res, next) => { try { const [result] = await Suicide.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Suicide Gif')) + return next(createError(404, 'Could not find any Suicide Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { suicide: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { suicide: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomSuicide; diff --git a/src/controllers/gifs/randomTease.js b/src/controllers/v3/gifs/randomTease.js similarity index 59% rename from src/controllers/gifs/randomTease.js rename to src/controllers/v3/gifs/randomTease.js index d698d21..5698856 100644 --- a/src/controllers/gifs/randomTease.js +++ b/src/controllers/v3/gifs/randomTease.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Tease = require('../../models/schemas/Tease') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Tease from '../../../models/schemas/Tease.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Tease -module.exports = async function getRandomTease(req, res, next) { +const getRandomTease = async (req, res, next) => { try { const [result] = await Tease.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Tease Gif')) + return next(createError(404, 'Could not find any Tease Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tease: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tease: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomTease; diff --git a/src/controllers/gifs/randomThink.js b/src/controllers/v3/gifs/randomThink.js similarity index 59% rename from src/controllers/gifs/randomThink.js rename to src/controllers/v3/gifs/randomThink.js index d7c73b9..0afad57 100644 --- a/src/controllers/gifs/randomThink.js +++ b/src/controllers/v3/gifs/randomThink.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Think = require('../../models/schemas/Think') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Think from '../../../models/schemas/Think.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Think -module.exports = async function getRandomThink(req, res, next) { +const getRandomThink = async (req, res, next) => { try { const [result] = await Think.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Think Gif')) + return next(createError(404, 'Could not find any Think Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { think: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { think: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomThink; diff --git a/src/controllers/gifs/randomThumbsup.js b/src/controllers/v3/gifs/randomThumbsup.js similarity index 51% rename from src/controllers/gifs/randomThumbsup.js rename to src/controllers/v3/gifs/randomThumbsup.js index 05dc315..6a2d1bd 100644 --- a/src/controllers/gifs/randomThumbsup.js +++ b/src/controllers/v3/gifs/randomThumbsup.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Thumbsup = require('../../models/schemas/Thumbsup') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Thumbsup from '../../../models/schemas/Thumbsup.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Thumbsup -module.exports = async function getRandomThumbsup(req, res, next) { +const getRandomThumbsup = async (req, res, next) => { try { const [result] = await Thumbsup.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Thumbsup Gif')) + return next(createError(404, 'Could not find any Thumbsup Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { thumbsup: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { thumbsup: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomThumbsup; diff --git a/src/controllers/gifs/randomTickle.js b/src/controllers/v3/gifs/randomTickle.js similarity index 51% rename from src/controllers/gifs/randomTickle.js rename to src/controllers/v3/gifs/randomTickle.js index b9da123..06e4bd2 100644 --- a/src/controllers/gifs/randomTickle.js +++ b/src/controllers/v3/gifs/randomTickle.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Tickle = require('../../models/schemas/Tickle') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Tickle from '../../../models/schemas/Tickle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Tickle -module.exports = async function getRandomTickle(req, res, next) { +const getRandomTickle = async (req, res, next) => { try { const [result] = await Tickle.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Tickle Gif')) + return next(createError(404, 'Could not find any Tickle Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { tickle: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tickle: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomTickle; diff --git a/src/controllers/gifs/randomTriggered.js b/src/controllers/v3/gifs/randomTriggered.js similarity index 50% rename from src/controllers/gifs/randomTriggered.js rename to src/controllers/v3/gifs/randomTriggered.js index 8e6cdc4..bfbc35e 100644 --- a/src/controllers/gifs/randomTriggered.js +++ b/src/controllers/v3/gifs/randomTriggered.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Triggered = require('../../models/schemas/Triggered') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Triggered from '../../../models/schemas/Triggered.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Triggered -module.exports = async function getRandomTriggered(req, res, next) { +const getRandomTriggered = async (req, res, next) => { try { const [result] = await Triggered.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Triggered Gif')) + return next(createError(404, 'Could not find any Triggered Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { triggered: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { triggered: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomTriggered; diff --git a/src/controllers/gifs/randomWag.js b/src/controllers/v3/gifs/randomWag.js similarity index 60% rename from src/controllers/gifs/randomWag.js rename to src/controllers/v3/gifs/randomWag.js index 964d847..88ad360 100644 --- a/src/controllers/gifs/randomWag.js +++ b/src/controllers/v3/gifs/randomWag.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Wag = require('../../models/schemas/Wag') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Wag from '../../../models/schemas/Wag.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wag -module.exports = async function getRandomWag(req, res, next) { +const getRandomWag = async (req, res, next) => { try { const [result] = await Wag.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Wag Gif')) + return next(createError(404, 'Could not find any Wag Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wag: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wag: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomWag; diff --git a/src/controllers/gifs/randomWave.js b/src/controllers/v3/gifs/randomWave.js similarity index 59% rename from src/controllers/gifs/randomWave.js rename to src/controllers/v3/gifs/randomWave.js index 688491f..195dfb1 100644 --- a/src/controllers/gifs/randomWave.js +++ b/src/controllers/v3/gifs/randomWave.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Wave = require('../../models/schemas/Wave') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Wave from '../../../models/schemas/Wave.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wave -module.exports = async function getRandomWave(req, res, next) { +const getRandomWave = async (req, res, next) => { try { const [result] = await Wave.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Wave Gif')) + return next(createError(404, 'Could not find any Wave Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wave: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wave: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomWave; diff --git a/src/controllers/gifs/randomWink.js b/src/controllers/v3/gifs/randomWink.js similarity index 59% rename from src/controllers/gifs/randomWink.js rename to src/controllers/v3/gifs/randomWink.js index d6b0c17..fb03a57 100644 --- a/src/controllers/gifs/randomWink.js +++ b/src/controllers/v3/gifs/randomWink.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Wink = require('../../models/schemas/Wink') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Wink from '../../../models/schemas/Wink.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wink -module.exports = async function getRandomWink(req, res, next) { +const getRandomWink = async (req, res, next) => { try { const [result] = await Wink.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Wink Gif')) + return next(createError(404, 'Could not find any Wink Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wink: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wink: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomWink; diff --git a/src/controllers/gifs/randomYes.js b/src/controllers/v3/gifs/randomYes.js similarity index 57% rename from src/controllers/gifs/randomYes.js rename to src/controllers/v3/gifs/randomYes.js index 31bdbe8..1408489 100644 --- a/src/controllers/gifs/randomYes.js +++ b/src/controllers/v3/gifs/randomYes.js @@ -1,28 +1,31 @@ -const createError = require('http-errors') -const Yesh = require('../../models/schemas/Yesh') -const Stats = require('../../models/schemas/Stat') -// Get random Anime Yesh -module.exports = async function getRandomYes(req, res, next) { +import createError from 'http-errors'; +import Yesh from '../../../models/schemas/Yesh.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Yes +const getRandomYes = async (req, res, next) => { try { const [result] = await Yesh.aggregate([ // Select a random document from the results { $sample: { size: 1 } }, { $project: { __v: 0, _id: 0 } }, - ]) + ]); if (!result) { - return next(createError(404, 'Could not find any Yes Gif')) + return next(createError(404, 'Could not find any Yes Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { yes: 1 } }) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { yes: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomYes; diff --git a/src/controllers/v3/quotes/randomQuotes.js b/src/controllers/v3/quotes/randomQuotes.js new file mode 100644 index 0000000..9ae2cce --- /dev/null +++ b/src/controllers/v3/quotes/randomQuotes.js @@ -0,0 +1,43 @@ +import createError from 'http-errors'; +import Quotes from '../../../models/schemas/Quote.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime quote with optional character filter and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomQuote = async (req, res, next) => { + try { + const { character } = req.query; + + // Create a filter object based on the optional character parameter + const filter = character ? { author: character } : {}; + + // Aggregate to match the filter, select a random quote, and project excluding version field + const [result] = await Quotes.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + // If no quote is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching Quote')); + } + + // Respond with the random quote + res.status(200).json(result); + + // Update system statistics for quotes + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { quotes: 1 } }); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomQuote; diff --git a/src/controllers/v3/utils/listTags.js b/src/controllers/v3/utils/listTags.js new file mode 100644 index 0000000..f7b15c1 --- /dev/null +++ b/src/controllers/v3/utils/listTags.js @@ -0,0 +1,58 @@ +import Tags from '../../../models/schemas/Tags.js'; +import parseOrder from '../../../modules/parseOrder.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Lists tags with optional sorting and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const listTags = async (req, res, next) => { + try { + let { sortBy, sortOrder } = req.query; + + // Supported parameter values + const Values = { sortBy: ['name', 'usedCount'] }; + // The default sort order depends on the `sortBy` field + const defaultSortOrder = { name: 1, usedCount: -1 }; + + // Validate and set sortBy and sortOrder + sortBy = Values.sortBy.includes(sortBy) ? sortBy : 'name'; + sortOrder = parseOrder(sortOrder) || defaultSortOrder[sortBy] || 1; + + // Aggregate tags, including the count of associated facts, and sort the results + const results = await Tags.aggregate([ + { + $lookup: { + from: 'facts', + localField: 'name', + foreignField: 'tags', + as: 'usedCount', + }, + }, + { $addFields: { usedCount: { $size: '$usedCount' } } }, + { $sort: { [sortBy]: sortOrder } }, + { $project: { __v: 0 } }, + ]); + + // Respond with the sorted tags + res.json(results); + + // Update system statistics for tags + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { tags: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default listTags; diff --git a/src/controllers/v3/utils/owoify.js b/src/controllers/v3/utils/owoify.js new file mode 100644 index 0000000..beb1fa0 --- /dev/null +++ b/src/controllers/v3/utils/owoify.js @@ -0,0 +1,41 @@ +import createError from 'http-errors'; +import owoify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets the Owofied version of the provided text and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + // Check for valid text input + if (!text) { + return next(createError(404, 'Invalid text input.')); + } + + // Owofy the text and send the response + res.status(200).json({ + text: owoify(text), + }); + + // Update system statistics for Owofied texts + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { owoify: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v3/utils/randomPassword.js b/src/controllers/v3/utils/randomPassword.js new file mode 100644 index 0000000..fe65922 --- /dev/null +++ b/src/controllers/v3/utils/randomPassword.js @@ -0,0 +1,44 @@ +import pass from 'generate-password'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Generates a random password with specified characteristics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomPassword = async (req, res, next) => { + try { + const { charLength } = req.query; + + // Generate a random password with specified characteristics + const password = pass.generate({ + length: charLength || 50, + uppercase: true, + numbers: true, + symbols: true, + lowercase: true, + strict: true, + }); + + res.status(200).json({ + pass: password, + }); + + // Update system statistics for generated passwords + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { password: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPassword; diff --git a/src/controllers/v3/utils/user.js b/src/controllers/v3/utils/user.js new file mode 100644 index 0000000..c255b2b --- /dev/null +++ b/src/controllers/v3/utils/user.js @@ -0,0 +1,96 @@ +import crypto from 'crypto'; +import Users from '../../../models/schemas/User.js'; +import generateToken from '../../../modules/generateToken.js'; + +/** + * Handles user-related operations based on the HTTP method. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const userEndpoint = async (req, res, next) => { + try { + const { body, headers, method } = req; + const { key } = headers; + + // Check for valid access key in headers + if (!key || key !== process.env.ACCESS_KEY) { + return res.status(401).json({ + message: 'Unauthorized', + }); + } + + if (method === 'POST') { + const { token, id } = body; + + // Check for required fields in the request body + if (!token || !id) { + return res.status(400).json({ + message: 'Token and User ID are required in the request body', + }); + } + + // Check if the user with the given _id exists + const userExists = await Users.exists({ _id: id }); + + if (!userExists) { + return res.status(404).json({ + message: 'User not found', + }); + } + + // Update user's token in the database + await Users.updateOne({ _id: { $eq: id } }, { $set: { token: token } }); + + return res.status(200).json({ + message: 'Token updated successfully', + }); + } else if (method === 'GET') { + const { id, email, access_token } = headers; + + // Check for required User ID in the headers + if (!id) { + return res.status(400).json({ + message: 'User ID missing in the request body', + }); + } + + // Fetch user details based on the provided user ID + const user = await Users.findOne({ _id: { $eq: id } }); + + if (!user) { + // If user not found, create a new user with the provided ID and token + const newUser = { + _id: id, + email: email, + password: crypto.randomBytes(22).toString('base64'), + token: generateToken(id, process.env.HMAC_KEY), + access_token: access_token, + // Add other fields in the "newUser" object based on your schema + }; + + await Users.create(newUser); + + return res.status(201).json(newUser.token); + } + + // Update user's token in the database + await Users.updateOne( + { _id: { $eq: id } }, + { $set: { access_token: access_token } }, + { upsert: true }, // Create the document if it doesn't exist + ); + + return res.status(200).json(user.token); + } else { + return res.status(405).json({ + message: 'Method Not Allowed', + }); + } + } catch (error) { + return next(error); + } +}; + +export default userEndpoint; diff --git a/src/controllers/v3/utils/uvuify.js b/src/controllers/v3/utils/uvuify.js new file mode 100644 index 0000000..e22dee0 --- /dev/null +++ b/src/controllers/v3/utils/uvuify.js @@ -0,0 +1,30 @@ +import createError from 'http-errors'; +import uwuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + if (!text) { + return next(createError(404, 'Invalid text input.')); + } + + res.status(200).json({ + text: uwuify(text), + }); + + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { uwuify: 1 } } + ); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v3/utils/uwuify.js b/src/controllers/v3/utils/uwuify.js new file mode 100644 index 0000000..02b2f2e --- /dev/null +++ b/src/controllers/v3/utils/uwuify.js @@ -0,0 +1,30 @@ +import createError from 'http-errors'; +import uvuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + if (!text) { + throw createError(404, 'Invalid text input.'); + } + + res.status(200).json({ + text: uvuify(text), + }); + + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { uvuify: 1 } } + ); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v3/waifus/randomWaifus.js b/src/controllers/v3/waifus/randomWaifus.js new file mode 100644 index 0000000..c6d3554 --- /dev/null +++ b/src/controllers/v3/waifus/randomWaifus.js @@ -0,0 +1,22 @@ +import Waifus from '../../../models/schemas/Waifu.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get a random waifu +const getRandomWaifu = async (req, res, next) => { + try { + const [result] = await Waifus.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0 } }, + ]); + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { waifus: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + next(error); + } +}; + +export default getRandomWaifu; diff --git a/src/controllers/v4/images/waifu.js b/src/controllers/v4/images/waifu.js new file mode 100644 index 0000000..fdb4af2 --- /dev/null +++ b/src/controllers/v4/images/waifu.js @@ -0,0 +1,97 @@ +import _ from 'lodash'; +import createError from 'http-errors'; +import Waifus from '../../../models/schemas/Waifu.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random waifu and updates system statistics. + * + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @throws {Error} If there is an error during waifu retrieval or database update. + * + * @returns {Object} JSON object containing the random waifu. + * @example + * // Example usage in Express route handler + * getWaifu(req, res, next); + */ +const getWaifu = async (req, res, next) => { + try { + /** + * Extracts character name and anime parameters from the request query. + * @type {Object} + */ + const { name, anime } = req.query; + + /** + * Holds the filter object based on the optional character name and anime name parameters. + * @type {Object} + */ + const filter = {}; + + /** + * Add conditions to filter object based on request parameters + * @type {Object} + */ + + if (name) { + const sanitizedName = _.escapeRegExp(name.trim()); + filter['names.en'] = { $regex: new RegExp(sanitizedName, 'i') }; // Case-insensitive regex match for English name + } + + if (anime) { + const sanitizedAnime = _.escapeRegExp(anime.trim()); + filter['from.name'] = { $regex: new RegExp(sanitizedAnime, 'i') }; // Case-insensitive regex match for anime name + } + + /** + * Holds the result of the random waifu retrieval. + * @type {Object} + */ + const [result] = await Waifus.aggregate([ + { $match: filter }, // Apply filter conditions (if any) + { $sample: { size: 1 } }, + { $project: { __v: 0 } }, + ]); + + // If no fact is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching waifu')); + } + /** + * Responds with a JSON object containing the random waifu. + * @type {Object} + * @property {Number} _id - The unique identifier of the waifu. + * @property {Object} names - Object containing different names for the waifu (en, jp, alt). + * @property {String} names.en - English name of the waifu. + * @property {String} names.jp - Japanese name of the waifu. + * @property {String} names.alt - Alternate name of the waifu. + * @property {Object} from - Object containing information about the origin of the waifu. + * @property {String} from.name - Name of the source or series. + * @property {String} from.type - Type of the source or series. + * @property {Array} images - Array of image URLs associated with the waifu. + * @property {Object} statistics - Object containing various statistics related to the waifu. + * @property {Number} statistics.fav - Number of favorites for the waifu. + * @property {Number} statistics.love - Number of loves for the waifu. + * @property {Number} statistics.hate - Number of hates for the waifu. + * @property {Number} statistics.upvote - Number of upvotes for the waifu. + * @property {Number} statistics.downvote - Number of downvotes for the waifu. + */ + res.status(200).json(result); + + // Update system statistics for waifus + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { waifus: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + next(error); + } +}; + +export default getWaifu; diff --git a/src/controllers/v4/interactions/angry.js b/src/controllers/v4/interactions/angry.js new file mode 100644 index 0000000..35e8051 --- /dev/null +++ b/src/controllers/v4/interactions/angry.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Angry from '../../../models/schemas/Angry.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Angry +const getRandomAngry = async (req, res, next) => { + try { + const [result] = await Angry.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Angry Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { angry: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomAngry; \ No newline at end of file diff --git a/src/controllers/v4/interactions/baka.js b/src/controllers/v4/interactions/baka.js new file mode 100644 index 0000000..1afa018 --- /dev/null +++ b/src/controllers/v4/interactions/baka.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Baka from '../../../models/schemas/Baka.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Baka +const getRandomBaka = async (req, res, next) => { + try { + const [result] = await Baka.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Baka Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { baka: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomBaka; diff --git a/src/controllers/v4/interactions/bite.js b/src/controllers/v4/interactions/bite.js new file mode 100644 index 0000000..591e677 --- /dev/null +++ b/src/controllers/v4/interactions/bite.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Bite from '../../../models/schemas/Bite.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bite +const getRandomBite = async (req, res, next) => { + try { + const [result] = await Bite.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bite Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bite: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomBite; diff --git a/src/controllers/v4/interactions/blush.js b/src/controllers/v4/interactions/blush.js new file mode 100644 index 0000000..2c698c8 --- /dev/null +++ b/src/controllers/v4/interactions/blush.js @@ -0,0 +1,32 @@ + +import createError from 'http-errors'; +import Blush from '../../../models/schemas/Blush.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Blush +const getRandomBlush = async (req, res, next) => { + try { + const [result] = await Blush.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Blush Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { blush: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBlush; + diff --git a/src/controllers/v4/interactions/bonk.js b/src/controllers/v4/interactions/bonk.js new file mode 100644 index 0000000..bcf4786 --- /dev/null +++ b/src/controllers/v4/interactions/bonk.js @@ -0,0 +1,32 @@ + +import createError from 'http-errors'; +import Bonk from '../../../models/schemas/Bonk.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bonk +const getRandomBonk = async (req, res, next) => { + try { + const [result] = await Bonk.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bonk Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bonk: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } + +}; + +export default getRandomBonk; diff --git a/src/controllers/v4/interactions/bored.js b/src/controllers/v4/interactions/bored.js new file mode 100644 index 0000000..3879136 --- /dev/null +++ b/src/controllers/v4/interactions/bored.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Bored from '../../../models/schemas/Bored.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bored +const getRandomBored = async (req, res, next) => { + try { + const [result] = await Bored.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bored Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bored: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomBored; diff --git a/src/controllers/v4/interactions/bully.js b/src/controllers/v4/interactions/bully.js new file mode 100644 index 0000000..d7ea12b --- /dev/null +++ b/src/controllers/v4/interactions/bully.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Bully from '../../../models/schemas/Bully.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bully +const getRandomBully = async (req, res, next) => { + try { + const [result] = await Bully.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bully Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bully: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomBully; diff --git a/src/controllers/v4/interactions/bye.js b/src/controllers/v4/interactions/bye.js new file mode 100644 index 0000000..3a6ff17 --- /dev/null +++ b/src/controllers/v4/interactions/bye.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Bye from '../../../models/schemas/Bye.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bye +const getRandomBye = async (req, res, next) => { + try { + const [result] = await Bye.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bye Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bye: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomBye; diff --git a/src/controllers/v4/interactions/chase.js b/src/controllers/v4/interactions/chase.js new file mode 100644 index 0000000..f2dfeea --- /dev/null +++ b/src/controllers/v4/interactions/chase.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Chase from '../../../models/schemas/Chase.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Chase +const getRandomChase = async (req, res, next) => { + try { + const [result] = await Chase.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Chase Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { chase: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomChase; diff --git a/src/controllers/v4/interactions/cheer.js b/src/controllers/v4/interactions/cheer.js new file mode 100644 index 0000000..54c4f55 --- /dev/null +++ b/src/controllers/v4/interactions/cheer.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Cheer from '../../../models/schemas/Cheer.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cheer +const getRandomCheer = async (req, res, next) => { + try { + const [result] = await Cheer.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cheer Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cheer: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomCheer; diff --git a/src/controllers/v4/interactions/cringe.js b/src/controllers/v4/interactions/cringe.js new file mode 100644 index 0000000..badd781 --- /dev/null +++ b/src/controllers/v4/interactions/cringe.js @@ -0,0 +1,32 @@ + + +import createError from 'http-errors'; +import Cringe from '../../../models/schemas/Cringe.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cringe +const getRandomCringe = async (req, res, next) => { + try { + const [result] = await Cringe.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cringe Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cringe: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomCringe; diff --git a/src/controllers/v4/interactions/cry.js b/src/controllers/v4/interactions/cry.js new file mode 100644 index 0000000..00c4861 --- /dev/null +++ b/src/controllers/v4/interactions/cry.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Cry from '../../../models/schemas/Cry.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cry +const getRandomCry = async (req, res, next) => { + try { + const [result] = await Cry.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cry Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cry: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomCry; diff --git a/src/controllers/v4/interactions/cuddle.js b/src/controllers/v4/interactions/cuddle.js new file mode 100644 index 0000000..36bdf52 --- /dev/null +++ b/src/controllers/v4/interactions/cuddle.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Cuddle from '../../../models/schemas/Cuddle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cuddle +const getRandomCuddle = async (req, res, next) => { + try { + const [result] = await Cuddle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cuddle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cuddle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomCuddle; diff --git a/src/controllers/v4/interactions/dab.js b/src/controllers/v4/interactions/dab.js new file mode 100644 index 0000000..88f3315 --- /dev/null +++ b/src/controllers/v4/interactions/dab.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Dab from '../../../models/schemas/Dab.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Dab +const getRandomDab = async (req, res, next) => { + try { + const [result] = await Dab.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Dab Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dab: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomDab; diff --git a/src/controllers/v4/interactions/dance.js b/src/controllers/v4/interactions/dance.js new file mode 100644 index 0000000..615a043 --- /dev/null +++ b/src/controllers/v4/interactions/dance.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Dance from '../../../models/schemas/Dance.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Dance +const getRandomDance = async (req, res, next) => { + try { + const [result] = await Dance.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Dance Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dance: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDance; diff --git a/src/controllers/v4/interactions/die.js b/src/controllers/v4/interactions/die.js new file mode 100644 index 0000000..e194b3e --- /dev/null +++ b/src/controllers/v4/interactions/die.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Die from '../../../models/schemas/Die.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Die +const getRandomDie = async (req, res, next) => { + try { + const [result] = await Die.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Die Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { die: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDie; diff --git a/src/controllers/v4/interactions/disgust.js b/src/controllers/v4/interactions/disgust.js new file mode 100644 index 0000000..6c83bb1 --- /dev/null +++ b/src/controllers/v4/interactions/disgust.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Disgust from '../../../models/schemas/Disgust.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Disgust +const getRandomDisgust = async (req, res, next) => { + try { + const [result] = await Disgust.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Disgust Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { disgust: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDisgust; diff --git a/src/controllers/v4/interactions/facepalm.js b/src/controllers/v4/interactions/facepalm.js new file mode 100644 index 0000000..8149def --- /dev/null +++ b/src/controllers/v4/interactions/facepalm.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Facepalm from '../../../models/schemas/Facepalm.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Facepalm +const getRandomFacepalm = async (req, res, next) => { + try { + const [result] = await Facepalm.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Facepalm Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facepalm: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomFacepalm; diff --git a/src/controllers/v4/interactions/feed.js b/src/controllers/v4/interactions/feed.js new file mode 100644 index 0000000..6145e04 --- /dev/null +++ b/src/controllers/v4/interactions/feed.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Feed from '../../../models/schemas/Feed.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Feed +const getRandomFeed = async (req, res, next) => { + try { + const [result] = await Feed.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Feed Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { feed: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomFeed; diff --git a/src/controllers/v4/interactions/glomp.js b/src/controllers/v4/interactions/glomp.js new file mode 100644 index 0000000..3f2e32b --- /dev/null +++ b/src/controllers/v4/interactions/glomp.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Glomp from '../../../models/schemas/Glomp.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Glomp +const getRandomGlomp = async (req, res, next) => { + try { + const [result] = await Glomp.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Glomp Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { glomp: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomGlomp; diff --git a/src/controllers/v4/interactions/happy.js b/src/controllers/v4/interactions/happy.js new file mode 100644 index 0000000..4379c45 --- /dev/null +++ b/src/controllers/v4/interactions/happy.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Happy from '../../../models/schemas/Happy.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Happy +const getRandomHappy = async (req, res, next) => { + try { + const [result] = await Happy.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Happy Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { happy: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomHappy; diff --git a/src/controllers/v4/interactions/hi.js b/src/controllers/v4/interactions/hi.js new file mode 100644 index 0000000..08ffb0f --- /dev/null +++ b/src/controllers/v4/interactions/hi.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Hi from '../../../models/schemas/Hi.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hi +const getRandomHi = async (req, res, next) => { + try { + const [result] = await Hi.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hi Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hi: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomHi; diff --git a/src/controllers/v4/interactions/highfive.js b/src/controllers/v4/interactions/highfive.js new file mode 100644 index 0000000..2f19fea --- /dev/null +++ b/src/controllers/v4/interactions/highfive.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Highfive from '../../../models/schemas/Highfive.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Highfive +const getRandomHighfive = async (req, res, next) => { + try { + const [result] = await Highfive.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Highfive Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { highfive: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHighfive; diff --git a/src/controllers/v4/interactions/hold.js b/src/controllers/v4/interactions/hold.js new file mode 100644 index 0000000..0dddf0d --- /dev/null +++ b/src/controllers/v4/interactions/hold.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Hold from '../../../models/schemas/Hold.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hold +const getRandomHold = async (req, res, next) => { + try { + const [result] = await Hold.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hold Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hold: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHold; diff --git a/src/controllers/v4/interactions/hug.js b/src/controllers/v4/interactions/hug.js new file mode 100644 index 0000000..f619681 --- /dev/null +++ b/src/controllers/v4/interactions/hug.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Hug from '../../../models/schemas/Hug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hug +const getRandomHug = async (req, res, next) => { + try { + const [result] = await Hug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomHug; diff --git a/src/controllers/v4/interactions/kick.js b/src/controllers/v4/interactions/kick.js new file mode 100644 index 0000000..c07b92e --- /dev/null +++ b/src/controllers/v4/interactions/kick.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Kick from '../../../models/schemas/Kick.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kick +const getRandomKick = async (req, res, next) => { + try { + const [result] = await Kick.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kick Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kick: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomKick; diff --git a/src/controllers/v4/interactions/kill.js b/src/controllers/v4/interactions/kill.js new file mode 100644 index 0000000..8e40895 --- /dev/null +++ b/src/controllers/v4/interactions/kill.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Kill from '../../../models/schemas/Kill.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kill +const getRandomKill = async (req, res, next) => { + try { + const [result] = await Kill.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kill Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kill: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomKill; diff --git a/src/controllers/v4/interactions/kiss.js b/src/controllers/v4/interactions/kiss.js new file mode 100644 index 0000000..d2e1b2a --- /dev/null +++ b/src/controllers/v4/interactions/kiss.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Kissu from '../../../models/schemas/Kissu.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kiss +const getRandomKiss = async (req, res, next) => { + try { + const [result] = await Kissu.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kiss Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kissu: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomKiss; diff --git a/src/controllers/v4/interactions/laugh.js b/src/controllers/v4/interactions/laugh.js new file mode 100644 index 0000000..f34b771 --- /dev/null +++ b/src/controllers/v4/interactions/laugh.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Laugh from '../../../models/schemas/Laugh.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Laugh +const getRandomLaugh = async (req, res, next) => { + try { + const [result] = await Laugh.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Laugh Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { laugh: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomLaugh; diff --git a/src/controllers/v4/interactions/lick.js b/src/controllers/v4/interactions/lick.js new file mode 100644 index 0000000..9c50d21 --- /dev/null +++ b/src/controllers/v4/interactions/lick.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Lick from '../../../models/schemas/Lick.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Lick +const getRandomLick = async (req, res, next) => { + try { + const [result] = await Lick.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Lick Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lick: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomLick; diff --git a/src/controllers/v4/interactions/love.js b/src/controllers/v4/interactions/love.js new file mode 100644 index 0000000..bf22105 --- /dev/null +++ b/src/controllers/v4/interactions/love.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Love from '../../../models/schemas/Love.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Love +const getRandomLove = async (req, res, next) => { + try { + const [result] = await Love.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Love Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { love: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomLove; diff --git a/src/controllers/v4/interactions/lurk.js b/src/controllers/v4/interactions/lurk.js new file mode 100644 index 0000000..b0ae8b5 --- /dev/null +++ b/src/controllers/v4/interactions/lurk.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Lurk from '../../../models/schemas/Lurk.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Lurk +const getRandomLurk = async (req, res, next) => { + try { + const [result] = await Lurk.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Lurk Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lurk: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomLurk; diff --git a/src/controllers/v4/interactions/midfing.js b/src/controllers/v4/interactions/midfing.js new file mode 100644 index 0000000..2f1afa0 --- /dev/null +++ b/src/controllers/v4/interactions/midfing.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Midfing from '../../../models/schemas/Midfing.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Midfing +const getRandomMidfing = async (req, res, next) => { + try { + const [result] = await Midfing.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Midfing Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { midfing: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomMidfing; diff --git a/src/controllers/v4/interactions/nervous.js b/src/controllers/v4/interactions/nervous.js new file mode 100644 index 0000000..c3f7b6e --- /dev/null +++ b/src/controllers/v4/interactions/nervous.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Nervous from '../../../models/schemas/Nervous.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nervous +const getRandomNervous = async (req, res, next) => { + try { + const [result] = await Nervous.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nervous Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nervous: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomNervous; diff --git a/src/controllers/v4/interactions/nom.js b/src/controllers/v4/interactions/nom.js new file mode 100644 index 0000000..47f04e2 --- /dev/null +++ b/src/controllers/v4/interactions/nom.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Nom from '../../../models/schemas/Nom.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nom +const getRandomNom = async (req, res, next) => { + try { + const [result] = await Nom.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nom Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nom: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomNom; diff --git a/src/controllers/v4/interactions/nope.js b/src/controllers/v4/interactions/nope.js new file mode 100644 index 0000000..1079cfa --- /dev/null +++ b/src/controllers/v4/interactions/nope.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Nope from '../../../models/schemas/Nope.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nope +const getRandomNope = async (req, res, next) => { + try { + const [result] = await Nope.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nope Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nope: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomNope; diff --git a/src/controllers/v4/interactions/nuzzle.js b/src/controllers/v4/interactions/nuzzle.js new file mode 100644 index 0000000..85b583f --- /dev/null +++ b/src/controllers/v4/interactions/nuzzle.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Nuzzle from '../../../models/schemas/Nuzzle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nuzzle +const getRandomNuzzle = async (req, res, next) => { + try { + const [result] = await Nuzzle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nuzzle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nuzzle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNuzzle; diff --git a/src/controllers/v4/interactions/panic.js b/src/controllers/v4/interactions/panic.js new file mode 100644 index 0000000..dc9a13e --- /dev/null +++ b/src/controllers/v4/interactions/panic.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Panic from '../../../models/schemas/Panic.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Panic +const getRandomPanic = async (req, res, next) => { + try { + const [result] = await Panic.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Panic Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { panic: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPanic; diff --git a/src/controllers/v4/interactions/pat.js b/src/controllers/v4/interactions/pat.js new file mode 100644 index 0000000..3295744 --- /dev/null +++ b/src/controllers/v4/interactions/pat.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Pat from '../../../models/schemas/Pat.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Pat +const getRandomPat = async (req, res, next) => { + try { + const [result] = await Pat.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Pat Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pat: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPat; diff --git a/src/controllers/v4/interactions/peck.js b/src/controllers/v4/interactions/peck.js new file mode 100644 index 0000000..133b904 --- /dev/null +++ b/src/controllers/v4/interactions/peck.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Peck from '../../../models/schemas/Peck.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Peck +const getRandomPeck = async (req, res, next) => { + try { + const [result] = await Peck.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Peck Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { peck: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPeck; diff --git a/src/controllers/v4/interactions/poke.js b/src/controllers/v4/interactions/poke.js new file mode 100644 index 0000000..94e4c9d --- /dev/null +++ b/src/controllers/v4/interactions/poke.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Poke from '../../../models/schemas/Poke.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Poke +const getRandomPoke = async (req, res, next) => { + try { + const [result] = await Poke.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Poke Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { poke: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPoke; diff --git a/src/controllers/v4/interactions/pout.js b/src/controllers/v4/interactions/pout.js new file mode 100644 index 0000000..995232b --- /dev/null +++ b/src/controllers/v4/interactions/pout.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Pout from '../../../models/schemas/Pout.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Pout +const getRandomPout = async (req, res, next) => { + try { + const [result] = await Pout.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Pout Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pout: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPout; diff --git a/src/controllers/v4/interactions/punch.js b/src/controllers/v4/interactions/punch.js new file mode 100644 index 0000000..f9f1d93 --- /dev/null +++ b/src/controllers/v4/interactions/punch.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Punch from '../../../models/schemas/Punch.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Punch +const getRandomPunch = async (req, res, next) => { + try { + const [result] = await Punch.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Punch Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { punch: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomPunch; diff --git a/src/controllers/v4/interactions/run.js b/src/controllers/v4/interactions/run.js new file mode 100644 index 0000000..3005f7a --- /dev/null +++ b/src/controllers/v4/interactions/run.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Run from '../../../models/schemas/Run.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Run +const getRandomRun = async (req, res, next) => { + try { + const [result] = await Run.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Run Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { run: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomRun; diff --git a/src/controllers/v4/interactions/sad.js b/src/controllers/v4/interactions/sad.js new file mode 100644 index 0000000..9b2c660 --- /dev/null +++ b/src/controllers/v4/interactions/sad.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Sad from '../../../models/schemas/Sad.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sad +const getRandomSad = async (req, res, next) => { + try { + const [result] = await Sad.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sad Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sad: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSad; diff --git a/src/controllers/v4/interactions/shoot.js b/src/controllers/v4/interactions/shoot.js new file mode 100644 index 0000000..de561ba --- /dev/null +++ b/src/controllers/v4/interactions/shoot.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Shoot from '../../../models/schemas/Shoot.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Shoot +const getRandomShoot = async (req, res, next) => { + try { + const [result] = await Shoot.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Shoot Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shoot: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomShoot; diff --git a/src/controllers/v4/interactions/shrug.js b/src/controllers/v4/interactions/shrug.js new file mode 100644 index 0000000..10dcf62 --- /dev/null +++ b/src/controllers/v4/interactions/shrug.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Shrug from '../../../models/schemas/Shrug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Shrug +const getRandomShrug = async (req, res, next) => { + try { + const [result] = await Shrug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Shrug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shrug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomShrug; diff --git a/src/controllers/v4/interactions/sip.js b/src/controllers/v4/interactions/sip.js new file mode 100644 index 0000000..9f41a60 --- /dev/null +++ b/src/controllers/v4/interactions/sip.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Sip from '../../../models/schemas/Sip.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sip +const getRandomSip = async (req, res, next) => { + try { + const [result] = await Sip.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sip Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sip: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSip; diff --git a/src/controllers/v4/interactions/slap.js b/src/controllers/v4/interactions/slap.js new file mode 100644 index 0000000..b9a51a2 --- /dev/null +++ b/src/controllers/v4/interactions/slap.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Slap from '../../../models/schemas/Slap.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Slap +const getRandomSlap = async (req, res, next) => { + try { + const [result] = await Slap.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Slap Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { slap: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSlap; diff --git a/src/controllers/v4/interactions/sleepy.js b/src/controllers/v4/interactions/sleepy.js new file mode 100644 index 0000000..b321317 --- /dev/null +++ b/src/controllers/v4/interactions/sleepy.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Sleepy from '../../../models/schemas/Sleepy.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sleepy +const getRandomSleepy = async (req, res, next) => { + try { + const [result] = await Sleepy.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sleepy Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sleepy: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSleepy; diff --git a/src/controllers/v4/interactions/smile.js b/src/controllers/v4/interactions/smile.js new file mode 100644 index 0000000..885057a --- /dev/null +++ b/src/controllers/v4/interactions/smile.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Smile from '../../../models/schemas/Smile.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Smile +const getRandomSmile = async (req, res, next) => { + try { + const [result] = await Smile.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Smile Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smile: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSmile; diff --git a/src/controllers/v4/interactions/smug.js b/src/controllers/v4/interactions/smug.js new file mode 100644 index 0000000..0f6a1f8 --- /dev/null +++ b/src/controllers/v4/interactions/smug.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Smug from '../../../models/schemas/Smug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Smug +const getRandomSmug = async (req, res, next) => { + try { + const [result] = await Smug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Smug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomSmug; diff --git a/src/controllers/v4/interactions/stab.js b/src/controllers/v4/interactions/stab.js new file mode 100644 index 0000000..742b2a1 --- /dev/null +++ b/src/controllers/v4/interactions/stab.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Stab from '../../../models/schemas/Stab.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Stab +const getRandomStab = async (req, res, next) => { + try { + const [result] = await Stab.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Stab Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stab: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomStab; diff --git a/src/controllers/v4/interactions/stare.js b/src/controllers/v4/interactions/stare.js new file mode 100644 index 0000000..6cd83f1 --- /dev/null +++ b/src/controllers/v4/interactions/stare.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Stare from '../../../models/schemas/Stare.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Stare +const getRandomStare = async (req, res, next) => { + try { + const [result] = await Stare.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Stare Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stare: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomStare; diff --git a/src/controllers/v4/interactions/suicide.js b/src/controllers/v4/interactions/suicide.js new file mode 100644 index 0000000..5ba6d1f --- /dev/null +++ b/src/controllers/v4/interactions/suicide.js @@ -0,0 +1,34 @@ + + + + +import createError from 'http-errors'; +import Suicide from '../../../models/schemas/Suicide.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Suicide +const getRandomSuicide = async (req, res, next) => { + try { + const [result] = await Suicide.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Suicide Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { suicide: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSuicide; diff --git a/src/controllers/v4/interactions/tease.js b/src/controllers/v4/interactions/tease.js new file mode 100644 index 0000000..8939709 --- /dev/null +++ b/src/controllers/v4/interactions/tease.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Tease from '../../../models/schemas/Tease.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Tease +const getRandomTease = async (req, res, next) => { + try { + const [result] = await Tease.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Tease Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tease: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomTease; diff --git a/src/controllers/v4/interactions/think.js b/src/controllers/v4/interactions/think.js new file mode 100644 index 0000000..5af4973 --- /dev/null +++ b/src/controllers/v4/interactions/think.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Think from '../../../models/schemas/Think.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Think +const getRandomThink = async (req, res, next) => { + try { + const [result] = await Think.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Think Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { think: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomThink; diff --git a/src/controllers/v4/interactions/thumbsup.js b/src/controllers/v4/interactions/thumbsup.js new file mode 100644 index 0000000..9131cf8 --- /dev/null +++ b/src/controllers/v4/interactions/thumbsup.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Thumbsup from '../../../models/schemas/Thumbsup.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Thumbsup +const getRandomThumbsup = async (req, res, next) => { + try { + const [result] = await Thumbsup.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Thumbsup Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { thumbsup: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomThumbsup; diff --git a/src/controllers/v4/interactions/tickle.js b/src/controllers/v4/interactions/tickle.js new file mode 100644 index 0000000..b7fee1e --- /dev/null +++ b/src/controllers/v4/interactions/tickle.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Tickle from '../../../models/schemas/Tickle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Tickle +const getRandomTickle = async (req, res, next) => { + try { + const [result] = await Tickle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Tickle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tickle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomTickle; diff --git a/src/controllers/v4/interactions/triggered.js b/src/controllers/v4/interactions/triggered.js new file mode 100644 index 0000000..c287eee --- /dev/null +++ b/src/controllers/v4/interactions/triggered.js @@ -0,0 +1,33 @@ + + + +import createError from 'http-errors'; +import Triggered from '../../../models/schemas/Triggered.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Triggered +const getRandomTriggered = async (req, res, next) => { + try { + const [result] = await Triggered.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Triggered Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { triggered: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomTriggered; diff --git a/src/controllers/v4/interactions/wag.js b/src/controllers/v4/interactions/wag.js new file mode 100644 index 0000000..6e32232 --- /dev/null +++ b/src/controllers/v4/interactions/wag.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Wag from '../../../models/schemas/Wag.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wag +const getRandomWag = async (req, res, next) => { + try { + const [result] = await Wag.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wag Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wag: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomWag; diff --git a/src/controllers/v4/interactions/wave.js b/src/controllers/v4/interactions/wave.js new file mode 100644 index 0000000..fb8bd0f --- /dev/null +++ b/src/controllers/v4/interactions/wave.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Wave from '../../../models/schemas/Wave.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wave +const getRandomWave = async (req, res, next) => { + try { + const [result] = await Wave.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wave Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wave: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomWave; diff --git a/src/controllers/v4/interactions/wink.js b/src/controllers/v4/interactions/wink.js new file mode 100644 index 0000000..a33087e --- /dev/null +++ b/src/controllers/v4/interactions/wink.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Wink from '../../../models/schemas/Wink.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wink +const getRandomWink = async (req, res, next) => { + try { + const [result] = await Wink.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wink Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wink: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomWink; diff --git a/src/controllers/v4/interactions/yes.js b/src/controllers/v4/interactions/yes.js new file mode 100644 index 0000000..82e2047 --- /dev/null +++ b/src/controllers/v4/interactions/yes.js @@ -0,0 +1,27 @@ +import createError from 'http-errors'; +import Yesh from '../../../models/schemas/Yesh.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Yes +const getRandomYes = async (req, res, next) => { + try { + const [result] = await Yesh.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Yes Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { yes: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getRandomYes; diff --git a/src/controllers/v4/internal/user.js b/src/controllers/v4/internal/user.js new file mode 100644 index 0000000..b8a2c7c --- /dev/null +++ b/src/controllers/v4/internal/user.js @@ -0,0 +1,141 @@ +import crypto from 'crypto'; +import Users from '../../../models/schemas/User.js'; +import generateToken from '../../../modules/generateToken.js'; + +/** + * Fetches user profile data based on the provided user ID + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * @returns {Object} - User profile data. + */ +const retrieveUserProfile = async (req, res, next) => { + const key = req.headers.key; + // Check for valid access key in headers + if (!key || key !== process.env.ACCESS_KEY) { + return res.status(401).json({ + message: 'Unauthorized', + }); + } + const user = await Users.findById(req.params.id); + if (!user) { + return res.status(404).json({ message: 'User not found' }); // User not found + } + + // This will return the data however it won't be the latest one after updating the token + return res.status(200).json(user); +}; + +/** + * Fetches user profile data based on the provided user ID and Reset Token. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * @returns {Object} - User profile data. + */ +const updateUserToken = async (req, res, next) => { + const key = req.headers.key; + // Check for valid access key in headers + if (!key || key !== process.env.ACCESS_KEY) { + return res.status(401).json({ + message: 'Unauthorized', + }); + } + const user = await Users.findById(req.params.id); + if (!user) { + return res.status(404).json({ message: 'User not found' }); // User not found + } + + // Update user's token in the database + await Users.updateOne( + { _id: { $eq: req.params.id } }, + { $set: { token: generateToken(req.params.id, process.env.HMAC_KEY) } }, + ); + + // This will return the data however it won't be the latest one after updating the token + return res.status(200).json({ + message: 'Token reset successfully.', + }); +}; + +/** + * Handles user-related operations based on the HTTP method. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const userEndpoint = async (req, res, next) => { + try { + const { body, headers, method } = req; + const { key } = headers; + + // Check for valid access key in headers + if (!key || key !== process.env.ACCESS_KEY) { + return res.status(401).json({ + message: 'Unauthorized', + }); + } + + if (method === 'POST') { + const { token, id } = body; + + // Check for required fields in the request body + if (!token || !id) { + return res.status(400).json({ + message: 'Token and User ID are required in the request body', + }); + } + + // Update user's token in the database + await Users.updateOne( + { _id: { $eq: id } }, + { $set: { token: token } }, + { upsert: true }, // Create the document if it doesn't exist + ); + + return res.status(200).json({ + message: 'Token updated successfully', + }); + } else if (method === 'GET') { + const { id, email } = headers; + + // Check for required User ID in the headers + if (!id) { + return res.status(400).json({ + message: 'User ID missing in the request body', + }); + } + + // Fetch user details based on the provided user ID + const user = await Users.findOne({ _id: { $eq: id } }); + + if (!user) { + // If user not found, create a new user with the provided ID and token + const newUser = { + _id: id, + email: email, + password: crypto.randomBytes(22).toString('base64'), + token: generateToken(id, process.env.HMAC_KEY), + // Add other fields in the "newUser" object based on your schema + }; + + await Users.create(newUser); + + return res.status(201).json(newUser.token); + } + + return res.status(200).json(user.token); + } else { + return res.status(405).json({ + message: 'Method Not Allowed', + }); + } + } catch (error) { + return next(error); + } +}; + +export { userEndpoint, retrieveUserProfile, updateUserToken }; diff --git a/src/controllers/v4/textUtilities/fact.js b/src/controllers/v4/textUtilities/fact.js new file mode 100644 index 0000000..1892ddd --- /dev/null +++ b/src/controllers/v4/textUtilities/fact.js @@ -0,0 +1,88 @@ +import createError from 'http-errors'; +import Facts from '../../../models/schemas/Fact.js'; +import tagsFilter from '../../../modules/tagsFilter.js'; +import lengthFilter from '../../../modules/lengthFilter.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime fact with optional length and tags filters and updates system statistics. + * + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @throws {Error} If there is an error during fact retrieval or database update. + * + * @returns {Object} JSON object containing the random fact. + * @property {String} _id - The unique identifier of the fact. + * @property {String} fact - The text of the anime fact. + * @property {Array} tags - Array of tags associated with the fact. + * @property {Number} length - The length of the fact. + * + * @example + * // Example usage in Express route handler + * getFact(req, res, next); + */ +const getFact = async (req, res, next) => { + try { + /** + * Extracts minLength, maxLength, and tags parameters from the request query. + * @type {Object} + */ + const { minLength, maxLength, tags } = req.query; + + /** + * Holds the filter object based on the optional length and tags parameters. + * @type {Object} + */ + const filter = {}; + + // Apply length filter (if minLength or maxLength is provided) + if (minLength || maxLength) { + filter.length = lengthFilter(minLength, maxLength); + } + + // Apply tags filter (if tags are provided) + if (tags) { + filter.tags = tagsFilter(tags); + } + + /** + * Holds the result of the random fact retrieval. + * @type {Object} + */ + const [result] = await Facts.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + // If no fact is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching fact')); + } + + /** + * Responds with a JSON object containing the random fact. + * @type {Object} + * @property {String} _id - The unique identifier of the fact. + * @property {String} fact - The text of the anime fact. + * @property {Array} tags - Array of tags associated with the fact. + * @property {Number} length - The length of the fact. + */ + res.status(200).json(result); + + // Update system statistics for facts + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facts: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getFact; diff --git a/src/controllers/v4/textUtilities/listTags.js b/src/controllers/v4/textUtilities/listTags.js new file mode 100644 index 0000000..1bac190 --- /dev/null +++ b/src/controllers/v4/textUtilities/listTags.js @@ -0,0 +1,81 @@ +import Tags from '../../../models/schemas/Tags.js'; +import parseOrder from '../../../modules/parseOrder.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Lists tags with optional sorting and updates system statistics. + * + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @throws {Error} If there is an error during tag listing or database update. + * + * @returns {Object} JSON object containing the sorted tags. + * @property {Array} results - Array of tags with additional usage count information. + * @property {String} results[].name - The name of the tag. + * @property {Number} results[].usedCount - The count of associated facts using the tag. + * + * @example + * // Example usage in Express route handler + * listTags(req, res, next); + */ +const listTags = async (req, res, next) => { + try { + /** + * Extracts sortBy and sortOrder parameters from the request query. + * @type {Object} + */ + let { sortBy, sortOrder } = req.query; + + // Supported parameter values + const Values = { sortBy: ['name', 'usedCount'] }; + // The default sort order depends on the `sortBy` field + const defaultSortOrder = { name: 1, usedCount: -1 }; + + // Validate and set sortBy and sortOrder + sortBy = Values.sortBy.includes(sortBy) ? sortBy : 'name'; + sortOrder = parseOrder(sortOrder) || defaultSortOrder[sortBy] || 1; + + /** + * Aggregate tags, including the count of associated facts, and sort the results + * Holds the results of the tag listing. + * @type {Array} + */ + const results = await Tags.aggregate([ + { + $lookup: { + from: 'facts', + localField: 'name', + foreignField: 'tags', + as: 'usedCount', + }, + }, + { $addFields: { usedCount: { $size: '$usedCount' } } }, + { $sort: { [sortBy]: sortOrder } }, + { $project: { __v: 0 } }, + ]); + + /** + * Responds with a JSON object containing the sorted tags. + * @type {Object} + * @property {Array} results - Array of tags with additional usage count information. + * @property {String} results[].name - The name of the tag. + * @property {Number} results[].usedCount - The count of associated facts using the tag. + */ + res.json(results); + + // Update system statistics for tags + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tags: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default listTags; diff --git a/src/controllers/v4/textUtilities/owoify.js b/src/controllers/v4/textUtilities/owoify.js new file mode 100644 index 0000000..15213b4 --- /dev/null +++ b/src/controllers/v4/textUtilities/owoify.js @@ -0,0 +1,59 @@ +import createError from 'http-errors'; +import owoify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets the Owofied version of the provided text and updates system statistics. + * + * @function + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @throws {Error} If there is an error during Owofication or database update. + * + * @returns {Object} JSON object containing the Owofied text. + * @property {String} text - The Owofied version of the provided text. + * + * @example + * // Example usage in Express route handler + * getOwoifyText(req, res, next); + */ +const getOwoifyText = async (req, res, next) => { + try { + /** + * Extracts the text to be Owofied from the request query. + * @type {String} + */ + const { text } = req.query; + + // Check for valid text input + if (!text) { + return next(createError(404, 'Invalid text input.')); + } + + /** + * Owofies the text and sends the response. + * @type {Object} + * @property {String} text - The Owofied version of the provided text. + */ + res.status(200).json({ + text: owoify(text), + }); + + /** + * Update system statistics for Owofied texts + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { owoify: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getOwoifyText; diff --git a/src/controllers/v4/textUtilities/password.js b/src/controllers/v4/textUtilities/password.js new file mode 100644 index 0000000..c04e539 --- /dev/null +++ b/src/controllers/v4/textUtilities/password.js @@ -0,0 +1,62 @@ +import pass from 'generate-password'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Generates a random password with specified characteristics. + * + * @function + * @async + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + * + * @throws {Error} If there is an error during the password generation or database update. + * + * @returns {Object} JSON object containing the generated password. + * @property {String} pass - The generated password. + * + * @example + * // Example usage in Express route handler + * getPassword(req, res, next); + */ +const getPassword = async (req, res, next) => { + try { + /** + * Extracts the desired character length for the password. + * @type {number} + * @default 50 + */ + const { charLength } = req.query; + + // Generate a random password with specified characteristics + const password = pass.generate({ + length: charLength || 50, + uppercase: true, + numbers: true, + symbols: true, + lowercase: true, + strict: true, + }); + + /** + * Responds with a JSON object containing the generated password. + * @type {Object} + * @property {String} pass - The generated password. + */ + res.status(200).json({ + pass: password, + }); + + // Update system statistics for generated passwords + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { password: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getPassword; diff --git a/src/controllers/v4/textUtilities/quote.js b/src/controllers/v4/textUtilities/quote.js new file mode 100644 index 0000000..a675a96 --- /dev/null +++ b/src/controllers/v4/textUtilities/quote.js @@ -0,0 +1,65 @@ +import createError from 'http-errors'; +import Quotes from '../../../models/schemas/Quote.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime quote with optional character filter and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getQuote = async (req, res, next) => { + try { + /** + * Extract character parameter from the query + * @type {string} + */ + const { character } = req.query; + + /** + * Create a filter object based on the optional character parameter + * @type {Object} + */ + const filter = character ? { author: character } : {}; + + /** + * Aggregate to match the filter, select a random quote, and project excluding version field + * @type {Array} + */ + const [result] = await Quotes.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + /** + * If no quote is found, return a 404 error + * @type {Object} + */ + if (!result) { + return next(createError(404, 'Could not find any matching Quote')); + } + + /** + * Respond with the random quote + * @type {Object} + */ + res.status(200).json(result); + + /** + * Update system statistics for quotes + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { quotes: 1 } }); + } catch (error) { + /** + * Update system statistics for failed requests + * @type {Object} + */ + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getQuote; diff --git a/src/controllers/v4/textUtilities/uvuify.js b/src/controllers/v4/textUtilities/uvuify.js new file mode 100644 index 0000000..1bfe5a9 --- /dev/null +++ b/src/controllers/v4/textUtilities/uvuify.js @@ -0,0 +1,35 @@ +import createError from 'http-errors'; +import uvuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Route handler to get UvUified text. + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getUvuifyText = async (req, res, next) => { + try { + // Extract text from query parameters + const { text } = req.query; + + // Validate text input + if (!text) { + return next(createError(400, 'Invalid text input.')); + } + + // UvUify the text and send the response + res.status(200).json({ + text: uvuify(text), + }); + + // Increment the UvUify counter in the stats + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { uvuify: 1 } }); + } catch (error) { + // Increment failed requests counter in the stats and pass the error to the next middleware + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + return next(error); + } +}; + +export default getUvuifyText; diff --git a/src/controllers/v4/textUtilities/uwuify.js b/src/controllers/v4/textUtilities/uwuify.js new file mode 100644 index 0000000..3b79d7a --- /dev/null +++ b/src/controllers/v4/textUtilities/uwuify.js @@ -0,0 +1,35 @@ +import createError from 'http-errors'; +import uwuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Route handler to get UwUified text. + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getUwuifyText = async (req, res, next) => { + try { + // Extract text from query parameters + const { text } = req.query; + + // Validate text input + if (!text) { + throw createError(400, 'Invalid text input.'); + } + + // UwUify the text and send the response + res.status(200).json({ + text: uwuify(text), + }); + + // Increment the UwUify counter in the stats + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { uwuify: 1 } }); + } catch (error) { + // Increment failed requests counter in the stats and pass the error to the next middleware + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { failed_requests: 1 } }); + next(error); + } +}; + +export default getUwuifyText; diff --git a/src/controllers/waifus/randomWaifus.js b/src/controllers/waifus/randomWaifus.js deleted file mode 100644 index 0b9b3b8..0000000 --- a/src/controllers/waifus/randomWaifus.js +++ /dev/null @@ -1,26 +0,0 @@ -const Waifus = require('../../models/schemas/Waifus') -const Stats = require('../../models/schemas/Stat') - -// Get a random waifu -module.exports = async function getRandomWaifu(req, res, next) { - try { - const [result] = await Waifus.aggregate([ - // Select a random document from the results - { $sample: { size: 1 } }, - { $project: { __v: 0 } }, - ]) - - res.status(200).json(result) - - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { waifus: 1 } } - ) - } catch (error) { - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { failed_requests: 1 } } - ) - return next(error) - } -} diff --git a/src/frontend/index.html b/src/frontend/index.html deleted file mode 100644 index e6ddb1b..0000000 --- a/src/frontend/index.html +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - Waifu.it - - - - - - - - diff --git a/src/frontend/public/android-chrome-192x192.png b/src/frontend/public/android-chrome-192x192.png deleted file mode 100644 index 691935c..0000000 Binary files a/src/frontend/public/android-chrome-192x192.png and /dev/null differ diff --git a/src/frontend/public/android-chrome-512x512.png b/src/frontend/public/android-chrome-512x512.png deleted file mode 100644 index ef8f9ac..0000000 Binary files a/src/frontend/public/android-chrome-512x512.png and /dev/null differ diff --git a/src/frontend/public/apple-touch-icon.png b/src/frontend/public/apple-touch-icon.png deleted file mode 100644 index b381537..0000000 Binary files a/src/frontend/public/apple-touch-icon.png and /dev/null differ diff --git a/src/frontend/public/favicon-16x16.png b/src/frontend/public/favicon-16x16.png deleted file mode 100644 index 41b415d..0000000 Binary files a/src/frontend/public/favicon-16x16.png and /dev/null differ diff --git a/src/frontend/public/favicon-32x32.png b/src/frontend/public/favicon-32x32.png deleted file mode 100644 index f239004..0000000 Binary files a/src/frontend/public/favicon-32x32.png and /dev/null differ diff --git a/src/frontend/public/favicon.ico b/src/frontend/public/favicon.ico deleted file mode 100644 index a2efdd8..0000000 Binary files a/src/frontend/public/favicon.ico and /dev/null differ diff --git a/src/frontend/public/logo192.png b/src/frontend/public/logo192.png deleted file mode 100644 index c96d36f..0000000 Binary files a/src/frontend/public/logo192.png and /dev/null differ diff --git a/src/frontend/public/logo512.png b/src/frontend/public/logo512.png deleted file mode 100644 index e4f2b6d..0000000 Binary files a/src/frontend/public/logo512.png and /dev/null differ diff --git a/src/frontend/styles.css b/src/frontend/styles.css deleted file mode 100644 index c71d360..0000000 --- a/src/frontend/styles.css +++ /dev/null @@ -1,139 +0,0 @@ -body { - background-color: white; - padding: 0; - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, - Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; -} - -a { - color: inherit; - text-decoration: none; -} - -* { - box-sizing: border-box; -} - -.container { - min-height: 100vh; - padding: 0 0.5rem; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; -} - -.main { - padding: 5rem 0; - flex: 1; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; -} - -.footer { - width: 100%; - height: 100px; - border-top: 1px solid #eaeaea; - display: flex; - justify-content: center; - align-items: center; -} - -.footer img { - margin-left: 0.5rem; -} - -.footer a { - display: flex; - justify-content: center; - align-items: center; -} - -.title a { - color: #0070f3; - text-decoration: none; -} - -.title a:hover, -.title a:focus, -.title a:active { - text-decoration: underline; -} - -.title { - margin: 0; - line-height: 1.15; - font-size: 4rem; -} - -.title, -.description { - text-align: center; -} - -.description { - line-height: 1.5; - font-size: 1.5rem; -} - -.code { - background: #fafafa; - border-radius: 5px; - padding: 0.75rem; - font-size: 1.1rem; - font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, - Bitstream Vera Sans Mono, Courier New, monospace; -} - -.grid { - display: flex; - align-items: center; - justify-content: center; - flex-wrap: wrap; - max-width: 800px; - margin-top: 3rem; -} - -.card { - margin: 1rem; - flex-basis: 45%; - padding: 1.5rem; - text-align: left; - color: inherit; - text-decoration: none; - border: 1px solid #eaeaea; - border-radius: 10px; - transition: color 0.15s ease, border-color 0.15s ease; -} - -.card:hover, -.card:focus, -.card:active { - color: #0070f3; - border-color: #0070f3; -} - -.card h3 { - margin: 0 0 1rem 0; - font-size: 1.5rem; -} - -.card p { - margin: 0; - font-size: 1.25rem; - line-height: 1.5; -} - -.logo { - height: 1em; -} - -@media (max-width: 600px) { - .grid { - width: 100%; - flex-direction: column; - } -} diff --git a/src/handlers/auth/index.js b/src/handlers/auth/index.js deleted file mode 100644 index 2dbe53f..0000000 --- a/src/handlers/auth/index.js +++ /dev/null @@ -1,69 +0,0 @@ -const createError = require('http-errors') -const Users = require('../../models/schemas/Users') -const Stats = require('../../models/schemas/Stat') - -module.exports = async function authHandler(req, res, next) { - try { - // Request Header AUTH var - const key = req.headers.authorization - // Verifies if the {auth} exists in the database - const userData = await Users.findOneAndUpdate( - { token: key }, - { $inc: { req_quoto: -1, req_count: 1 } } - ) - - // @returns if the user has not provided token in header - if (!userData) { - await Stats.findByIdAndUpdate( - { _id: 'systemstats' }, - { - $inc: { - failed_requests: 1, - endpoints_requests: 1, - daily_requests: 1, - }, - } - ) - return next( - createError( - 401, - 'Invalid API key. Go to https://docs.waifu.it for more info.' - ) - ) - } - // @returns if the user is banned - if (userData.banned) { - await Stats.findByIdAndUpdate( - { _id: 'systemstats' }, - { - $inc: { - banned_requests: 1, - endpoints_requests: 1, - daily_requests: 1, - }, - } - ) - return next(createError(403, "You've been banned from using the API.")) - } - // If request limit exhausted throw this [ Currently Disabled ] - // if (userData.req_quoto <= 0) { - // return next( - // createError( - // 403, - // "You've exhausted your request limits. Buy Premium to increase it more." - // ) - // ) - // } - - await Stats.findByIdAndUpdate( - { _id: 'systemstats' }, - { - $inc: { endpoints_requests: 1, success_requests: 1, daily_requests: 1 }, - } - ) - - return next() - } catch (error) { - return next(error) - } -} diff --git a/src/handlers/errors/index.js b/src/handlers/errors/index.js deleted file mode 100644 index df639ee..0000000 --- a/src/handlers/errors/index.js +++ /dev/null @@ -1,22 +0,0 @@ -const createError = require('http-errors') -const chalk = require('chalk') - -// Handles 404 errors -module.exports.handler404 = function handler404(req, res, next) { - return next(createError(404, 'The requested resource could not be found')) -} - -module.exports.errorsLogger = function errorsLogger(error, req, res, next) { - if (process.env.NODE_ENV === 'development') { - /* eslint-disable-next-line no-console */ - console.error(chalk.red('[ERROR]'), error.stack) - } - return next(error) -} - -// Sends error response to client -module.exports.errorsHandler = function errorsHandler(error, req, res, next) { - const statusCode = error.status || 500 - const statusMessage = error.message || 'Internal server error' - res.status(statusCode).json({ statusCode, statusMessage }) -} diff --git a/src/handlers/logger/ip.js b/src/handlers/logger/ip.js deleted file mode 100644 index 5757c75..0000000 --- a/src/handlers/logger/ip.js +++ /dev/null @@ -1,28 +0,0 @@ -// const fs = require('fs') -const requestIp = require('request-ip') -const { Webhook } = require('discord-webhook-node') -const hook = new Webhook(process.env.DISCORD_WEBHOOK_URL) - -// Logger In One File -module.exports.ipLogger = function ipLogger(req, res, next) { - let auth = req.headers.auth - if (!auth) { - auth = 'Null Auth' - } - const log = `${new Date()} - STATUS=${res.statusCode} - METHOD=${ - req.method - } - IP=${req.ip} | ${requestIp.getClientIp(req)} - URL=${ - req.originalUrl - } - ${auth}\n` - const IMAGE_URL = 'https://homepages.cae.wisc.edu/~ece533/images/airplane.png' - hook.setUsername('API Logger') - hook.setAvatar(IMAGE_URL) - hook.send(`\`${log}\``) - - // fs.appendFile('./logs/ip-logs.log', log, err => { - // if (err) throw err - // }) - console.log(log) - - next() -} diff --git a/src/index.js b/src/index.js index 69fdd44..8e271ff 100644 --- a/src/index.js +++ b/src/index.js @@ -1,94 +1,68 @@ /* eslint-disable no-console */ -require('dotenv').config() -const mongoose = require('mongoose') -const chalk = require('chalk') -const app = require('./app') - -// PORT -const PORT = process.env.PORT || 4000 - -// NODE ENV LOGGER -if (process.env.NODE_ENV === 'development') { - console.log( - `${chalk.yellow( - '[DEBUG]' - )} You've enabled developer mode. Now your console will be dirty.` - ) -} - -// Connect to database, then start's the Express server -mongoose - .connect(process.env.MONGODB_URI, { - useUnifiedTopology: true, - useNewUrlParser: true, - useCreateIndex: true, - useFindAndModify: false, - }) - .then(() => { - app.listen(PORT, () => - console.log( - `${chalk.green( - '[SUCCESS]' - )} API is running on: http://localhost:${PORT}/api` - ) - ) - }) - .catch(error => { - console.error(error) - }) - -// const Users = require('./models/schemas/Users') - -// // function to reset token of every user once every 24 hours -// const quotoInterval = setInterval(() => { -// // query and update all users req_quoto to 250 -// Users.updateMany({}, { $set: { req_quoto: 25 } }, (err, res) => { -// if (err) console.log(err) -// console.log(res) -// }) -// }, 5000) - - - - -// const Stats = require('./models/schemas/Stat'); - -// function to reset daily_requests to 0 every 24 hours at 00:00 AM GMT+0 -// setInterval(() => { - -// Stats.findByIdAndUpdate( -// { _id: "systemstats" }, -// { $set: { daily_requests: 0 } } -// ) -// .then(() => { -// console.log(`${chalk.green('[SUCCESS]')} Daily requests reset to 0`) -// }) -// .catch(error => { -// console.error(error) -// }) -// }, 86400000) - - -// a interval to update the daily_requests at 00:00 AM GMT+0 -// setInterval(() => { -// Stats.findByIdAndUpdate( -// { _id: "systemstats" }, -// { $inc: { daily_requests: 1 } } -// ) -// .then(() => { -// console.log(`${chalk.green('[SUCCESS]')} Daily requests incremented`) -// }) -// .catch(error => { -// console.error(error) -// }) -// }, 1000) - - - -// function to reset daily_requests to 0 every 24 hours at 00:00 AM GMT+0 using unix timestamp - - - - - +// Importing configuration modules +import '../config.js'; +import 'dotenv/config'; + +// Importing external modules +import mongoose from 'mongoose'; +import chalk from 'chalk'; +import app from './app.js'; + +/** + * Server setup script for initializing the Express server and connecting to the MongoDB database. + * + * @function + * @throws {Error} If there is an error during database connection or server start. + * + * @returns {void} + */ +const setupServer = async () => { + try { + /** + * Setting up the server port. + * @type {number} + */ + const PORT = process.env.PORT || 4000; + + /** + * Logging developer mode information for the Node environment. + * @type {string} + */ + if (process.env.NODE_ENV === 'development') { + console.log(`${chalk.yellow('[DEBUG]')} Developer mode enabled. Console logging is active.`); + } + + /** + * Connecting to the MongoDB database. + * @type {mongoose.Connection} + */ + const dbConnection = await mongoose.connect(process.env.MONGODB_URI, { + useUnifiedTopology: true, + useNewUrlParser: true, + useCreateIndex: true, + useFindAndModify: false, + }); + + /** + * Starting the Express server and logging success message. + * @type {void} + */ + app.listen(PORT, () => { + console.log(`${chalk.green('[SUCCESS]')} API is running on: http://localhost:${PORT}/api`); + }); + + // Return the database connection for potential future use + return dbConnection; + } catch (error) { + /** + * Logging errors during database connection or server start. + * @type {Error} + */ + console.error(error); + throw error; + } +}; + +// Call the setup function +setupServer(); diff --git a/src/middlewares/authorize.js b/src/middlewares/authorize.js new file mode 100644 index 0000000..ba6deda --- /dev/null +++ b/src/middlewares/authorize.js @@ -0,0 +1,128 @@ +import createError from 'http-errors'; +import Users from '../models/schemas/User.js'; +import Stats from '../models/schemas/Stat.js'; + +/** + * Middleware for handling user authentication and request validation. + * + * @function + * @param {string} requiredRole - The required role to access the endpoint. + * @returns {function} - Express middleware function. + * @throws {Error} Throws an error if there is an issue with authentication or validation. + * + * @error {400} Bad Request - User has not provided a valid token. + * @error {401} Unauthorized - User has provided an invalid API key. + * @error {403} Forbidden - User is banned, request limit is exhausted, or insufficient privileges. + */ +const authorize = requiredRole => async (req, res, next) => { + try { + /** + * Extract API key from request headers. + * + * @type {string} + */ + const key = req.headers.authorization; + + /** + * Handle case where the user has not provided a valid token. + */ + if (!key) { + await incrementSystemStats({ + endpoints_requests: 1, + daily_requests: 1, + }); + return next(createError(400, 'Bad Request. Go to https://docs.waifu.it for more info.')); + } + + /** + * Verify if the API key exists in the database. + * + * @type {Object|null} + */ + const userData = await Users.findOne({ token: key }); + + /** + * Update request quotas and count. + * + * @type {Object} + */ + const updateData = { + $inc: { + req_quota: userData && userData.req_quota > 0 ? -1 : 0, + req_count: userData ? 1 : 0, + }, + }; + await Users.updateOne({ token: key }, updateData); + + /** + * Handle case where the user has not provided a valid token. + */ + if (!userData) { + await incrementSystemStats({ + failed_requests: 1, + endpoints_requests: 1, + daily_requests: 1, + }); + return next(createError(401, 'Invalid API key. Go to https://docs.waifu.it for more info.')); + } + + /** + * Handle case where the user is banned. + */ + if (userData.banned) { + await incrementSystemStats({ + banned_requests: 1, + endpoints_requests: 1, + daily_requests: 1, + }); + return next(createError(403, "You've been banned from using the API.")); + } + + /** + * Handle case where the request limit is exhausted. + */ + if (userData.req_quota <= 0) { + return next(createError(403, "You've exhausted your request limits.")); + } + + /** + * Check if the user has the required role. + */ + if (!userData.roles.includes(requiredRole)) { + return next(createError(403, 'Insufficient privileges to access this endpoint.')); + } + + /** + * Increment system stats for successful requests. + */ + await incrementSystemStats({ + endpoints_requests: 1, + success_requests: 1, + daily_requests: 1, + }); + + /** + * Call the next middleware. + */ + return next(); + } catch (error) { + /** + * Pass any caught errors to the error handler. + */ + return next(error); + } +}; + +/** + * Increment the specified statistics in the system stats collection. + * + * @function + * @param {Object} stats - Statistics to be incremented. + * @returns {Promise} - Resolves when the stats are updated. + * @throws {Error} Throws an error if there is an issue with updating statistics. + */ +const incrementSystemStats = async stats => { + await Stats.findByIdAndUpdate({ _id: 'systemstats' }, { $inc: stats }); +}; + +export default authorize; diff --git a/src/middlewares/database/add.js b/src/middlewares/database/add.js new file mode 100644 index 0000000..d3c4393 --- /dev/null +++ b/src/middlewares/database/add.js @@ -0,0 +1,81 @@ +/** + * Middleware to increment data with a new document in the specified schema. + * + * @param {string} schemaName - The name of the schema to use for data incrementation. + * @returns {Function} Express middleware function. + */ +const incrementData = schemaName => async (req, res, next) => { + try { + /** + * Dynamically import the schema based on the provided schemaName. + * @type {import('../../models/schemas').default} + */ + const schema = await import(`../../models/schemas/${schemaName}.js`); + + /** + * Extract the data from the request body. + */ + const data = req.body; + if (!data) { + return res.status(400).json({ error: 'Missing data body' }); + } + + /** + * Find the document with the highest _id value. + * @type {import('../../models/schemas').default} + */ + const highestIdDocument = await schema.default.findOne({}, {}, { sort: { _id: -1 } }); + + /** + * Calculate the next _id value. + */ + const nextItemId = (highestIdDocument && highestIdDocument._id ? highestIdDocument._id : 0) + 1; + + /** + * Create a new document with the incremented _id and other data. + */ + const newItem = { _id: nextItemId, ...data }; // Spread the properties of data + + /** + * Save the new document. + */ + const result = await schema.default.create(newItem); + + /** + * Respond with a JSON object indicating successful data addition. + */ + res.status(200).json({ + status: '200', + message: 'Data added successfully', + result, + }); + } catch (error) { + /** + * @errorHandling + * Determine the appropriate error message based on the type of error caught. + */ + let errorMessage = 'Internal Server Error'; + + switch (true) { + case error.code === 11000: + errorMessage = 'Duplicate key value'; + break; + + case error.name === 'ValidationError': + errorMessage = 'Missing key value'; + break; + } + + /** + * Log the encountered error for further investigation. + */ + console.error('Error encountered while adding data:', error); + + /** + * Respond with a JSON object containing the determined error message and a 500 Internal Server Error status. + */ + res.status(500).json({ error: errorMessage }); + } +}; + +export default incrementData; diff --git a/src/middlewares/database/delete.js b/src/middlewares/database/delete.js new file mode 100644 index 0000000..ea52685 --- /dev/null +++ b/src/middlewares/database/delete.js @@ -0,0 +1,63 @@ +/** + * Middleware to delete data from the specified schema based on the provided _id. + * + * @param {string} schemaName - The name of the schema to use for data deletion. + * @returns {Function} Express middleware function. + */ +const deleteData = schemaName => async (req, res, next) => { + try { + /** + * Dynamically import the schema based on the provided schemaName. + * @type {import('../../models/schemas').default} + */ + const schema = await import(`../../models/schemas/${schemaName}.js`); + + /** + * Check if _id is provided in the request parameters. + * @type {string} + */ + const requestedId = req.params.id; + if (!requestedId) { + return res.status(400).json({ error: 'Missing id parameter' }); + } + + /** + * Find the document with the specified _id. + * @type {import('../../models/schemas').default} + */ + const existingItem = await schema.default.findById(requestedId); + + /** + * Check if the document exists. + */ + if (!existingItem) { + return res.status(404).json({ error: 'Document not found' }); + } + + /** + * Delete the document. + */ + await existingItem.remove(); + + /** + * Respond with a JSON object indicating successful data deletion. + */ + res.status(200).json({ + status: '200', + message: 'Data deleted successfully', + result: existingItem, + }); + } catch (error) { + /** + * Log the encountered error for further investigation. + */ + console.error('Error deleting data:', error); + + /** + * Respond with a JSON object containing a generic error message and a 500 Internal Server Error status. + */ + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export default deleteData; diff --git a/src/middlewares/database/update.js b/src/middlewares/database/update.js new file mode 100644 index 0000000..b96599b --- /dev/null +++ b/src/middlewares/database/update.js @@ -0,0 +1,84 @@ +/** + * Middleware to update data in the specified schema based on the provided _id. + * + * @param {string} schemaName - The name of the schema to use for data updating. + * @returns {Function} Express middleware function. + */ +const updateData = schemaName => async (req, res, next) => { + try { + /** + * Dynamically import the schema based on the provided schemaName. + * @type {import('../../models/schemas').default} + */ + const schema = await import(`../../models/schemas/${schemaName}.js`); + + /** + * Extract the data from the request body. + */ + const data = req.body; + if (!data) { + return res.status(400).json({ error: 'Missing data body' }); + } + + /** + * Check if _id is provided in the request parameters. + * @type {string} + */ + const requestedId = req.params.id; + if (!requestedId) { + return res.status(400).json({ error: 'Missing id parameter' }); + } + + /** + * Find the document with the specified _id. + * @type {import('../../models/schemas').default} + */ + const existingItem = await schema.default.findById(requestedId); + + /** + * Check if the document exists. + */ + if (!existingItem) { + return res.status(404).json({ error: 'Document not found' }); + } + + /** + * Update the existing document with the new data. + */ + Object.assign(existingItem, data); + + /** + * Save the updated document. + */ + const result = await existingItem.save(); + + /** + * Respond with a JSON object indicating successful data update. + */ + res.status(200).json({ + status: '200', + message: 'Data updated successfully', + result, + }); + } catch (error) { + /** + * @errorHandling + * Handle specific error cases and respond accordingly. + */ + if (error.code === 11000) { + return res.status(500).json({ error: 'Duplicate key value' }); + } + + /** + * Log the encountered error for further investigation. + */ + console.error('Error updating data:', error); + + /** + * Respond with a JSON object containing a generic error message and a 500 Internal Server Error status. + */ + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export default updateData; diff --git a/src/middlewares/errors.js b/src/middlewares/errors.js new file mode 100644 index 0000000..8117c89 --- /dev/null +++ b/src/middlewares/errors.js @@ -0,0 +1,40 @@ +import createError from 'http-errors'; +import chalk from 'chalk'; + +/** + * Middleware to handle 404 errors. + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +export const handle404 = (req, res, next) => { + next(createError(404, 'The requested resource could not be found')); +}; + +/** + * Middleware to log errors. + * @param {Error} error - The error object. + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +export const logErrors = (error, req, res, next) => { + if (process.env.NODE_ENV === 'development') { + /* eslint-disable-next-line no-console */ + console.error(chalk.red('[ERROR]'), error.stack); + } + next(error); +}; + +/** + * Middleware to send error response to the client. + * @param {Error} error - The error object. + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +export const errorHandler = (error, req, res, next) => { + const statusCode = error.status || 500; + const statusMessage = error.message || 'Internal server error'; + res.status(statusCode).json({ statusCode, statusMessage }); +}; diff --git a/src/middlewares/logger.js b/src/middlewares/logger.js new file mode 100644 index 0000000..37cc5a2 --- /dev/null +++ b/src/middlewares/logger.js @@ -0,0 +1,25 @@ +import requestIp from 'request-ip'; +import { Webhook } from 'discord-webhook-node'; + +const hook = new Webhook(process.env.DISCORD_WEBHOOK_URL); + +export const logIP = (req, res, next) => { + const auth = req.headers.authorization || 'Null Auth'; + + const log = `${new Date()} - STATUS=${res.statusCode} - METHOD=${req.method} - IP=${req.ip} | ${requestIp.getClientIp( + req, + )} - URL=${req.originalUrl} - ${auth}\n`; + + const IMAGE_URL = 'https://homepages.cae.wisc.edu/~ece533/images/airplane.png'; + hook.setUsername('API Logger'); + hook.setAvatar(IMAGE_URL); + hook.send(`\`${log}\``); + + // fs.appendFile('./logs/ip-logs.log', log, (err) => { + // if (err) throw err; + // }); + + console.log(log); + + next(); +}; diff --git a/src/middlewares/rateLimit.js b/src/middlewares/rateLimit.js new file mode 100644 index 0000000..0059530 --- /dev/null +++ b/src/middlewares/rateLimit.js @@ -0,0 +1,66 @@ +import rateLimit from 'express-rate-limit'; +import Users from '../models/schemas/User.js'; + +/** + * @function createRateLimiter + * @description Create and return the rate limiter middleware. + * @returns {Function} Express middleware for rate limiting. + * + * @example + * // Basic usage + * const limiter = createRateLimiter(); + * app.use('/api/route', limiter); + * + * @example + * // Customized options + * const customOptions = { + * windowMs: 15 * 60 * 1000, // 15 minutes + * max: 100, // limit each IP to 100 requests per windowMs + * message: 'Too many requests from this IP, please try again after a few minutes.', + * }; + * const customLimiter = createRateLimiter(customOptions); + * app.use('/api/customRoute', customLimiter); + */ +const createRateLimiter = () => { + /** + * @typedef {Object} RateLimitOptions + * @property {number} [windowMs=60 * 1000] - The time window for which the requests are checked/metered (in milliseconds). + * @property {function|number} [max=20] - The maximum number of allowed requests within the windowMs time frame. Can be a function that receives the request object. + * @property {string|object} [message] - The message sent in the response when the limit is exceeded. + * @property {number} [message.status=429] - The HTTP status code to be set in the response. + * @property {string} [message.message='You've exhausted your ratelimit, please try again later.'] - The message to be sent in the response. + */ + + /** + * @type {RateLimitOptions} + */ + const defaultOptions = { + windowMs: 60 * 1000, // 1 minute + max: async (req) => { + try { + // Get the user's token from the request headers + const token = req.headers.authorization; + + // Fetch user data from the database based on the token + const user = await Users.findOne({ token }); + + // Return the user's rate limit from the database or default to 20 if not found + return user ? user.rateLimit : 20; + } catch (error) { + console.error('Error fetching user data:', error.message); + return 20; // Default to 20 if there is an error + } + }, + message: { + status: 429, + message: 'You\'ve exhausted your ratelimit, please try again later.', + }, + }; + + // Create and configure the rate limiter middleware + const limiter = rateLimit(defaultOptions); + + return limiter; +}; + +export default createRateLimiter; diff --git a/src/models/index.js b/src/models/index.js index 072157a..06b3a20 100644 --- a/src/models/index.js +++ b/src/models/index.js @@ -1,144 +1,12 @@ -const Tags = require('./schemas/Tags') -const Facts = require('./schemas/Facts') -const Users = require('./schemas/Users') -const Waifus = require('./schemas/Waifus') -const Quotes = require('./schemas/Quotes') -const Sleepy = require('./schemas/Sleepy') -const Smile = require('./schemas/Smile') -const Stab = require('./schemas/Stab') -const Stare = require('./schemas/Stare') -const Suicide = require('./schemas/Suicide') -const Tease = require('./schemas/Tease') -const Wag = require('./schemas/Wag') -const Bite = require('./schemas/Bite') -const Blush = require('./schemas/Blush') -const Bonk = require('./schemas/Bonk') -const Bored = require('./schemas/Bored') -const Bully = require('./schemas/Bully') -const Bye = require('./schemas/Bye') -const Chase = require('./schemas/Chase') -const Cheer = require('./schemas/Cheer') -const Dab = require('./schemas/Dab') -const Die = require('./schemas/Die') -const Disgust = require('./schemas/Disgust') -const Feed = require('./schemas/Feed') -const Hold = require('./schemas/Hold') -const Hi = require('./schemas/Hi') -const Hug = require('./schemas/Hug') -const Kick = require('./schemas/Kick') -const Kill = require('./schemas/Kill') -const Kissu = require('./schemas/Kissu') -const Midfing = require('./schemas/Midfing') -const Nuzzle = require('./schemas/Nuzzle') -const Punch = require('./schemas/Punch') -const Shoot = require('./schemas/Shoot') -const Sip = require('./schemas/Sip') -const Triggered = require('./schemas/Triggered') -const Wave = require('./schemas/Wave') -const Wink = require('./schemas/Wink') -const Yesh = require('./schemas/Yesh') -const Angry = require('./schemas/Angry') -const Cringe = require('./schemas/Cringe') -const Cry = require('./schemas/Cry') -const Cuddle = require('./schemas/Cuddle') -const Dance = require('./schemas/Dance') -const Facepalm = require('./schemas/Facepalm') -const Glomp = require('./schemas/Glomp') -const Happy = require('./schemas/Happy') -const Highfive = require('./schemas/Highfive') -const Laugh = require('./schemas/Laugh') -const Lick = require('./schemas/Lick') -const Love = require('./schemas/Love') -const Lurk = require('./schemas/Lurk') -const Nervouse = require('./schemas/Nervouse') -const Nom = require('./schemas/Nom') -const Nope = require('./schemas/Nope') -const Panic = require('./schemas/Panic') -const Pat = require('./schemas/Pat') -const Peck = require('./schemas/Peck') -const Poke = require('./schemas/Poke') -const Pout = require('./schemas/Pout') -const Run = require('./schemas/Run') -const Sad = require('./schemas/Sad') -const Shrug = require('./schemas/Shrug') -const Slap = require('./schemas/Slap') -const Smug = require('./schemas/Smug') -const Think = require('./schemas/Think') -const Thumbsup = require('./schemas/Thumbsup') -const Tickle = require('./schemas/Tickle') -const Baka = require('./schemas/Baka') -const Stat = require('./schemas/Stat') +/** + * Importing all the necessary schemas. + * @namespace Schemas + */ +import * as Schemas from './schemas'; - -module.exports = { - Stat, - Tags, - Facts, - Users, - Waifus, - Quotes, - Sleepy, - Smile, - Stab, - Stare, - Suicide, - Tease, - Wag, - Bite, - Blush, - Bonk, - Bored, - Bully, - Bye, - Chase, - Cheer, - Dab, - Die, - Disgust, - Feed, - Hold, - Hi, - Hug, - Kick, - Kill, - Kissu, - Midfing, - Nuzzle, - Punch, - Shoot, - Sip, - Triggered, - Wave, - Wink, - Yesh, - Angry, - Cringe, - Cry, - Cuddle, - Dance, - Facepalm, - Glomp, - Happy, - Highfive, - Laugh, - Lick, - Love, - Lurk, - Nervouse, - Nom, - Nope, - Panic, - Pat, - Peck, - Poke, - Pout, - Run, - Sad, - Shrug, - Slap, - Smug, - Think, - Thumbsup, - Tickle, - Baka, -} +/** + * Exporting all the schemas. + * @type {Object} + * @memberof Schemas + */ +export default Schemas; diff --git a/src/models/schemas/Angry.js b/src/models/schemas/Angry.js index e443d3d..d07b36a 100644 --- a/src/models/schemas/Angry.js +++ b/src/models/schemas/Angry.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const AngrySchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Angry', AngrySchema); -module.exports = model('Angry', AngrySchema) diff --git a/src/models/schemas/Baka.js b/src/models/schemas/Baka.js index ccd7903..7170d80 100644 --- a/src/models/schemas/Baka.js +++ b/src/models/schemas/Baka.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BakaSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Baka', BakaSchema); -module.exports = model('Baka', BakaSchema) diff --git a/src/models/schemas/Bite.js b/src/models/schemas/Bite.js index 5ed7e5c..e9779cc 100644 --- a/src/models/schemas/Bite.js +++ b/src/models/schemas/Bite.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BiteSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Bite', BiteSchema); -module.exports = model('Bite', BiteSchema) diff --git a/src/models/schemas/Blush.js b/src/models/schemas/Blush.js index e21a406..3c93b45 100644 --- a/src/models/schemas/Blush.js +++ b/src/models/schemas/Blush.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BlushSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Blush', BlushSchema); -module.exports = model('Blush', BlushSchema) diff --git a/src/models/schemas/Bonk.js b/src/models/schemas/Bonk.js index 071ed4a..2ccf49f 100644 --- a/src/models/schemas/Bonk.js +++ b/src/models/schemas/Bonk.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BonkSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Bonk', BonkSchema); -module.exports = model('Bonk', BonkSchema) diff --git a/src/models/schemas/Bored.js b/src/models/schemas/Bored.js index 6393ba0..8c55c62 100644 --- a/src/models/schemas/Bored.js +++ b/src/models/schemas/Bored.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BoredSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Bored', BoredSchema); -module.exports = model('Bored', BoredSchema) diff --git a/src/models/schemas/Bully.js b/src/models/schemas/Bully.js index 5c84c31..31a4a0c 100644 --- a/src/models/schemas/Bully.js +++ b/src/models/schemas/Bully.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const BullySchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Bully', BullySchema); -module.exports = model('Bully', BullySchema) diff --git a/src/models/schemas/Bye.js b/src/models/schemas/Bye.js index e9c316b..d847743 100644 --- a/src/models/schemas/Bye.js +++ b/src/models/schemas/Bye.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ByeSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Bye', ByeSchema); -module.exports = model('Bye', ByeSchema) diff --git a/src/models/schemas/Chase.js b/src/models/schemas/Chase.js index 2d25f31..a3c33da 100644 --- a/src/models/schemas/Chase.js +++ b/src/models/schemas/Chase.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ChaseSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Chase', ChaseSchema); -module.exports = model('Chase', ChaseSchema) diff --git a/src/models/schemas/Cheer.js b/src/models/schemas/Cheer.js index df71532..01274fb 100644 --- a/src/models/schemas/Cheer.js +++ b/src/models/schemas/Cheer.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const CheerSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Cheer', CheerSchema); -module.exports = model('Cheer', CheerSchema) diff --git a/src/models/schemas/Cringe.js b/src/models/schemas/Cringe.js index aa66000..a6860f7 100644 --- a/src/models/schemas/Cringe.js +++ b/src/models/schemas/Cringe.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const CringeSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Cringe', CringeSchema); -module.exports = model('Cringe', CringeSchema) diff --git a/src/models/schemas/Cry.js b/src/models/schemas/Cry.js index bb18960..cd328a4 100644 --- a/src/models/schemas/Cry.js +++ b/src/models/schemas/Cry.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const CrySchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Cry', CrySchema); -module.exports = model('Cry', CrySchema) diff --git a/src/models/schemas/Cuddle.js b/src/models/schemas/Cuddle.js index 991d4fd..18e90be 100644 --- a/src/models/schemas/Cuddle.js +++ b/src/models/schemas/Cuddle.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const CuddleSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Cuddle', CuddleSchema); -module.exports = model('Cuddle', CuddleSchema) diff --git a/src/models/schemas/Dab.js b/src/models/schemas/Dab.js index f5ebf33..4eaea99 100644 --- a/src/models/schemas/Dab.js +++ b/src/models/schemas/Dab.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const DabSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Dab', DabSchema); -module.exports = model('Dab', DabSchema) diff --git a/src/models/schemas/Dance.js b/src/models/schemas/Dance.js index cffb36b..90c0ad3 100644 --- a/src/models/schemas/Dance.js +++ b/src/models/schemas/Dance.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const DanceSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Dance', DanceSchema); -module.exports = model('Dance', DanceSchema) diff --git a/src/models/schemas/Die.js b/src/models/schemas/Die.js index 148de2e..e1b2d90 100644 --- a/src/models/schemas/Die.js +++ b/src/models/schemas/Die.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const DieSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Die', DieSchema); -module.exports = model('Die', DieSchema) diff --git a/src/models/schemas/Disgust.js b/src/models/schemas/Disgust.js index 3a00fa3..2fe2e14 100644 --- a/src/models/schemas/Disgust.js +++ b/src/models/schemas/Disgust.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const DisgustSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Disgust', DisgustSchema); -module.exports = model('Disgust', DisgustSchema) diff --git a/src/models/schemas/Facepalm.js b/src/models/schemas/Facepalm.js index fd6d178..6d1d1e9 100644 --- a/src/models/schemas/Facepalm.js +++ b/src/models/schemas/Facepalm.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const FacepalmSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Facepalm', FacepalmSchema); -module.exports = model('Facepalm', FacepalmSchema) diff --git a/src/models/schemas/Fact.js b/src/models/schemas/Fact.js new file mode 100644 index 0000000..e0a97fc --- /dev/null +++ b/src/models/schemas/Fact.js @@ -0,0 +1,42 @@ +import mongoose from 'mongoose'; + +/** + * Represents the schema for the Fact model. + * @class FactSchema + */ +const FactSchema = new mongoose.Schema({ + /** + * Unique identifier for the fact. + * @type {Number} + */ + _id: { type: Number }, + + /** + * The actual fact text. + * @type {string} + * @required + */ + fact: { type: String, required: true }, + + /** + * Tags associated with the fact. + * @type {Array} + * @required + */ + tags: { type: [String], required: true }, + + /** + * The length of the fact. + * @type {Number} + */ + length: { type: Number }, +}); + +/** + * Fact model for storing facts. + * @class Fact + * @type {mongoose.Model} + */ +const Fact = mongoose.model('Fact', FactSchema); + +export default Fact; diff --git a/src/models/schemas/Facts.js b/src/models/schemas/Facts.js deleted file mode 100644 index c0987ab..0000000 --- a/src/models/schemas/Facts.js +++ /dev/null @@ -1,10 +0,0 @@ -const { Schema, model } = require('mongoose') - -const FactSchema = new Schema({ - _id: { type: Number }, - fact: { type: String, required: true }, - tags: { type: [String], required: true }, - length: { type: Number }, -}) - -module.exports = model('Fact', FactSchema) diff --git a/src/models/schemas/Feed.js b/src/models/schemas/Feed.js index b27b5ae..63d1838 100644 --- a/src/models/schemas/Feed.js +++ b/src/models/schemas/Feed.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const FeedSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Feed', FeedSchema); -module.exports = model('Feed', FeedSchema) diff --git a/src/models/schemas/Glomp.js b/src/models/schemas/Glomp.js index 6325c5d..5972c29 100644 --- a/src/models/schemas/Glomp.js +++ b/src/models/schemas/Glomp.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const GlompSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Glomp', GlompSchema); -module.exports = model('Glomp', GlompSchema) diff --git a/src/models/schemas/Happy.js b/src/models/schemas/Happy.js index 540f1df..245fb57 100644 --- a/src/models/schemas/Happy.js +++ b/src/models/schemas/Happy.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const HappySchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Happy', HappySchema); -module.exports = model('Happy', HappySchema) diff --git a/src/models/schemas/Hi.js b/src/models/schemas/Hi.js index 69539e7..73eed45 100644 --- a/src/models/schemas/Hi.js +++ b/src/models/schemas/Hi.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const HiSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Hi', HiSchema); -module.exports = model('Hi', HiSchema) diff --git a/src/models/schemas/Highfive.js b/src/models/schemas/Highfive.js index 7fe5901..1260672 100644 --- a/src/models/schemas/Highfive.js +++ b/src/models/schemas/Highfive.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const HighfiveSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Highfive', HighfiveSchema); -module.exports = model('Highfive', HighfiveSchema) diff --git a/src/models/schemas/Hold.js b/src/models/schemas/Hold.js index 859d1bd..91c1c3a 100644 --- a/src/models/schemas/Hold.js +++ b/src/models/schemas/Hold.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const HoldSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Hold', HoldSchema); -module.exports = model('Hold', HoldSchema) diff --git a/src/models/schemas/Hug.js b/src/models/schemas/Hug.js index 371098b..1efa54f 100644 --- a/src/models/schemas/Hug.js +++ b/src/models/schemas/Hug.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const HugSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Hug', HugSchema); -module.exports = model('Hug', HugSchema) diff --git a/src/models/schemas/Kick.js b/src/models/schemas/Kick.js index 40c5666..c2c7254 100644 --- a/src/models/schemas/Kick.js +++ b/src/models/schemas/Kick.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const KickSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Kick', KickSchema); -module.exports = model('Kick', KickSchema) diff --git a/src/models/schemas/Kill.js b/src/models/schemas/Kill.js index 9e278c3..fbd441f 100644 --- a/src/models/schemas/Kill.js +++ b/src/models/schemas/Kill.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const KillSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Kill', KillSchema); -module.exports = model('Kill', KillSchema) diff --git a/src/models/schemas/Kissu.js b/src/models/schemas/Kissu.js index e3addba..c2603f1 100644 --- a/src/models/schemas/Kissu.js +++ b/src/models/schemas/Kissu.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const KissuSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Kissu', KissuSchema); -module.exports = model('Kissu', KissuSchema) diff --git a/src/models/schemas/Laugh.js b/src/models/schemas/Laugh.js index c9b235b..6fcdf54 100644 --- a/src/models/schemas/Laugh.js +++ b/src/models/schemas/Laugh.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const LaughSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Laugh', LaughSchema); -module.exports = model('Laugh', LaughSchema) diff --git a/src/models/schemas/Lick.js b/src/models/schemas/Lick.js index b24812d..7e5526a 100644 --- a/src/models/schemas/Lick.js +++ b/src/models/schemas/Lick.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const LickSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Lick', LickSchema); -module.exports = model('Lick', LickSchema) diff --git a/src/models/schemas/Love.js b/src/models/schemas/Love.js index 5879558..a47119b 100644 --- a/src/models/schemas/Love.js +++ b/src/models/schemas/Love.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const LoveSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Love', LoveSchema); -module.exports = model('Love', LoveSchema) diff --git a/src/models/schemas/Lurk.js b/src/models/schemas/Lurk.js index 48fa84e..77b53c7 100644 --- a/src/models/schemas/Lurk.js +++ b/src/models/schemas/Lurk.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const LurkSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Lurk', LurkSchema); -module.exports = model('Lurk', LurkSchema) diff --git a/src/models/schemas/Midfing.js b/src/models/schemas/Midfing.js index d36ef33..905f037 100644 --- a/src/models/schemas/Midfing.js +++ b/src/models/schemas/Midfing.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const MidfingSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Midfing', MidfingSchema); -module.exports = model('Midfing', MidfingSchema) diff --git a/src/models/schemas/Nervous.js b/src/models/schemas/Nervous.js new file mode 100644 index 0000000..4cc18a1 --- /dev/null +++ b/src/models/schemas/Nervous.js @@ -0,0 +1,10 @@ +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; + +const NervousSchema = new Schema({ + _id: { type: Number }, + url: { type: String, required: true }, +}); + +export default model('Nervous', NervousSchema); + diff --git a/src/models/schemas/Nervouse.js b/src/models/schemas/Nervouse.js deleted file mode 100644 index 2f73061..0000000 --- a/src/models/schemas/Nervouse.js +++ /dev/null @@ -1,8 +0,0 @@ -const { Schema, model } = require('mongoose') - -const NervouseSchema = new Schema({ - _id: { type: Number }, - url: { type: String, required: true }, -}) - -module.exports = model('Nervouse', NervouseSchema) diff --git a/src/models/schemas/Nom.js b/src/models/schemas/Nom.js index ae41fe8..e0ee996 100644 --- a/src/models/schemas/Nom.js +++ b/src/models/schemas/Nom.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const NomSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Nom', NomSchema); -module.exports = model('Nom', NomSchema) diff --git a/src/models/schemas/Nope.js b/src/models/schemas/Nope.js index 37701f0..933b78c 100644 --- a/src/models/schemas/Nope.js +++ b/src/models/schemas/Nope.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const NopeSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Nope', NopeSchema); -module.exports = model('Nope', NopeSchema) diff --git a/src/models/schemas/Nuzzle.js b/src/models/schemas/Nuzzle.js index 0f3f81d..c7d0d52 100644 --- a/src/models/schemas/Nuzzle.js +++ b/src/models/schemas/Nuzzle.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const NuzzleSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Nuzzle', NuzzleSchema); -module.exports = model('Nuzzle', NuzzleSchema) diff --git a/src/models/schemas/Panic.js b/src/models/schemas/Panic.js index 43edf71..bc56563 100644 --- a/src/models/schemas/Panic.js +++ b/src/models/schemas/Panic.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PanicSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Panic', PanicSchema); -module.exports = model('Panic', PanicSchema) diff --git a/src/models/schemas/Pat.js b/src/models/schemas/Pat.js index 7350eb4..4f23c59 100644 --- a/src/models/schemas/Pat.js +++ b/src/models/schemas/Pat.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PatSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Pat', PatSchema); -module.exports = model('Pat', PatSchema) diff --git a/src/models/schemas/Peck.js b/src/models/schemas/Peck.js index 0768bbe..ef146b6 100644 --- a/src/models/schemas/Peck.js +++ b/src/models/schemas/Peck.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PeckSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Peck', PeckSchema); -module.exports = model('Peck', PeckSchema) diff --git a/src/models/schemas/Poke.js b/src/models/schemas/Poke.js index ad8f37e..924d5c9 100644 --- a/src/models/schemas/Poke.js +++ b/src/models/schemas/Poke.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PokeSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Poke', PokeSchema); -module.exports = model('Poke', PokeSchema) diff --git a/src/models/schemas/Pout.js b/src/models/schemas/Pout.js index 07abc12..cf08cef 100644 --- a/src/models/schemas/Pout.js +++ b/src/models/schemas/Pout.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PoutSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Pout', PoutSchema); -module.exports = model('Pout', PoutSchema) diff --git a/src/models/schemas/Punch.js b/src/models/schemas/Punch.js index 3c2d129..6e44d36 100644 --- a/src/models/schemas/Punch.js +++ b/src/models/schemas/Punch.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const PunchSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Punch', PunchSchema); -module.exports = model('Punch', PunchSchema) diff --git a/src/models/schemas/Quote.js b/src/models/schemas/Quote.js new file mode 100644 index 0000000..bf4e8ad --- /dev/null +++ b/src/models/schemas/Quote.js @@ -0,0 +1,43 @@ +import mongoose from 'mongoose'; + +/** + * Represents the schema for the Quote model. + * @class QuoteSchema + */ +const QuoteSchema = new mongoose.Schema({ + /** + * Unique identifier for the quote. + * @type {Number} + * @required + */ + _id: { type: Number, required: true }, + + /** + * The actual quote text. + * @type {string} + * @required + */ + quote: { type: String, required: true }, + + /** + * The name of the anime associated with the quote. + * @type {string} + */ + anime: { type: String }, + + /** + * The author of the quote. + * @type {string} + * @required + */ + author: { type: String, required: true }, +}); + +/** + * Quote model for storing quotes. + * @class Quote + * @type {mongoose.Model} + */ +const Quote = mongoose.model('Quote', QuoteSchema); + +export default Quote; diff --git a/src/models/schemas/Quotes.js b/src/models/schemas/Quotes.js deleted file mode 100644 index 234182a..0000000 --- a/src/models/schemas/Quotes.js +++ /dev/null @@ -1,10 +0,0 @@ -const { Schema, model } = require('mongoose') - -const QuoteSchema = new Schema({ - _id: { type: Number, required: true }, - quote: { type: String, required: true }, - anime: { type: String }, - author: { type: String, required: true }, -}) - -module.exports = model('Quote', QuoteSchema) diff --git a/src/models/schemas/Run.js b/src/models/schemas/Run.js index c1ef5c9..4ae898f 100644 --- a/src/models/schemas/Run.js +++ b/src/models/schemas/Run.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const RunSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Run', RunSchema); -module.exports = model('Run', RunSchema) diff --git a/src/models/schemas/Sad.js b/src/models/schemas/Sad.js index d316f6e..a2575c5 100644 --- a/src/models/schemas/Sad.js +++ b/src/models/schemas/Sad.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const SadSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Sad', SadSchema); -module.exports = model('Sad', SadSchema) diff --git a/src/models/schemas/Shoot.js b/src/models/schemas/Shoot.js index 438bf90..497bf3b 100644 --- a/src/models/schemas/Shoot.js +++ b/src/models/schemas/Shoot.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ShootSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Shoot', ShootSchema); -module.exports = model('Shoot', ShootSchema) diff --git a/src/models/schemas/Shrug.js b/src/models/schemas/Shrug.js index 95904ca..d45f88e 100644 --- a/src/models/schemas/Shrug.js +++ b/src/models/schemas/Shrug.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ShrugSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Shrug', ShrugSchema); -module.exports = model('Shrug', ShrugSchema) diff --git a/src/models/schemas/Sip.js b/src/models/schemas/Sip.js index 81b31e3..d2cc6d0 100644 --- a/src/models/schemas/Sip.js +++ b/src/models/schemas/Sip.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const SipSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Sip', SipSchema); -module.exports = model('Sip', SipSchema) diff --git a/src/models/schemas/Slap.js b/src/models/schemas/Slap.js index 24fd688..de1ffde 100644 --- a/src/models/schemas/Slap.js +++ b/src/models/schemas/Slap.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const SlapSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Slap', SlapSchema); -module.exports = model('Slap', SlapSchema) diff --git a/src/models/schemas/Sleepy.js b/src/models/schemas/Sleepy.js index b6e73b5..85fa26d 100644 --- a/src/models/schemas/Sleepy.js +++ b/src/models/schemas/Sleepy.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; -const BiteSchema = new Schema({ +const SleepySchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Sleepy', SleepySchema); -module.exports = model('Sleepy', BiteSchema) diff --git a/src/models/schemas/Smile.js b/src/models/schemas/Smile.js index d8e013b..8b74524 100644 --- a/src/models/schemas/Smile.js +++ b/src/models/schemas/Smile.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; -const BiteSchema = new Schema({ +const SmileSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Smile', SmileSchema); -module.exports = model('Smile', BiteSchema) diff --git a/src/models/schemas/Smug.js b/src/models/schemas/Smug.js index dabc129..5467a87 100644 --- a/src/models/schemas/Smug.js +++ b/src/models/schemas/Smug.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const SmugSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Smug', SmugSchema); -module.exports = model('Smug', SmugSchema) diff --git a/src/models/schemas/Stab.js b/src/models/schemas/Stab.js index 4761e28..c2e942b 100644 --- a/src/models/schemas/Stab.js +++ b/src/models/schemas/Stab.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const StabSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Stab', StabSchema); -module.exports = model('Stab', StabSchema) diff --git a/src/models/schemas/Stare.js b/src/models/schemas/Stare.js index 6ba4960..4201df9 100644 --- a/src/models/schemas/Stare.js +++ b/src/models/schemas/Stare.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const StareSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Stare', StareSchema); -module.exports = model('Stare', StareSchema) diff --git a/src/models/schemas/Stat.js b/src/models/schemas/Stat.js index aeb1c7b..18a1da6 100644 --- a/src/models/schemas/Stat.js +++ b/src/models/schemas/Stat.js @@ -1,4 +1,5 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const StatSchema = new Schema({ _id: { type: String, required: true, default: 'system' }, @@ -82,6 +83,8 @@ const StatSchema = new Schema({ punch: { type: Number, default: 0 }, quotes: { type: Number, default: 0 }, password: { type: Number, default: 0 }, -}) +}); -module.exports = model('Stat', StatSchema) +const Stat = model('Stat', StatSchema); + +export default Stat; diff --git a/src/models/schemas/Suicide.js b/src/models/schemas/Suicide.js index 1dc2daf..709b9f7 100644 --- a/src/models/schemas/Suicide.js +++ b/src/models/schemas/Suicide.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const SuicideSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Suicide', SuicideSchema); -module.exports = model('Suicide', SuicideSchema) diff --git a/src/models/schemas/Tags.js b/src/models/schemas/Tags.js index 82c8c10..e7a2e52 100644 --- a/src/models/schemas/Tags.js +++ b/src/models/schemas/Tags.js @@ -1,10 +1,13 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const TagSchema = new Schema({ _id: { type: Number }, name: { type: String, required: true }, -}) +}); -TagSchema.index({ name: 1 }, { name: 'nameIndex' }) +TagSchema.index({ name: 1 }, { name: 'nameIndex' }); -module.exports = model('Tag', TagSchema) +const Tag = model('Tag', TagSchema); + +export default Tag; diff --git a/src/models/schemas/Tease.js b/src/models/schemas/Tease.js index db8cd6c..331e870 100644 --- a/src/models/schemas/Tease.js +++ b/src/models/schemas/Tease.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const TeaseSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Tease', TeaseSchema); -module.exports = model('Tease', TeaseSchema) diff --git a/src/models/schemas/Think.js b/src/models/schemas/Think.js index 2c673f1..055f982 100644 --- a/src/models/schemas/Think.js +++ b/src/models/schemas/Think.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ThinkSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Think', ThinkSchema); -module.exports = model('Think', ThinkSchema) diff --git a/src/models/schemas/Thumbsup.js b/src/models/schemas/Thumbsup.js index cff36eb..6537d2e 100644 --- a/src/models/schemas/Thumbsup.js +++ b/src/models/schemas/Thumbsup.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const ThumbsupSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Thumbsup', ThumbsupSchema); -module.exports = model('Thumbsup', ThumbsupSchema) diff --git a/src/models/schemas/Tickle.js b/src/models/schemas/Tickle.js index da5981a..9fbc747 100644 --- a/src/models/schemas/Tickle.js +++ b/src/models/schemas/Tickle.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const TickleSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Tickle', TickleSchema); -module.exports = model('Tickle', TickleSchema) diff --git a/src/models/schemas/Triggered.js b/src/models/schemas/Triggered.js index 5456962..451f205 100644 --- a/src/models/schemas/Triggered.js +++ b/src/models/schemas/Triggered.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const TriggeredSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Triggered', TriggeredSchema); -module.exports = model('Triggered', TriggeredSchema) diff --git a/src/models/schemas/User.js b/src/models/schemas/User.js new file mode 100644 index 0000000..97d832c --- /dev/null +++ b/src/models/schemas/User.js @@ -0,0 +1,117 @@ +import mongoose from 'mongoose'; + +/** + * Represents the schema for the User model. + * @class UserSchema + */ +const UserSchema = new mongoose.Schema({ + /** + * Unique identifier for the user. + * @type {string} + */ + _id: { type: String }, + + /** + * User's email address. + * @type {string} + * @required + */ + email: { type: String, required: true }, + + /** + * User's hashed password. + * @type {string} + * @required + */ + password: { type: String, required: true }, + + /** + * User's Discord access token + * @type {string} + */ + access_token: { type: String }, + + /** + * Authentication token for the user. + * @type {string} + */ + token: { type: String }, + + /** + * Flag indicating whether the user is banned. + * @type {boolean} + * @default false + */ + banned: { type: Boolean, default: false }, + + /** + * Array to store the history of status changes with timestamp, reason, and ban/unban flag. + * @type {Array<{ timestamp: Date, reason: string, isBanned: boolean }>} + */ + status_history: [ + { + /** + * Timestamp of the status change. + * @type {Date} + * @default Date.now + */ + timestamp: { type: Date, default: Date.now }, + + /** + * The reason for the status change. + * @type {string} + */ + reason: { type: String }, + + /** + * Flag indicating whether the user is banned at this status change. + * @type {boolean} + */ + isBanned: { type: Boolean }, + }, + ], + + /** + * User's request quota. + * @type {number} + * @default 500 + */ + req_quota: { type: Number, default: 500 }, + + /** + * Number of requests made by the user. + * @type {number} + * @default 0 + */ + req_count: { type: Number, default: 0 }, + + /** + * Date and time when the user account was created. + * @type {Date} + * @default Date.now + */ + createdAt: { type: Date, default: Date.now() }, + + /** + * Request rate limit for the user. + * @type {number} + * @default 20 + */ + rateLimit: { type: Number, default: 20 }, + + /** + * Array of roles assigned to the user. + * @type {Array} + * @default ['user'] + */ + roles: { type: [String], default: ['user'] }, +}); + +/** + * User model for interacting with the 'Users' collection in MongoDB. + * @class User + * @type {mongoose.Model} + */ +const User = mongoose.model('User', UserSchema); + +export default User; diff --git a/src/models/schemas/Users.js b/src/models/schemas/Users.js deleted file mode 100644 index c255463..0000000 --- a/src/models/schemas/Users.js +++ /dev/null @@ -1,13 +0,0 @@ -const { Schema, model } = require('mongoose') - -const UserSchema = new Schema({ - _id: { type: String, required: true }, - email: { type: String, required: true }, - password: { type: String, required: true }, - token: { type: String }, - banned: { type: Boolean, default: false }, - req_quoto: { type: Number, default: 900 }, - req_count: { type: Number, default: 0 }, -}) - -module.exports = model('User', UserSchema) diff --git a/src/models/schemas/Wag.js b/src/models/schemas/Wag.js index df5577d..7e7a624 100644 --- a/src/models/schemas/Wag.js +++ b/src/models/schemas/Wag.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const WagSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Wag', WagSchema); -module.exports = model('Wag', WagSchema) diff --git a/src/models/schemas/Waifu.js b/src/models/schemas/Waifu.js new file mode 100644 index 0000000..e0dc531 --- /dev/null +++ b/src/models/schemas/Waifu.js @@ -0,0 +1,89 @@ +import mongoose from 'mongoose'; + +// Destructuring to extract Schema and model from mongoose +const { Schema, model } = mongoose; + +/** + * Represents the schema for the Waifu model. + * @class WaifuSchema + */ +const WaifuSchema = new Schema({ + _id: { type: Number, required: true }, + names: { + /** + * The English name of the waifu. + * @type {String} + */ + en: { type: String, required: true }, + + /** + * The Japanese name of the waifu. + * @type {String} + */ + jp: { type: String }, + + /** + * Alternative name or alias of the waifu. + * @type {String} + */ + alt: { type: String }, + }, + from: { + /** + * The name of the source or origin of the waifu. + * @type {String} + */ + name: { type: String }, + + /** + * The type or category of the source from which the waifu originates. + * @type {String} + */ + type: { type: String }, + }, + /** + * Array of image URLs associated with the waifu. + * @type {Array} + */ + images: [String], + + statistics: { + /** + * The number of favorites received by the waifu. + * @type {Number} + */ + fav: { type: Number }, + + /** + * The number of times the waifu is loved. + * @type {Number} + */ + love: { type: Number }, + + /** + * The number of times the waifu is disliked or hated. + * @type {Number} + */ + hate: { type: Number }, + + /** + * The number of upvotes received by the waifu. + * @type {Number} + */ + upvote: { type: Number }, + + /** + * The number of downvotes received by the waifu. + * @type {Number} + */ + downvote: { type: Number }, + }, +}); + +/** + * Represents the Waifu model. + * @class Waifu + */ +const Waifu = model('Waifu', WaifuSchema); + +export default Waifu; diff --git a/src/models/schemas/Waifus.js b/src/models/schemas/Waifus.js deleted file mode 100644 index f224fc9..0000000 --- a/src/models/schemas/Waifus.js +++ /dev/null @@ -1,24 +0,0 @@ -const { Schema, model } = require('mongoose') - -const WaifuSchema = new Schema({ - _id: { type: Number }, - names: { - en: { type: String }, - jp: { type: String }, - alt: { type: String }, - }, - from: { - name: { type: String }, - type: { type: String }, - }, - images: [], - statistics: { - fav: { type: Number }, - love: { type: Number }, - hate: { type: Number }, - upvote: { type: Number }, - downvote: { type: Number }, - }, -}) - -module.exports = model('Waifu', WaifuSchema) diff --git a/src/models/schemas/Wave.js b/src/models/schemas/Wave.js index 72f6929..ba293b0 100644 --- a/src/models/schemas/Wave.js +++ b/src/models/schemas/Wave.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const WaveSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Wave', WaveSchema); -module.exports = model('Wave', WaveSchema) diff --git a/src/models/schemas/Wink.js b/src/models/schemas/Wink.js index 0146c5e..8cc8209 100644 --- a/src/models/schemas/Wink.js +++ b/src/models/schemas/Wink.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const WinkSchema = new Schema({ _id: { type: Number }, url: { type: String, required: true }, -}) +}); + +export default model('Wink', WinkSchema); -module.exports = model('Wink', WinkSchema) diff --git a/src/models/schemas/Yesh.js b/src/models/schemas/Yesh.js index 93acc51..354bc1b 100644 --- a/src/models/schemas/Yesh.js +++ b/src/models/schemas/Yesh.js @@ -1,8 +1,10 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const YeshSchema = new Schema({ _id: { type: Number }, - url: { type: String, required: true }, -}) + url: { type: String, required: true, unique: true }, +}); + +export default model('Yesh', YeshSchema); -module.exports = model('Yesh', YeshSchema) diff --git a/src/modules/generateToken.js b/src/modules/generateToken.js new file mode 100644 index 0000000..5e5a802 --- /dev/null +++ b/src/modules/generateToken.js @@ -0,0 +1,74 @@ +import crypto from 'crypto'; + +/** + * Generates a Waifu.it-style token for user authentication. + * + * @function + * @param {string} id - User ID for generating the token. + * @param {string} key - Secret key used for token generation. + * + * @throws {Error} If there is an error during token generation. + * + * @returns {string} The generated Waifu.it-style token. + */ +const generateToken = (id, key) => { + /** + * Function to generate a random hexadecimal string. + * @param {number} length - Length of the hexadecimal string. + * @returns {string} Random hexadecimal string. + */ + const generateRandomHex = length => { + return crypto + .randomBytes(Math.ceil(length / 2)) + .toString('hex') + .slice(0, length); + }; + + /** + * Function to convert a timestamp to epoch and encode it to base64. + * @param {number} timestamp - Timestamp to be encoded. + * @returns {string} Base64-encoded timestamp. + */ + const encodeTimestampToBase64 = timestamp => { + const epoch = Math.floor(timestamp / 1000); // Convert to seconds (Waifu.it uses seconds for epoch) + return Buffer.from(epoch.toString()).toString('base64'); + }; + + /** + * Function to generate a random signature between 10 to 28 characters. + * @param {number} minLength - Minimum length of the signature. + * @param {number} maxLength - Maximum length of the signature. + * @returns {string} Random signature string. + */ + const generateRandomSignature = (minLength, maxLength) => { + const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; + return generateRandomHex(length).replace(/M/g, 'N').replace(/=/g, '-'); + }; + + /** + * Function to generate a Waifu.it-style token (64 characters). + * @param {string} userID - User ID to be included in the token. + * @param {string} secretKey - Secret key used for HMAC generation. + * @returns {string} Waifu.it-style token. + */ + const generateAPIToken = (userID, secretKey) => { + const userIDBase64 = Buffer.from(userID).toString('base64').replace(/=/g, '-'); + const timestamp = Date.now(); + const timestampBase64 = encodeTimestampToBase64(timestamp).replace(/=/g, '-'); + const payload = `${userIDBase64}.${timestampBase64}`; + + // Generate HMAC for the payload using the secretKey + const hmac = crypto.createHmac('sha256', secretKey).update(payload).digest('hex').slice(0, 5); + const signature = generateRandomSignature(4, 7); + + // Combine payload and signature to form a 64-character token + const token = `${payload}.${hmac}${signature}`; + + return token; + }; + + // Return the generated Waifu.it-style token + return generateAPIToken(id, key); +}; + +export default generateToken; diff --git a/src/modules/lengthFilter.js b/src/modules/lengthFilter.js new file mode 100644 index 0000000..ae17b0b --- /dev/null +++ b/src/modules/lengthFilter.js @@ -0,0 +1,17 @@ +/** + * Generates a MongoDB query object for filtering documents based on length range. + * + * @function lengthFilter + * @param {number|string} minLength - Minimum length for the filter. (default: 0) + * @param {number|string} maxLength - Maximum length for the filter. (default: 10000) + * + * @returns {Object} MongoDB query object. + * @returns {number} $gte - Greater than or equal to the minimum length. + * @returns {number} $lte - Less than or equal to the maximum length. + */ +const lengthFilter = (minLength, maxLength) => ({ + $gte: Number(minLength) || 0, + $lte: Number(maxLength) || 1e4, +}); + +export default lengthFilter; diff --git a/src/modules/parseOrder.js b/src/modules/parseOrder.js new file mode 100644 index 0000000..3be75d3 --- /dev/null +++ b/src/modules/parseOrder.js @@ -0,0 +1,21 @@ +/** + * Parses the input order keyword into a numeric value for MongoDB sorting. + * + * @function parseOrder + * @param {string|number} input - Input order keyword. Supported values: "asc", "ascending", "desc", "descending", 1, -1. + * + * @returns {number|null} Numeric value for MongoDB sorting: 1 for ascending, -1 for descending, or null if the input is invalid. + */ +const parseOrder = input => { + let value = input; + + // If value is one of the supported keywords ("asc", "ascending", + // "desc", "descending"), convert it to the corresponding numeric value. + if (/^asc(ending)?$|^desc(ending)?$/.test(String(value))) { + value = /^asc/.test(input) ? 1 : -1; + } + + return Math.abs(value) === 1 ? Number(value) : null; +}; + +export default parseOrder; diff --git a/src/modules/tagsFilter.js b/src/modules/tagsFilter.js new file mode 100644 index 0000000..9f9a57d --- /dev/null +++ b/src/modules/tagsFilter.js @@ -0,0 +1,21 @@ +/** + * Parses the input tags and constructs a MongoDB filter for tag matching. + * + * @function tagsFilter + * @param {string} tags - Input tags string separated by ',' or '|' (e.g., "tag1,tag2" or "tag1|tag2"). + * + * @returns {Object|null} MongoDB filter for tag matching: { $all: ['tag1', 'tag2'] } or { $in: ['tag1', 'tag2'] }. + * Returns null if the input is not a string. + */ +const tagsFilter = tags => { + if (typeof tags === 'string') { + if (tags.includes('|')) { + return { $in: tags.split('|') }; + } + return { $all: tags.split(',') }; + } + + return null; +}; + +export default tagsFilter; diff --git a/src/routes.js b/src/routes.js deleted file mode 100644 index a879d5a..0000000 --- a/src/routes.js +++ /dev/null @@ -1,178 +0,0 @@ -const { Router } = require('express') -const rateLimit = require('express-rate-limit') -const authHandler = require('./handlers/auth/index') -const randomFacts = require('./controllers/facts/randomFacts') -const getAllTags = require('./controllers/utils/listTags') -const getOwoify = require('./controllers/utils/owoify') -const getUwuify = require('./controllers/utils/uwuify') -const getUvuify = require('./controllers/utils/uvuify') -const randomWaifus = require('./controllers/waifus/randomWaifus') -const randomPasswords = require('./controllers/utils/randomPassword') -const randomQuotes = require('./controllers/quotes/randomQuotes') -const randomKick = require('./controllers/gifs/randomKick') -const randomKill = require('./controllers/gifs/randomKill') -const randomKissu = require('./controllers/gifs/randomKissu') -const randomMidfing = require('./controllers/gifs/randomMidfing') -const randomNuzzle = require('./controllers/gifs/randomNuzzle') -const randomPunch = require('./controllers/gifs/randomPunch') -const randomShoot = require('./controllers/gifs/randomShoot') -const randomSip = require('./controllers/gifs/randomSip') -const randomSleepy = require('./controllers/gifs/randomSleepy') -const randomSmile = require('./controllers/gifs/randomSmile') -const randomStab = require('./controllers/gifs/randomStab') -const randomStare = require('./controllers/gifs/randomStare') -const randomSuicide = require('./controllers/gifs/randomSuicide') -const randomTease = require('./controllers/gifs/randomTease') -const randomWag = require('./controllers/gifs/randomWag') -const randomBite = require('./controllers/gifs/randomBite') -const randomBlush = require('./controllers/gifs/randomBlush') -const randomBonk = require('./controllers/gifs/randomBonk') -const randomBored = require('./controllers/gifs/randomBored') -const randomBully = require('./controllers/gifs/randomBully') -const randomBye = require('./controllers/gifs/randomBye') -const randomChase = require('./controllers/gifs/randomChase') -const randomCheer = require('./controllers/gifs/randomCheer') -const randomDab = require('./controllers/gifs/randomDab') -const randomDie = require('./controllers/gifs/randomDie') -const randomDisgust = require('./controllers/gifs/randomDisgust') -const randomFeed = require('./controllers/gifs/randomFeed') -const randomHi = require('./controllers/gifs/randomHi') -const randomHold = require('./controllers/gifs/randomHold') -const randomHug = require('./controllers/gifs/randomHug') -const randomNope = require('./controllers/gifs/randomNope') -const randomPanic = require('./controllers/gifs/randomPanic') -const randomPat = require('./controllers/gifs/randomPat') -const randomPeck = require('./controllers/gifs/randomPeck') -const randomPoke = require('./controllers/gifs/randomPoke') -const randomPout = require('./controllers/gifs/randomPout') -const randomRun = require('./controllers/gifs/randomRun') -const randomSad = require('./controllers/gifs/randomSad') -const randomShrug = require('./controllers/gifs/randomShrug') -const randomSlap = require('./controllers/gifs/randomSlap') -const randomSmug = require('./controllers/gifs/randomSmug') -const randomThink = require('./controllers/gifs/randomThink') -const randomThumbsup = require('./controllers/gifs/randomThumbsup') -const randomTickle = require('./controllers/gifs/randomTickle') -const randomTriggered = require('./controllers/gifs/randomTriggered') -const randomWave = require('./controllers/gifs/randomWave') -const randomWink = require('./controllers/gifs/randomWink') -const randomYes = require('./controllers/gifs/randomYes') -const randomAngry = require('./controllers/gifs/randomAngry') -const randomCringe = require('./controllers/gifs/randomCringe') -const randomCry = require('./controllers/gifs/randomCry') -const randomCuddle = require('./controllers/gifs/randomCuddle') -const randomDance = require('./controllers/gifs/randomDance') -const randomFacepalm = require('./controllers/gifs/randomFacepalm') -const randomGlomp = require('./controllers/gifs/randomGlomp') -const randomHappy = require('./controllers/gifs/randomHappy') -const randomHighfive = require('./controllers/gifs/randomHighfive') -const randomLaugh = require('./controllers/gifs/randomLaugh') -const randomLick = require('./controllers/gifs/randomLick') -const randomLove = require('./controllers/gifs/randomLove') -const randomLurk = require('./controllers/gifs/randomLurk') -const randomNervous = require('./controllers/gifs/randomNervous') -const randomNom = require('./controllers/gifs/randomNom') -const randomBaka = require('./controllers/gifs/randomBaka') - -const router = Router() - -// Rate Limiter for Fact || Other endpoints -const Limiter = rateLimit({ - windowMs: 1000, // 1 second - max: 2, // limit each IP to 5 requests per windowMs - message: { - status: 429, - message: 'Too many requests, please try again later.', - }, -}) - -// Base API -router.get('/api', (req, res) => { - res.redirect("https://docs.waifu.it/list-of-endpoints"); -}) - -// Fact Endpoints -router.get('/api/fact', Limiter, authHandler, randomFacts) - -// Waifu Endpoint -router.get('/api/waifu', Limiter, authHandler, randomWaifus) - -// Utils Endpoint -router.get('/api/password', Limiter, authHandler, randomPasswords) -router.get('/api/alltags', Limiter, authHandler, getAllTags) -router.get('/api/owoify', Limiter, authHandler, getOwoify) -router.get('/api/uwuify', Limiter, authHandler, getUwuify) -router.get('/api/uvuify', Limiter, authHandler, getUvuify) - -// Random Quote Endpoint -router.get('/api/quote', Limiter, authHandler, randomQuotes) - -// Random Gifs Endpoints -router.get('/api/kick', Limiter, authHandler, randomKick) -router.get('/api/kill', Limiter, authHandler, randomKill) -router.get('/api/kiss', Limiter, authHandler, randomKissu) -router.get('/api/midfing', Limiter, authHandler, randomMidfing) -router.get('/api/nuzzle', Limiter, authHandler, randomNuzzle) -router.get('/api/punch', Limiter, authHandler, randomPunch) -router.get('/api/shoot', Limiter, authHandler, randomShoot) -router.get('/api/sip', Limiter, authHandler, randomSip) -router.get('/api/sleepy', Limiter, authHandler, randomSleepy) -router.get('/api/smile', Limiter, authHandler, randomSmile) -router.get('/api/stab', Limiter, authHandler, randomStab) -router.get('/api/stare', Limiter, authHandler, randomStare) -router.get('/api/suicide', Limiter, authHandler, randomSuicide) -router.get('/api/tease', Limiter, authHandler, randomTease) -router.get('/api/wag', Limiter, authHandler, randomWag) -router.get('/api/bite', Limiter, authHandler, randomBite) -router.get('/api/blush', Limiter, authHandler, randomBlush) -router.get('/api/bonk', Limiter, authHandler, randomBonk) -router.get('/api/bored', Limiter, authHandler, randomBored) -router.get('/api/bully', Limiter, authHandler, randomBully) -router.get('/api/bye', Limiter, authHandler, randomBye) -router.get('/api/chase', Limiter, authHandler, randomChase) -router.get('/api/cheer', Limiter, authHandler, randomCheer) -router.get('/api/dab', Limiter, authHandler, randomDab) -router.get('/api/die', Limiter, authHandler, randomDie) -router.get('/api/disgust', Limiter, authHandler, randomDisgust) -router.get('/api/feed', Limiter, authHandler, randomFeed) -router.get('/api/hi', Limiter, authHandler, randomHi) -router.get('/api/hold', Limiter, authHandler, randomHold) -router.get('/api/hug', Limiter, authHandler, randomHug) -router.get('/api/Nope', Limiter, authHandler, randomNope) -router.get('/api/panic', Limiter, authHandler, randomPanic) -router.get('/api/pat', Limiter, authHandler, randomPat) -router.get('/api/peck', Limiter, authHandler, randomPeck) -router.get('/api/poke', Limiter, authHandler, randomPoke) -router.get('/api/punch', Limiter, authHandler, randomPunch) -router.get('/api/pout', Limiter, authHandler, randomPout) -router.get('/api/run', Limiter, authHandler, randomRun) -router.get('/api/sad', Limiter, authHandler, randomSad) -router.get('/api/shrug', Limiter, authHandler, randomShrug) -router.get('/api/slap', Limiter, authHandler, randomSlap) -router.get('/api/smug', Limiter, authHandler, randomSmug) -router.get('/api/think', Limiter, authHandler, randomThink) -router.get('/api/thumbsup', Limiter, authHandler, randomThumbsup) -router.get('/api/tickle', Limiter, authHandler, randomTickle) -router.get('/api/triggered', Limiter, authHandler, randomTriggered) -router.get('/api/wave', Limiter, authHandler, randomWave) -router.get('/api/wink', Limiter, authHandler, randomWink) -router.get('/api/yes', Limiter, authHandler, randomYes) -router.get('/api/angry', Limiter, authHandler, randomAngry) -router.get('/api/cringe', Limiter, authHandler, randomCringe) -router.get('/api/cry', Limiter, authHandler, randomCry) -router.get('/api/cuddle', Limiter, authHandler, randomCuddle) -router.get('/api/dance', Limiter, authHandler, randomDance) -router.get('/api/facepalm', Limiter, authHandler, randomFacepalm) -router.get('/api/glomp', Limiter, authHandler, randomGlomp) -router.get('/api/happy', Limiter, authHandler, randomHappy) -router.get('/api/highfive', Limiter, authHandler, randomHighfive) -router.get('/api/hug', Limiter, authHandler, randomHug) -router.get('/api/laugh', Limiter, authHandler, randomLaugh) -router.get('/api/lick', Limiter, authHandler, randomLick) -router.get('/api/love', Limiter, authHandler, randomLove) -router.get('/api/lurk', Limiter, authHandler, randomLurk) -router.get('/api/nervous', Limiter, authHandler, randomNervous) -router.get('/api/nom', Limiter, authHandler, randomNom) -router.get('/api/baka', Limiter, authHandler, randomBaka) - -module.exports = router diff --git a/src/routes/v3/index.js b/src/routes/v3/index.js new file mode 100644 index 0000000..619e742 --- /dev/null +++ b/src/routes/v3/index.js @@ -0,0 +1,233 @@ +/** + * This module defines the main routing logic for the API endpoints of the application. It utilizes the Express framework + * and various controllers v3/to handle different types of requests and provide responses. Additionally, it incorporates rate + * limiting and authentication handling for enhanced security and control over incoming requests. + * + * The available endpoints include retrieving random facts, generating random waifus, creating random passwords, listing + * tags, and applying various text transformations like owoify, uwuify, and uvuify. Furthermore, there are endpoints for + * fetching random quotes and an extensive collection of animated GIFs to express a wide range of emotions and actions. + * + * A rate createRateLimiter() has been implemented to manage the frequency of requests and prevent abuse. The `authorize(config.roles.USER)` middleware + * is also employed to ensure authentication for relevant endpoints. + * + * Please refer to the documentation link provided in the '/api' endpoint for more details about the available endpoints. + * + * @module routes + */ + +import { Router } from 'express'; +import createRateLimiter from '../../middlewares/rateLimit.js'; +import authorize from '../../middlewares/authorize.js'; +import randomFacts from '../../controllers/v3/facts/randomFacts.js'; +import getAllTags from '../../controllers/v3/utils/listTags.js'; +import getOwoify from '../../controllers/v3/utils/owoify.js'; +import getUwuify from '../../controllers/v3/utils/uwuify.js'; +import getUvuify from '../../controllers/v3/utils/uvuify.js'; +import randomWaifus from '../../controllers/v3/waifus/randomWaifus.js'; +import randomPasswords from '../../controllers/v3/utils/randomPassword.js'; +import randomQuotes from '../../controllers/v3/quotes/randomQuotes.js'; +import randomKick from '../../controllers/v3/gifs/randomKick.js'; +import randomKill from '../../controllers/v3/gifs/randomKill.js'; +import randomKissu from '../../controllers/v3/gifs/randomKissu.js'; +import randomMidfing from '../../controllers/v3/gifs/randomMidfing.js'; +import randomNuzzle from '../../controllers/v3/gifs/randomNuzzle.js'; +import randomPunch from '../../controllers/v3/gifs/randomPunch.js'; +import randomShoot from '../../controllers/v3/gifs/randomShoot.js'; +import randomSip from '../../controllers/v3/gifs/randomSip.js'; +import randomSleepy from '../../controllers/v3/gifs/randomSleepy.js'; +import randomSmile from '../../controllers/v3/gifs/randomSmile.js'; +import randomStab from '../../controllers/v3/gifs/randomStab.js'; +import randomStare from '../../controllers/v3/gifs/randomStare.js'; +import randomSuicide from '../../controllers/v3/gifs/randomSuicide.js'; +import randomTease from '../../controllers/v3/gifs/randomTease.js'; +import randomWag from '../../controllers/v3/gifs/randomWag.js'; +import randomBite from '../../controllers/v3/gifs/randomBite.js'; +import randomBlush from '../../controllers/v3/gifs/randomBlush.js'; +import randomBonk from '../../controllers/v3/gifs/randomBonk.js'; +import randomBored from '../../controllers/v3/gifs/randomBored.js'; +import randomBully from '../../controllers/v3/gifs/randomBully.js'; +import randomBye from '../../controllers/v3/gifs/randomBye.js'; +import randomChase from '../../controllers/v3/gifs/randomChase.js'; +import randomCheer from '../../controllers/v3/gifs/randomCheer.js'; +import randomDab from '../../controllers/v3/gifs/randomDab.js'; +import randomDie from '../../controllers/v3/gifs/randomDie.js'; +import randomDisgust from '../../controllers/v3/gifs/randomDisgust.js'; +import randomFeed from '../../controllers/v3/gifs/randomFeed.js'; +import randomHi from '../../controllers/v3/gifs/randomHi.js'; +import randomHold from '../../controllers/v3/gifs/randomHold.js'; +import randomHug from '../../controllers/v3/gifs/randomHug.js'; +import randomNope from '../../controllers/v3/gifs/randomNope.js'; +import randomPanic from '../../controllers/v3/gifs/randomPanic.js'; +import randomPat from '../../controllers/v3/gifs/randomPat.js'; +import randomPeck from '../../controllers/v3/gifs/randomPeck.js'; +import randomPoke from '../../controllers/v3/gifs/randomPoke.js'; +import randomPout from '../../controllers/v3/gifs/randomPout.js'; +import randomRun from '../../controllers/v3/gifs/randomRun.js'; +import randomSad from '../../controllers/v3/gifs/randomSad.js'; +import randomShrug from '../../controllers/v3/gifs/randomShrug.js'; +import randomSlap from '../../controllers/v3/gifs/randomSlap.js'; +import randomSmug from '../../controllers/v3/gifs/randomSmug.js'; +import randomThink from '../../controllers/v3/gifs/randomThink.js'; +import randomThumbsup from '../../controllers/v3/gifs/randomThumbsup.js'; +import randomTickle from '../../controllers/v3/gifs/randomTickle.js'; +import randomTriggered from '../../controllers/v3/gifs/randomTriggered.js'; +import randomWave from '../../controllers/v3/gifs/randomWave.js'; +import randomWink from '../../controllers/v3/gifs/randomWink.js'; +import randomYes from '../../controllers/v3/gifs/randomYes.js'; +import randomAngry from '../../controllers/v3/gifs/randomAngry.js'; +import randomCringe from '../../controllers/v3/gifs/randomCringe.js'; +import randomCry from '../../controllers/v3/gifs/randomCry.js'; +import randomCuddle from '../../controllers/v3/gifs/randomCuddle.js'; +import randomDance from '../../controllers/v3/gifs/randomDance.js'; +import randomFacepalm from '../../controllers/v3/gifs/randomFacepalm.js'; +import randomGlomp from '../../controllers/v3/gifs/randomGlomp.js'; +import randomHappy from '../../controllers/v3/gifs/randomHappy.js'; +import randomHighfive from '../../controllers/v3/gifs/randomHighfive.js'; +import randomLaugh from '../../controllers/v3/gifs/randomLaugh.js'; +import randomLick from '../../controllers/v3/gifs/randomLick.js'; +import randomLove from '../../controllers/v3/gifs/randomLove.js'; +import randomLurk from '../../controllers/v3/gifs/randomLurk.js'; +import randomNervous from '../../controllers/v3/gifs/randomNervous.js'; +import randomNom from '../../controllers/v3/gifs/randomNom.js'; +import randomBaka from '../../controllers/v3/gifs/randomBaka.js'; +import userEndpoint from '../../controllers/v3/utils/user.js'; + +const router = Router(); + +// Base +router.get('/', (req, res) => { + /** + * Endpoint to verify the basic functionality of the API. Returns a success message if the API is working as expected. + */ + res.status(200).json({ + message: 'Working', + }); +}); + +// Base API +router.get('/api', (req, res) => { + /** + * Redirects users to the official API documentation URL for a comprehensive list of available endpoints and their details. + */ + res.redirect('https://docs.waifu.it/list-of-endpoints'); +}); + +// Route: GET /api/v3 +// Description: Endpoint to verify the basic functionality of the API. Returns a success message if the API is working as expected. +router.get('/api/v3', (req, res) => { + // Response with a success message and the current API version + res.status(200).json({ + version: '3.4.14', + message: 'API is functioning correctly.', + }); +}); + +// Fact Endpoints +router.get('/api/v3/fact', createRateLimiter(), authorize(config.roles.USER), randomFacts); +/** + * Retrieves a random fact from a predefined collection of facts. Requires authentication and is rate-limited to prevent abuse. + */ + +// Waifu Endpoint +router.get('/api/v3/waifu', createRateLimiter(), authorize(config.roles.USER), randomWaifus); +/** + * Returns a randomly generated waifu character. Requires authentication and is rate-limited to manage the frequency of requests. + */ + +// Utils Endpoints +router.get('/api/v3/password', createRateLimiter(), authorize(config.roles.USER), randomPasswords); +router.get('/api/v3/alltags', createRateLimiter(), authorize(config.roles.USER), getAllTags); +router.get('/api/v3/owoify', createRateLimiter(), authorize(config.roles.USER), getOwoify); +router.get('/api/v3/uwuify', createRateLimiter(), authorize(config.roles.USER), getUwuify); +router.get('/api/v3/uvuify', createRateLimiter(), authorize(config.roles.USER), getUvuify); +router.all('/api/v3/user', createRateLimiter(), userEndpoint); +/** + * Endpoint responsible for handling user-related operations, such as authenticating users through Discord, + * generating access tokens, and creating new user profiles. The endpoint provides a way for the main website to + * interact with Discord's authentication system and manage user accounts securely. + * + * The ratelimit is applied to control the frequency of requests and mitigate potential abuse. The `userEndpoint` + * controller manages the underlying logic for user-related actions, including token generation and profile creation. + * + * Authentication and token-based authorization are crucial components of this endpoint, ensuring that only authorized + * users can access and manipulate user-related data and functionalities. + */ + +// Random Quote Endpoint +router.get('/api/v3/quote', createRateLimiter(), authorize(config.roles.USER), randomQuotes); +/** + * Retrieves a random quote or saying from a collection of quotes. Requires authentication and is rate-limited to avoid misuse. + */ + +// Random Gifs Endpoints +router.get('/api/v3/kick', createRateLimiter(), authorize(config.roles.USER), randomKick); +router.get('/api/v3/kill', createRateLimiter(), authorize(config.roles.USER), randomKill); +router.get('/api/v3/kiss', createRateLimiter(), authorize(config.roles.USER), randomKissu); +router.get('/api/v3/midfing', createRateLimiter(), authorize(config.roles.USER), randomMidfing); +router.get('/api/v3/nuzzle', createRateLimiter(), authorize(config.roles.USER), randomNuzzle); +router.get('/api/v3/punch', createRateLimiter(), authorize(config.roles.USER), randomPunch); +router.get('/api/v3/shoot', createRateLimiter(), authorize(config.roles.USER), randomShoot); +router.get('/api/v3/sip', createRateLimiter(), authorize(config.roles.USER), randomSip); +router.get('/api/v3/sleepy', createRateLimiter(), authorize(config.roles.USER), randomSleepy); +router.get('/api/v3/smile', createRateLimiter(), authorize(config.roles.USER), randomSmile); +router.get('/api/v3/stab', createRateLimiter(), authorize(config.roles.USER), randomStab); +router.get('/api/v3/stare', createRateLimiter(), authorize(config.roles.USER), randomStare); +router.get('/api/v3/suicide', createRateLimiter(), authorize(config.roles.USER), randomSuicide); +router.get('/api/v3/tease', createRateLimiter(), authorize(config.roles.USER), randomTease); +router.get('/api/v3/wag', createRateLimiter(), authorize(config.roles.USER), randomWag); +router.get('/api/v3/bite', createRateLimiter(), authorize(config.roles.USER), randomBite); +router.get('/api/v3/blush', createRateLimiter(), authorize(config.roles.USER), randomBlush); +router.get('/api/v3/bonk', createRateLimiter(), authorize(config.roles.USER), randomBonk); +router.get('/api/v3/bored', createRateLimiter(), authorize(config.roles.USER), randomBored); +router.get('/api/v3/bully', createRateLimiter(), authorize(config.roles.USER), randomBully); +router.get('/api/v3/bye', createRateLimiter(), authorize(config.roles.USER), randomBye); +router.get('/api/v3/chase', createRateLimiter(), authorize(config.roles.USER), randomChase); +router.get('/api/v3/cheer', createRateLimiter(), authorize(config.roles.USER), randomCheer); +router.get('/api/v3/dab', createRateLimiter(), authorize(config.roles.USER), randomDab); +router.get('/api/v3/die', createRateLimiter(), authorize(config.roles.USER), randomDie); +router.get('/api/v3/disgust', createRateLimiter(), authorize(config.roles.USER), randomDisgust); +router.get('/api/v3/feed', createRateLimiter(), authorize(config.roles.USER), randomFeed); +router.get('/api/v3/hi', createRateLimiter(), authorize(config.roles.USER), randomHi); +router.get('/api/v3/hold', createRateLimiter(), authorize(config.roles.USER), randomHold); +router.get('/api/v3/hug', createRateLimiter(), authorize(config.roles.USER), randomHug); +router.get('/api/v3/Nope', createRateLimiter(), authorize(config.roles.USER), randomNope); +router.get('/api/v3/panic', createRateLimiter(), authorize(config.roles.USER), randomPanic); +router.get('/api/v3/pat', createRateLimiter(), authorize(config.roles.USER), randomPat); +router.get('/api/v3/peck', createRateLimiter(), authorize(config.roles.USER), randomPeck); +router.get('/api/v3/poke', createRateLimiter(), authorize(config.roles.USER), randomPoke); +router.get('/api/v3/punch', createRateLimiter(), authorize(config.roles.USER), randomPunch); +router.get('/api/v3/pout', createRateLimiter(), authorize(config.roles.USER), randomPout); +router.get('/api/v3/run', createRateLimiter(), authorize(config.roles.USER), randomRun); +router.get('/api/v3/sad', createRateLimiter(), authorize(config.roles.USER), randomSad); +router.get('/api/v3/shrug', createRateLimiter(), authorize(config.roles.USER), randomShrug); +router.get('/api/v3/slap', createRateLimiter(), authorize(config.roles.USER), randomSlap); +router.get('/api/v3/smug', createRateLimiter(), authorize(config.roles.USER), randomSmug); +router.get('/api/v3/think', createRateLimiter(), authorize(config.roles.USER), randomThink); +router.get('/api/v3/thumbsup', createRateLimiter(), authorize(config.roles.USER), randomThumbsup); +router.get('/api/v3/tickle', createRateLimiter(), authorize(config.roles.USER), randomTickle); +router.get('/api/v3/triggered', createRateLimiter(), authorize(config.roles.USER), randomTriggered); +router.get('/api/v3/wave', createRateLimiter(), authorize(config.roles.USER), randomWave); +router.get('/api/v3/wink', createRateLimiter(), authorize(config.roles.USER), randomWink); +router.get('/api/v3/yes', createRateLimiter(), authorize(config.roles.USER), randomYes); +router.get('/api/v3/angry', createRateLimiter(), authorize(config.roles.USER), randomAngry); +router.get('/api/v3/cringe', createRateLimiter(), authorize(config.roles.USER), randomCringe); +router.get('/api/v3/cry', createRateLimiter(), authorize(config.roles.USER), randomCry); +router.get('/api/v3/cuddle', createRateLimiter(), authorize(config.roles.USER), randomCuddle); +router.get('/api/v3/dance', createRateLimiter(), authorize(config.roles.USER), randomDance); +router.get('/api/v3/facepalm', createRateLimiter(), authorize(config.roles.USER), randomFacepalm); +router.get('/api/v3/glomp', createRateLimiter(), authorize(config.roles.USER), randomGlomp); +router.get('/api/v3/happy', createRateLimiter(), authorize(config.roles.USER), randomHappy); +router.get('/api/v3/highfive', createRateLimiter(), authorize(config.roles.USER), randomHighfive); +router.get('/api/v3/hug', createRateLimiter(), authorize(config.roles.USER), randomHug); +router.get('/api/v3/laugh', createRateLimiter(), authorize(config.roles.USER), randomLaugh); +router.get('/api/v3/lick', createRateLimiter(), authorize(config.roles.USER), randomLick); +router.get('/api/v3/love', createRateLimiter(), authorize(config.roles.USER), randomLove); +router.get('/api/v3/lurk', createRateLimiter(), authorize(config.roles.USER), randomLurk); +router.get('/api/v3/nervous', createRateLimiter(), authorize(config.roles.USER), randomNervous); +router.get('/api/v3/nom', createRateLimiter(), authorize(config.roles.USER), randomNom); +router.get('/api/v3/baka', createRateLimiter(), authorize(config.roles.USER), randomBaka); + +// Note: The comments for the remaining endpoints (utils and GIFs) follow a similar structure of explaining the purpose, +// authentication requirement, and rate-limiting aspect of each endpoint. + +export default router; diff --git a/src/routes/v4/images/waifu.js b/src/routes/v4/images/waifu.js new file mode 100644 index 0000000..8ae90ac --- /dev/null +++ b/src/routes/v4/images/waifu.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getWaifu from '../../../controllers/v4/images/waifu.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/waifu Get a Random Waifu + * @apiDescription Retrieve a random Waifu. + * @apiName getWaifu + * @apiGroup images + * @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(), getWaifu) + /** + * @api {post} v4/waifu Increment Waifu Data + * @apiDescription Increment data related to Waifus (only accessible by database moderators). + * @apiName IncrementWaifuData + * @apiGroup images + * @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('Waifu')); + +router + .route('/:id') + /** + * @api {patch} v4/waifu/:id Update Waifu Data + * @apiDescription Update data related to Waifus with a specific ID (only accessible by database moderators). + * @apiName UpdateWaifuData + * @apiGroup Waifu + * @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('Waifu')) + /** + * @api {delete} v4/waifu/:id Delete Waifu Data + * @apiDescription Delete data related to Waifu with a specific ID (only accessible by admins). + * @apiName DeleteWaifuData + * @apiGroup Waifu + * @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('Waifu')); +// Export the router +export default router; diff --git a/src/routes/v4/index.js b/src/routes/v4/index.js new file mode 100644 index 0000000..15865da --- /dev/null +++ b/src/routes/v4/index.js @@ -0,0 +1,1167 @@ +// routes/index.js +import { Router } from 'express'; + +/** + * Express Router for handling API routes. + * @type {Router} + * @namespace routes + */ +const router = Router(); + +import factRoutes from './textUtilities/fact.js'; + +/** + * @api {use} v4/fact Use Fact Routes + * @apiDescription Mount the fact-related routes for handling text utilities. + * @apiName UseFactRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Fact-related routes mounted on the parent router. + * + * @function createFactRoutes + * @description Creates and returns a set of routes for handling text utilities related to facts. + * @returns {Object} Fact-related routes. + */ +router.use('/fact', factRoutes); + +import listTagsRoutes from './textUtilities/listTags.js'; + +/** + * @api {use} v4/listTags Use ListTags Routes + * @apiDescription Mount the listTags-related routes for handling text utilities. + * @apiName UseListTagsRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes ListTags-related routes mounted on the parent router. + * + * @function createListTagsRoutes + * @description Creates and returns a set of routes for handling text utilities related to listTags. + * @returns {Object} ListTags-related routes. + */ +router.use('/listTags', listTagsRoutes); + +import owoifyRoutes from './textUtilities/owoify.js'; + +/** + * @api {use} v4/owoify Use Owoify Routes + * @apiDescription Mount the owoify-related routes for handling text utilities. + * @apiName UseOwoifyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Owoify-related routes mounted on the parent router. + * + * @function createOwoifyRoutes + * @description Creates and returns a set of routes for handling text utilities related to owoify. + * @returns {Object} Owoify-related routes. + */ +router.use('/owoify', owoifyRoutes); + +import passwordRoutes from './textUtilities/password.js'; + +/** + * @api {use} v4/password Use Password Routes + * @apiDescription Mount the password-related routes for handling text utilities. + * @apiName UsePasswordRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Password-related routes mounted on the parent router. + * + * @function createPasswordRoutes + * @description Creates and returns a set of routes for handling text utilities related to password. + * @returns {Object} Password-related routes. + */ +router.use('/password', passwordRoutes); + +import uvuifyRoutes from './textUtilities/uvuify.js'; + +/** + * @api {use} v4/uvuify Use Uvuify Routes + * @apiDescription Mount the uvuify-related routes for handling text utilities. + * @apiName UseUvuifyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Uvuify-related routes mounted on the parent router. + * + * @function createUvuifyRoutes + * @description Creates and returns a set of routes for handling text utilities related to uvuify. + * @returns {Object} Uvuify-related routes. + */ +router.use('/uvuify', uvuifyRoutes); + +import uwuifyRoutes from './textUtilities/uwuify.js'; + +/** + * @api {use} v4/uwuify Use Uwuify Routes + * @apiDescription Mount the uwuify-related routes for handling text utilities. + * @apiName UseUwuifyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Uwuify-related routes mounted on the parent router. + * + * @function createUwuifyRoutes + * @description Creates and returns a set of routes for handling text utilities related to uwuify. + * @returns {Object} Uwuify-related routes. + */ +router.use('/uwuify', uwuifyRoutes); + +import waifuRoutes from './images/waifu.js'; + +/** + * @api {use} v4/waifu Use Waifu Routes + * @apiDescription Mount the waifu-related routes for handling images. + * @apiName UseWaifuRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Uwuify-related routes mounted on the parent router. + * + * @function createUwuifyRoutes + * @description Creates and returns a set of routes for handling images related to waifu. + * @returns {Object} Waifu-related routes. + */ +router.use('/waifu', waifuRoutes); + +import userRoutes from './internal/user.js'; + +/** + * @api {use} v4/user Use User Routes + * @apiDescription Mount the user-related routes for handling images. + * @apiName UseUserRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes User-related routes mounted on the parent router. + * + * @function createUserRoutes + * @description Creates and returns a set of routes for handling user data. + * @returns {Object} Waifu-related routes. + */ +router.use('/user', userRoutes); + +import angryRoutes from './interactions/angry.js'; + +/** + * @api {use} v4/angry Use Angry Routes + * @apiDescription Mount the angry-related routes for handling interactions. + * @apiName UseAngryRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Angry-related routes mounted on the parent router. + * + * @function createAngryRoutes + * @description Creates and returns a set of routes for handling interactions related to angry. + * @returns {Object} Angry-related routes. + */ +router.use('/angry', angryRoutes); + +import bakaRoutes from './interactions/baka.js'; + +/** + * @api {use} v4/baka Use Baka Routes + * @apiDescription Mount the baka-related routes for handling interactions. + * @apiName UseBakaRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Baka-related routes mounted on the parent router. + * + * @function createBakaRoutes + * @description Creates and returns a set of routes for handling interactions related to baka. + * @returns {Object} Baka-related routes. + */ +router.use('/baka', bakaRoutes); + +import biteRoutes from './interactions/bite.js'; + +/** + * @api {use} v4/bite Use Bite Routes + * @apiDescription Mount the bite-related routes for handling interactions. + * @apiName UseBiteRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Bite-related routes mounted on the parent router. + * + * @function createBiteRoutes + * @description Creates and returns a set of routes for handling interactions related to bite. + * @returns {Object} Bite-related routes. + */ +router.use('/bite', biteRoutes); + +import blushRoutes from './interactions/blush.js'; + +/** + * @api {use} v4/blush Use Blush Routes + * @apiDescription Mount the blush-related routes for handling interactions. + * @apiName UseBlushRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Blush-related routes mounted on the parent router. + * + * @function createBlushRoutes + * @description Creates and returns a set of routes for handling interactions related to blush. + * @returns {Object} Blush-related routes. + */ +router.use('/blush', blushRoutes); + +import bonkRoutes from './interactions/bonk.js'; + +/** + * @api {use} v4/bonk Use Bonk Routes + * @apiDescription Mount the bonk-related routes for handling interactions. + * @apiName UseBonkRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Bonk-related routes mounted on the parent router. + * + * @function createBonkRoutes + * @description Creates and returns a set of routes for handling interactions related to bonk. + * @returns {Object} Bonk-related routes. + */ +router.use('/bonk', bonkRoutes); + +import boredRoutes from './interactions/bored.js'; + +/** + * @api {use} v4/bored Use Bored Routes + * @apiDescription Mount the bored-related routes for handling interactions. + * @apiName UseBoredRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Bored-related routes mounted on the parent router. + * + * @function createBoredRoutes + * @description Creates and returns a set of routes for handling interactions related to bored. + * @returns {Object} Bored-related routes. + */ +router.use('/bored', boredRoutes); + +import bullyRoutes from './interactions/bully.js'; + +/** + * @api {use} v4/bully Use Bully Routes + * @apiDescription Mount the bully-related routes for handling interactions. + * @apiName UseBullyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Bully-related routes mounted on the parent router. + * + * @function createBullyRoutes + * @description Creates and returns a set of routes for handling interactions related to bully. + * @returns {Object} Bully-related routes. + */ +router.use('/bully', bullyRoutes); + +import byeRoutes from './interactions/bye.js'; + +/** + * @api {use} v4/bye Use Bye Routes + * @apiDescription Mount the bye-related routes for handling interactions. + * @apiName UseByeRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Bye-related routes mounted on the parent router. + * + * @function createByeRoutes + * @description Creates and returns a set of routes for handling interactions related to bye. + * @returns {Object} Bye-related routes. + */ +router.use('/bye', byeRoutes); + +import chaseRoutes from './interactions/chase.js'; + +/** + * @api {use} v4/chase Use Chase Routes + * @apiDescription Mount the chase-related routes for handling interactions. + * @apiName UseChaseRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Chase-related routes mounted on the parent router. + * + * @function createChaseRoutes + * @description Creates and returns a set of routes for handling interactions related to chase. + * @returns {Object} Chase-related routes. + */ +router.use('/chase', chaseRoutes); + +import cheerRoutes from './interactions/cheer.js'; + +/** + * @api {use} v4/cheer Use Cheer Routes + * @apiDescription Mount the cheer-related routes for handling interactions. + * @apiName UseCheerRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Cheer-related routes mounted on the parent router. + * + * @function createCheerRoutes + * @description Creates and returns a set of routes for handling interactions related to cheer. + * @returns {Object} Cheer-related routes. + */ +router.use('/cheer', cheerRoutes); + +import cringeRoutes from './interactions/cringe.js'; + +/** + * @api {use} v4/cringe Use Cringe Routes + * @apiDescription Mount the cringe-related routes for handling interactions. + * @apiName UseCringeRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Cringe-related routes mounted on the parent router. + * + * @function createCringeRoutes + * @description Creates and returns a set of routes for handling interactions related to cringe. + * @returns {Object} Cringe-related routes. + */ +router.use('/cringe', cringeRoutes); + +import cryRoutes from './interactions/cry.js'; + +/** + * @api {use} v4/cry Use Cry Routes + * @apiDescription Mount the cry-related routes for handling interactions. + * @apiName UseCryRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Cry-related routes mounted on the parent router. + * + * @function createCryRoutes + * @description Creates and returns a set of routes for handling interactions related to cry. + * @returns {Object} Cry-related routes. + */ +router.use('/cry', cryRoutes); + +import cuddleRoutes from './interactions/cuddle.js'; + +/** + * @api {use} v4/cuddle Use Cuddle Routes + * @apiDescription Mount the cuddle-related routes for handling interactions. + * @apiName UseCuddleRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Cuddle-related routes mounted on the parent router. + * + * @function createCuddleRoutes + * @description Creates and returns a set of routes for handling interactions related to cuddle. + * @returns {Object} Cuddle-related routes. + */ +router.use('/cuddle', cuddleRoutes); + +import dabRoutes from './interactions/dab.js'; + +/** + * @api {use} v4/dab Use Dab Routes + * @apiDescription Mount the dab-related routes for handling interactions. + * @apiName UseDabRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Dab-related routes mounted on the parent router. + * + * @function createDabRoutes + * @description Creates and returns a set of routes for handling interactions related to dab. + * @returns {Object} Dab-related routes. + */ +router.use('/dab', dabRoutes); + +import danceRoutes from './interactions/dance.js'; + +/** + * @api {use} v4/dance Use Dance Routes + * @apiDescription Mount the dance-related routes for handling interactions. + * @apiName UseDanceRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Dance-related routes mounted on the parent router. + * + * @function createDanceRoutes + * @description Creates and returns a set of routes for handling interactions related to dance. + * @returns {Object} Dance-related routes. + */ +router.use('/dance', danceRoutes); + +import dieRoutes from './interactions/die.js'; + +/** + * @api {use} v4/die Use Die Routes + * @apiDescription Mount the die-related routes for handling interactions. + * @apiName UseDieRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Die-related routes mounted on the parent router. + * + * @function createDieRoutes + * @description Creates and returns a set of routes for handling interactions related to die. + * @returns {Object} Die-related routes. + */ +router.use('/die', dieRoutes); + +import disgustRoutes from './interactions/disgust.js'; + +/** + * @api {use} v4/disgust Use Disgust Routes + * @apiDescription Mount the disgust-related routes for handling interactions. + * @apiName UseDisgustRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Disgust-related routes mounted on the parent router. + * + * @function createDisgustRoutes + * @description Creates and returns a set of routes for handling interactions related to disgust. + * @returns {Object} Disgust-related routes. + */ +router.use('/disgust', disgustRoutes); + +import facepalmRoutes from './interactions/facepalm.js'; + +/** + * @api {use} v4/facepalm Use Facepalm Routes + * @apiDescription Mount the facepalm-related routes for handling interactions. + * @apiName UseFacepalmRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Facepalm-related routes mounted on the parent router. + * + * @function createFacepalmRoutes + * @description Creates and returns a set of routes for handling interactions related to facepalm. + * @returns {Object} Facepalm-related routes. + */ +router.use('/facepalm', facepalmRoutes); + +import feedRoutes from './interactions/feed.js'; + +/** + * @api {use} v4/feed Use Feed Routes + * @apiDescription Mount the feed-related routes for handling interactions. + * @apiName UseFeedRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Feed-related routes mounted on the parent router. + * + * @function createFeedRoutes + * @description Creates and returns a set of routes for handling interactions related to feed. + * @returns {Object} Feed-related routes. + */ +router.use('/feed', feedRoutes); + +import glompRoutes from './interactions/glomp.js'; + +/** + * @api {use} v4/glomp Use Glomp Routes + * @apiDescription Mount the glomp-related routes for handling interactions. + * @apiName UseGlompRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Glomp-related routes mounted on the parent router. + * + * @function createGlompRoutes + * @description Creates and returns a set of routes for handling interactions related to glomp. + * @returns {Object} Glomp-related routes. + */ +router.use('/glomp', glompRoutes); + +import happyRoutes from './interactions/happy.js'; + +/** + * @api {use} v4/happy Use Happy Routes + * @apiDescription Mount the happy-related routes for handling interactions. + * @apiName UseHappyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Happy-related routes mounted on the parent router. + * + * @function createHappyRoutes + * @description Creates and returns a set of routes for handling interactions related to happy. + * @returns {Object} Happy-related routes. + */ +router.use('/happy', happyRoutes); + +import hiRoutes from './interactions/hi.js'; + +/** + * @api {use} v4/hi Use Hi Routes + * @apiDescription Mount the hi-related routes for handling interactions. + * @apiName UseHiRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Hi-related routes mounted on the parent router. + * + * @function createHiRoutes + * @description Creates and returns a set of routes for handling interactions related to hi. + * @returns {Object} Hi-related routes. + */ +router.use('/hi', hiRoutes); + +import highfiveRoutes from './interactions/highfive.js'; + +/** + * @api {use} v4/highfive Use Highfive Routes + * @apiDescription Mount the highfive-related routes for handling interactions. + * @apiName UseHighfiveRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Highfive-related routes mounted on the parent router. + * + * @function createHighfiveRoutes + * @description Creates and returns a set of routes for handling interactions related to highfive. + * @returns {Object} Highfive-related routes. + */ +router.use('/highfive', highfiveRoutes); + +import holdRoutes from './interactions/hold.js'; + +/** + * @api {use} v4/hold Use Hold Routes + * @apiDescription Mount the hold-related routes for handling interactions. + * @apiName UseHoldRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Hold-related routes mounted on the parent router. + * + * @function createHoldRoutes + * @description Creates and returns a set of routes for handling interactions related to hold. + * @returns {Object} Hold-related routes. + */ +router.use('/hold', holdRoutes); + +import hugRoutes from './interactions/hug.js'; + +/** + * @api {use} v4/hug Use Hug Routes + * @apiDescription Mount the hug-related routes for handling interactions. + * @apiName UseHugRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Hug-related routes mounted on the parent router. + * + * @function createHugRoutes + * @description Creates and returns a set of routes for handling interactions related to hug. + * @returns {Object} Hug-related routes. + */ +router.use('/hug', hugRoutes); + +import kickRoutes from './interactions/kick.js'; + +/** + * @api {use} v4/kick Use Kick Routes + * @apiDescription Mount the kick-related routes for handling interactions. + * @apiName UseKickRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Kick-related routes mounted on the parent router. + * + * @function createKickRoutes + * @description Creates and returns a set of routes for handling interactions related to kick. + * @returns {Object} Kick-related routes. + */ +router.use('/kick', kickRoutes); + +import killRoutes from './interactions/kill.js'; + +/** + * @api {use} v4/kill Use Kill Routes + * @apiDescription Mount the kill-related routes for handling interactions. + * @apiName UseKillRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Kill-related routes mounted on the parent router. + * + * @function createKillRoutes + * @description Creates and returns a set of routes for handling interactions related to kill. + * @returns {Object} Kill-related routes. + */ +router.use('/kill', killRoutes); + +import kissRoutes from './interactions/kiss.js'; + +/** + * @api {use} v4/kiss Use Kiss Routes + * @apiDescription Mount the kiss-related routes for handling interactions. + * @apiName UseKissRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Kiss-related routes mounted on the parent router. + * + * @function createKissRoutes + * @description Creates and returns a set of routes for handling interactions related to kiss. + * @returns {Object} Kiss-related routes. + */ +router.use('/kiss', kissRoutes); + +import laughRoutes from './interactions/laugh.js'; + +/** + * @api {use} v4/laugh Use Laugh Routes + * @apiDescription Mount the laugh-related routes for handling interactions. + * @apiName UseLaughRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Laugh-related routes mounted on the parent router. + * + * @function createLaughRoutes + * @description Creates and returns a set of routes for handling interactions related to laugh. + * @returns {Object} Laugh-related routes. + */ +router.use('/laugh', laughRoutes); + +import lickRoutes from './interactions/lick.js'; + +/** + * @api {use} v4/lick Use Lick Routes + * @apiDescription Mount the lick-related routes for handling interactions. + * @apiName UseLickRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Lick-related routes mounted on the parent router. + * + * @function createLickRoutes + * @description Creates and returns a set of routes for handling interactions related to lick. + * @returns {Object} Lick-related routes. + */ +router.use('/lick', lickRoutes); + +import loveRoutes from './interactions/love.js'; + +/** + * @api {use} v4/love Use Love Routes + * @apiDescription Mount the love-related routes for handling interactions. + * @apiName UseLoveRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Love-related routes mounted on the parent router. + * + * @function createLoveRoutes + * @description Creates and returns a set of routes for handling interactions related to love. + * @returns {Object} Love-related routes. + */ +router.use('/love', loveRoutes); + +import lurkRoutes from './interactions/lurk.js'; + +/** + * @api {use} v4/lurk Use Lurk Routes + * @apiDescription Mount the lurk-related routes for handling interactions. + * @apiName UseLurkRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Lurk-related routes mounted on the parent router. + * + * @function createLurkRoutes + * @description Creates and returns a set of routes for handling interactions related to lurk. + * @returns {Object} Lurk-related routes. + */ +router.use('/lurk', lurkRoutes); + +import midfingRoutes from './interactions/midfing.js'; + +/** + * @api {use} v4/midfing Use Midfing Routes + * @apiDescription Mount the midfing-related routes for handling interactions. + * @apiName UseMidfingRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Midfing-related routes mounted on the parent router. + * + * @function createMidfingRoutes + * @description Creates and returns a set of routes for handling interactions related to midfing. + * @returns {Object} Midfing-related routes. + */ +router.use('/midfing', midfingRoutes); + +import nervousRoutes from './interactions/nervous.js'; + +/** + * @api {use} v4/nervous Use Nervous Routes + * @apiDescription Mount the nervous-related routes for handling interactions. + * @apiName UseNervousRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Nervous-related routes mounted on the parent router. + * + * @function createNervousRoutes + * @description Creates and returns a set of routes for handling interactions related to nervous. + * @returns {Object} Nervous-related routes. + */ +router.use('/nervous', nervousRoutes); + +import nomRoutes from './interactions/nom.js'; + +/** + * @api {use} v4/nom Use Nom Routes + * @apiDescription Mount the nom-related routes for handling interactions. + * @apiName UseNomRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Nom-related routes mounted on the parent router. + * + * @function createNomRoutes + * @description Creates and returns a set of routes for handling interactions related to nom. + * @returns {Object} Nom-related routes. + */ +router.use('/nom', nomRoutes); + +import nopeRoutes from './interactions/nope.js'; + +/** + * @api {use} v4/nope Use Nope Routes + * @apiDescription Mount the nope-related routes for handling interactions. + * @apiName UseNopeRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Nope-related routes mounted on the parent router. + * + * @function createNopeRoutes + * @description Creates and returns a set of routes for handling interactions related to nope. + * @returns {Object} Nope-related routes. + */ +router.use('/nope', nopeRoutes); + +import nuzzleRoutes from './interactions/nuzzle.js'; + +/** + * @api {use} v4/nuzzle Use Nuzzle Routes + * @apiDescription Mount the nuzzle-related routes for handling interactions. + * @apiName UseNuzzleRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Nuzzle-related routes mounted on the parent router. + * + * @function createNuzzleRoutes + * @description Creates and returns a set of routes for handling interactions related to nuzzle. + * @returns {Object} Nuzzle-related routes. + */ +router.use('/nuzzle', nuzzleRoutes); + +import panicRoutes from './interactions/panic.js'; + +/** + * @api {use} v4/panic Use Panic Routes + * @apiDescription Mount the panic-related routes for handling interactions. + * @apiName UsePanicRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Panic-related routes mounted on the parent router. + * + * @function createPanicRoutes + * @description Creates and returns a set of routes for handling interactions related to panic. + * @returns {Object} Panic-related routes. + */ +router.use('/panic', panicRoutes); + +import patRoutes from './interactions/pat.js'; + +/** + * @api {use} v4/pat Use Pat Routes + * @apiDescription Mount the pat-related routes for handling interactions. + * @apiName UsePatRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Pat-related routes mounted on the parent router. + * + * @function createPatRoutes + * @description Creates and returns a set of routes for handling interactions related to pat. + * @returns {Object} Pat-related routes. + */ +router.use('/pat', patRoutes); + +import peckRoutes from './interactions/peck.js'; + +/** + * @api {use} v4/peck Use Peck Routes + * @apiDescription Mount the peck-related routes for handling interactions. + * @apiName UsePeckRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Peck-related routes mounted on the parent router. + * + * @function createPeckRoutes + * @description Creates and returns a set of routes for handling interactions related to peck. + * @returns {Object} Peck-related routes. + */ +router.use('/peck', peckRoutes); + +import pokeRoutes from './interactions/poke.js'; + +/** + * @api {use} v4/poke Use Poke Routes + * @apiDescription Mount the poke-related routes for handling interactions. + * @apiName UsePokeRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Poke-related routes mounted on the parent router. + * + * @function createPokeRoutes + * @description Creates and returns a set of routes for handling interactions related to poke. + * @returns {Object} Poke-related routes. + */ +router.use('/poke', pokeRoutes); + +import poutRoutes from './interactions/pout.js'; + +/** + * @api {use} v4/pout Use Pout Routes + * @apiDescription Mount the pout-related routes for handling interactions. + * @apiName UsePoutRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Pout-related routes mounted on the parent router. + * + * @function createPoutRoutes + * @description Creates and returns a set of routes for handling interactions related to pout. + * @returns {Object} Pout-related routes. + */ +router.use('/pout', poutRoutes); + +import punchRoutes from './interactions/punch.js'; + +/** + * @api {use} v4/punch Use Punch Routes + * @apiDescription Mount the punch-related routes for handling interactions. + * @apiName UsePunchRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Punch-related routes mounted on the parent router. + * + * @function createPunchRoutes + * @description Creates and returns a set of routes for handling interactions related to punch. + * @returns {Object} Punch-related routes. + */ +router.use('/punch', punchRoutes); + +import runRoutes from './interactions/run.js'; + +/** + * @api {use} v4/run Use Run Routes + * @apiDescription Mount the run-related routes for handling interactions. + * @apiName UseRunRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Run-related routes mounted on the parent router. + * + * @function createRunRoutes + * @description Creates and returns a set of routes for handling interactions related to run. + * @returns {Object} Run-related routes. + */ +router.use('/run', runRoutes); + +import sadRoutes from './interactions/sad.js'; + +/** + * @api {use} v4/sad Use Sad Routes + * @apiDescription Mount the sad-related routes for handling interactions. + * @apiName UseSadRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Sad-related routes mounted on the parent router. + * + * @function createSadRoutes + * @description Creates and returns a set of routes for handling interactions related to sad. + * @returns {Object} Sad-related routes. + */ +router.use('/sad', sadRoutes); + +import shootRoutes from './interactions/shoot.js'; + +/** + * @api {use} v4/shoot Use Shoot Routes + * @apiDescription Mount the shoot-related routes for handling interactions. + * @apiName UseShootRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Shoot-related routes mounted on the parent router. + * + * @function createShootRoutes + * @description Creates and returns a set of routes for handling interactions related to shoot. + * @returns {Object} Shoot-related routes. + */ +router.use('/shoot', shootRoutes); + +import shrugRoutes from './interactions/shrug.js'; + +/** + * @api {use} v4/shrug Use Shrug Routes + * @apiDescription Mount the shrug-related routes for handling interactions. + * @apiName UseShrugRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Shrug-related routes mounted on the parent router. + * + * @function createShrugRoutes + * @description Creates and returns a set of routes for handling interactions related to shrug. + * @returns {Object} Shrug-related routes. + */ +router.use('/shrug', shrugRoutes); + +import sipRoutes from './interactions/sip.js'; + +/** + * @api {use} v4/sip Use Sip Routes + * @apiDescription Mount the sip-related routes for handling interactions. + * @apiName UseSipRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Sip-related routes mounted on the parent router. + * + * @function createSipRoutes + * @description Creates and returns a set of routes for handling interactions related to sip. + * @returns {Object} Sip-related routes. + */ +router.use('/sip', sipRoutes); + +import slapRoutes from './interactions/slap.js'; + +/** + * @api {use} v4/slap Use Slap Routes + * @apiDescription Mount the slap-related routes for handling interactions. + * @apiName UseSlapRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Slap-related routes mounted on the parent router. + * + * @function createSlapRoutes + * @description Creates and returns a set of routes for handling interactions related to slap. + * @returns {Object} Slap-related routes. + */ +router.use('/slap', slapRoutes); + +import sleepyRoutes from './interactions/sleepy.js'; + +/** + * @api {use} v4/sleepy Use Sleepy Routes + * @apiDescription Mount the sleepy-related routes for handling interactions. + * @apiName UseSleepyRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Sleepy-related routes mounted on the parent router. + * + * @function createSleepyRoutes + * @description Creates and returns a set of routes for handling interactions related to sleepy. + * @returns {Object} Sleepy-related routes. + */ +router.use('/sleepy', sleepyRoutes); + +import smileRoutes from './interactions/smile.js'; + +/** + * @api {use} v4/smile Use Smile Routes + * @apiDescription Mount the smile-related routes for handling interactions. + * @apiName UseSmileRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Smile-related routes mounted on the parent router. + * + * @function createSmileRoutes + * @description Creates and returns a set of routes for handling interactions related to smile. + * @returns {Object} Smile-related routes. + */ +router.use('/smile', smileRoutes); + +import smugRoutes from './interactions/smug.js'; + +/** + * @api {use} v4/smug Use Smug Routes + * @apiDescription Mount the smug-related routes for handling interactions. + * @apiName UseSmugRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Smug-related routes mounted on the parent router. + * + * @function createSmugRoutes + * @description Creates and returns a set of routes for handling interactions related to smug. + * @returns {Object} Smug-related routes. + */ +router.use('/smug', smugRoutes); + +import stabRoutes from './interactions/stab.js'; + +/** + * @api {use} v4/stab Use Stab Routes + * @apiDescription Mount the stab-related routes for handling interactions. + * @apiName UseStabRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Stab-related routes mounted on the parent router. + * + * @function createStabRoutes + * @description Creates and returns a set of routes for handling interactions related to stab. + * @returns {Object} Stab-related routes. + */ +router.use('/stab', stabRoutes); + +import stareRoutes from './interactions/stare.js'; + +/** + * @api {use} v4/stare Use Stare Routes + * @apiDescription Mount the stare-related routes for handling interactions. + * @apiName UseStareRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Stare-related routes mounted on the parent router. + * + * @function createStareRoutes + * @description Creates and returns a set of routes for handling interactions related to stare. + * @returns {Object} Stare-related routes. + */ +router.use('/stare', stareRoutes); + +import suicideRoutes from './interactions/suicide.js'; + +/** + * @api {use} v4/suicide Use Suicide Routes + * @apiDescription Mount the suicide-related routes for handling interactions. + * @apiName UseSuicideRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Suicide-related routes mounted on the parent router. + * + * @function createSuicideRoutes + * @description Creates and returns a set of routes for handling interactions related to suicide. + * @returns {Object} Suicide-related routes. + */ +router.use('/suicide', suicideRoutes); + +import teaseRoutes from './interactions/tease.js'; + +/** + * @api {use} v4/tease Use Tease Routes + * @apiDescription Mount the tease-related routes for handling interactions. + * @apiName UseTeaseRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Tease-related routes mounted on the parent router. + * + * @function createTeaseRoutes + * @description Creates and returns a set of routes for handling interactions related to tease. + * @returns {Object} Tease-related routes. + */ +router.use('/tease', teaseRoutes); + +import thinkRoutes from './interactions/think.js'; + +/** + * @api {use} v4/think Use Think Routes + * @apiDescription Mount the think-related routes for handling interactions. + * @apiName UseThinkRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Think-related routes mounted on the parent router. + * + * @function createThinkRoutes + * @description Creates and returns a set of routes for handling interactions related to think. + * @returns {Object} Think-related routes. + */ +router.use('/think', thinkRoutes); + +import thumbsupRoutes from './interactions/thumbsup.js'; + +/** + * @api {use} v4/thumbsup Use Thumbsup Routes + * @apiDescription Mount the thumbsup-related routes for handling interactions. + * @apiName UseThumbsupRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Thumbsup-related routes mounted on the parent router. + * + * @function createThumbsupRoutes + * @description Creates and returns a set of routes for handling interactions related to thumbsup. + * @returns {Object} Thumbsup-related routes. + */ +router.use('/thumbsup', thumbsupRoutes); + +import tickleRoutes from './interactions/tickle.js'; + +/** + * @api {use} v4/tickle Use Tickle Routes + * @apiDescription Mount the tickle-related routes for handling interactions. + * @apiName UseTickleRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Tickle-related routes mounted on the parent router. + * + * @function createTickleRoutes + * @description Creates and returns a set of routes for handling interactions related to tickle. + * @returns {Object} Tickle-related routes. + */ +router.use('/tickle', tickleRoutes); + +import triggeredRoutes from './interactions/triggered.js'; + +/** + * @api {use} v4/triggered Use Triggered Routes + * @apiDescription Mount the triggered-related routes for handling interactions. + * @apiName UseTriggeredRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Triggered-related routes mounted on the parent router. + * + * @function createTriggeredRoutes + * @description Creates and returns a set of routes for handling interactions related to triggered. + * @returns {Object} Triggered-related routes. + */ +router.use('/triggered', triggeredRoutes); + +import wagRoutes from './interactions/wag.js'; + +/** + * @api {use} v4/wag Use Wag Routes + * @apiDescription Mount the wag-related routes for handling interactions. + * @apiName UseWagRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Wag-related routes mounted on the parent router. + * + * @function createWagRoutes + * @description Creates and returns a set of routes for handling interactions related to wag. + * @returns {Object} Wag-related routes. + */ +router.use('/wag', wagRoutes); + +import waveRoutes from './interactions/wave.js'; + +/** + * @api {use} v4/wave Use Wave Routes + * @apiDescription Mount the wave-related routes for handling interactions. + * @apiName UseWaveRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Wave-related routes mounted on the parent router. + * + * @function createWaveRoutes + * @description Creates and returns a set of routes for handling interactions related to wave. + * @returns {Object} Wave-related routes. + */ +router.use('/wave', waveRoutes); + +import winkRoutes from './interactions/wink.js'; + +/** + * @api {use} v4/wink Use Wink Routes + * @apiDescription Mount the wink-related routes for handling interactions. + * @apiName UseWinkRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Wink-related routes mounted on the parent router. + * + * @function createWinkRoutes + * @description Creates and returns a set of routes for handling interactions related to wink. + * @returns {Object} Wink-related routes. + */ +router.use('/wink', winkRoutes); + +import yesRoutes from './interactions/yes.js'; + +/** + * @api {use} v4/yes Use Yes Routes + * @apiDescription Mount the yes-related routes for handling interactions. + * @apiName UseYesRoutes + * @apiGroup Routes + * + * @apiSuccess {Object} routes Yes-related routes mounted on the parent router. + * + * @function createYesRoutes + * @description Creates and returns a set of routes for handling interactions related to yes. + * @returns {Object} Yes-related routes. + */ +router.use('/yes', yesRoutes); + +/** + * Exporting the router for use in other parts of the application. + * @exports {Router} router - Express Router instance with mounted routes. + */ +export default router; 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; diff --git a/src/routes/v4/internal/user.js b/src/routes/v4/internal/user.js new file mode 100644 index 0000000..8319fcf --- /dev/null +++ b/src/routes/v4/internal/user.js @@ -0,0 +1,91 @@ +import { Router } from 'express'; +import { userEndpoint, retrieveUserProfile, updateUserToken } from '../../../controllers/v4/internal/user.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {post} v4/user Get User Details + * @apiDescription Get details about the authenticated user. + * @apiName getUserDetails + * @apiGroup UserManagement + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object} userDetails User's details. + * @apiSuccess {String} userDetails.username User's username. + * @apiSuccess {String} userDetails.email User's email address. + * @apiSuccess {String} userDetails.avatar User's avatar URL. + * @apiSuccess {Date} userDetails.createdAt Date when the user profile was created. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .post(createRateLimiter(), userEndpoint); + +router + .route('/profile/:id') + /** + * @api {get} v4/user/profile/:id Get User Profile + * @apiDescription Get the profile of a specific user. + * @apiName retrieveUserProfile + * @apiGroup UserManagement + * @apiPermission sudo + * + * @apiHeader {String} Authorization User's access token. + * + * @apiParam {String} id User's unique identifier. + * + * @apiSuccess {Object} userProfile User's profile information. + * @apiSuccess {String} userProfile.username User's username. + * @apiSuccess {String} userProfile.email User's email address. + * @apiSuccess {String} userProfile.avatar User's avatar URL. + * @apiSuccess {Date} userProfile.createdAt Date when the user profile was created. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(createRateLimiter(), retrieveUserProfile) + /** + * @api {patch} v4/user/profile/:id Get User Profile and Update reset the existing token + * @apiDescription Update the token for a specific user + * @apiName updateUserToken + * @apiGroup UserManagement + * @apiPermission sudo + * + * @apiHeader {String} Authorization User's access token. + * + * @apiParam {String} id User's unique identifier. + * + * @apiSuccess {Object} message + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .patch(createRateLimiter(), updateUserToken); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/fact.js b/src/routes/v4/textUtilities/fact.js new file mode 100644 index 0000000..b08da20 --- /dev/null +++ b/src/routes/v4/textUtilities/fact.js @@ -0,0 +1,103 @@ +import { Router } from 'express'; +import getFact from '../../../controllers/v4/textUtilities/fact.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/fact Get a Random Fact + * @apiDescription Retrieve a random fact. + * @apiName GetFact + * @apiGroup Fact + * @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(), getFact) + /** + * @api {post} v4/fact Increment Fact Data + * @apiDescription Increment data related to facts (only accessible by database moderators). + * @apiName IncrementFactData + * @apiGroup Fact + * @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('Fact')); + +router + .route('/:id') + /** + * @api {patch} v4/fact/:id Update Fact Data + * @apiDescription Update data related to facts with a specific ID (only accessible by database moderators). + * @apiName UpdateFactData + * @apiGroup Fact + * @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('Fact')) + /** + * @api {delete} v4/fact/:id Delete Fact Data + * @apiDescription Delete data related to fact with a specific ID (only accessible by admins). + * @apiName DeleteFactData + * @apiGroup Fact + * @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('Fact')); +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/listTags.js b/src/routes/v4/textUtilities/listTags.js new file mode 100644 index 0000000..e972b23 --- /dev/null +++ b/src/routes/v4/textUtilities/listTags.js @@ -0,0 +1,34 @@ +import { Router } from 'express'; +import listTags from '../../../controllers/v4/textUtilities/listTags.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/listTags List Tags + * @apiDescription Retrieve a list of tags. + * @apiName listTags + * @apiGroup TextUtilities + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {String} owoifiedText Owoified version of the input text. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), listTags); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/owoify.js b/src/routes/v4/textUtilities/owoify.js new file mode 100644 index 0000000..0fc4188 --- /dev/null +++ b/src/routes/v4/textUtilities/owoify.js @@ -0,0 +1,34 @@ +import { Router } from 'express'; +import getOwoifyText from '../../../controllers/v4/textUtilities/owoify.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/owoify Owoify Text + * @apiDescription Transform user input normal text into owoified text. + * @apiName owoifyText + * @apiGroup TextUtilities + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {String} owoifiedText Owoified version of the input text. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getOwoifyText); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/password.js b/src/routes/v4/textUtilities/password.js new file mode 100644 index 0000000..ead80f5 --- /dev/null +++ b/src/routes/v4/textUtilities/password.js @@ -0,0 +1,31 @@ +import { Router } from 'express'; +import getPassword from '../../../controllers/v4/textUtilities/password.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/password Generate Random Password + * @apiDescription Generates a random password. + * @apiName getPassword + * @apiGroup TextUtilities + * @apiPermission global + * + * @apiSuccess {String} password Randomly generated password. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(createRateLimiter(), getPassword); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/quote.js b/src/routes/v4/textUtilities/quote.js new file mode 100644 index 0000000..c7d352a --- /dev/null +++ b/src/routes/v4/textUtilities/quote.js @@ -0,0 +1,104 @@ +import { Router } from 'express'; +import getQuote from '../../../controllers/v4/textUtilities/quote.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/quote Get a Random Quote + * @apiDescription Retrieve a random quote. + * @apiName getQuote + * @apiGroup Quote + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {Object} quote Random quote object. + * + * @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(), getQuote) + /** + * @api {post} v4/quote Increment Quote Data + * @apiDescription Increment data related to quotes (only accessible by database moderators). + * @apiName IncrementQuoteData + * @apiGroup Quote + * @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('Quote')); + +router + .route('/:id') + /** + * @api {patch} v4/quote/:id Update Quote Data + * @apiDescription Update data related to quotes with a specific ID (only accessible by database moderators). + * @apiName UpdateQuoteData + * @apiGroup Quote + * @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('Quote')) + /** + * @api {delete} v4/quote/:id Delete Quote Data + * @apiDescription Delete data related to quotes with a specific ID (only accessible by admins). + * @apiName DeleteQuoteData + * @apiGroup Quote + * @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('Quote')); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/uvuify.js b/src/routes/v4/textUtilities/uvuify.js new file mode 100644 index 0000000..76b217d --- /dev/null +++ b/src/routes/v4/textUtilities/uvuify.js @@ -0,0 +1,34 @@ +import { Router } from 'express'; +import getUvuifyText from '../../../controllers/v4/textUtilities/uvuify.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/uvuify Uvuify Text + * @apiDescription Transform user input normal text into uvuified text. + * @apiName uvuifyText + * @apiGroup TextUtilities + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {String} owoifiedText Owoified version of the input text. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getUvuifyText); + +// Export the router +export default router; diff --git a/src/routes/v4/textUtilities/uwuify.js b/src/routes/v4/textUtilities/uwuify.js new file mode 100644 index 0000000..ce40a0b --- /dev/null +++ b/src/routes/v4/textUtilities/uwuify.js @@ -0,0 +1,34 @@ +import { Router } from 'express'; +import getUwuifyText from '../../../controllers/v4/textUtilities/uwuify.js'; +import createRateLimiter from '../../../middlewares/rateLimit.js'; +import authorize from '../../../middlewares/authorize.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/uwuify Uwuify Text + * @apiDescription Transform user input normal text into uwuified text. + * @apiName uwuifyText + * @apiGroup TextUtilities + * @apiPermission user + * + * @apiHeader {String} Authorization User's access token. + * + * @apiSuccess {String} owoifiedText Owoified version of the input text. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. + * @apiError (Forbidden 403) Forbidden Only authorized users can access the data. + * @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. + * @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. + * + * @api {function} createRateLimiter + * @apiDescription Creates a rate limiter middleware to control the frequency of requests. + * @apiSuccess {function} middleware Express middleware function that handles rate limiting. + * + */ + .get(authorize(config.roles.USER), createRateLimiter(), getUwuifyText); + +// Export the router +export default router; diff --git a/src/utils/lengthFilter.js b/src/utils/lengthFilter.js deleted file mode 100644 index 9b46332..0000000 --- a/src/utils/lengthFilter.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function lengthFilter(minLength, maxLength) { - return { - $gte: Number(minLength) || 0, - $lte: Number(maxLength) || 1e4, - } -} diff --git a/src/utils/parseOrder.js b/src/utils/parseOrder.js deleted file mode 100644 index d2ac6df..0000000 --- a/src/utils/parseOrder.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = function parseOrder(input) { - let value = input - // If value is one of the supported keywords ("asc", "ascending", - // "desc", "descending"), convert it to the corresponding numeric value. - if (/^asc(ending)?$|^desc(ending)?$/.test(String(value))) { - value = /^asc/.test(input) ? 1 : -1 - } - return Math.abs(value) === 1 ? Number(value) : null -} diff --git a/src/utils/tagsFilter.js b/src/utils/tagsFilter.js deleted file mode 100644 index d0f6378..0000000 --- a/src/utils/tagsFilter.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function tagsFilter(tags) { - if (tags.includes('|')) { - return { $in: tags.split('|') } - } - return { $all: tags.split(',') } -}