diff --git a/package.json b/package.json index 593730d..a0b4fc8 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "engines": { "node": ">=18.x" }, + "type": "module", "scripts": { "start": "node src/index.js", "dev": "nodemon src/index.js" diff --git a/src/app.js b/src/app.js index 9420381..c8bdff0 100644 --- a/src/app.js +++ b/src/app.js @@ -1,15 +1,14 @@ -const express = require('express'); -const cors = require('cors'); +import express from 'express'; +import cors from 'cors'; // Import custom error handlers and logger -const { +import { handler404, errorsLogger, errorsHandler, -} = require('./handlers/errors/index'); -const { ipLogger } = require('./handlers/logger/ip'); -const routes = require('./routes'); - +} from './handlers/errors/index.js'; +import { ipLogger } from './handlers/logger/ip.js'; +import routes from './routes.js'; // Express APP const app = express(); @@ -26,7 +25,6 @@ app.use(express.json()); // Middleware to parse URL-encoded bodies app.use(express.urlencoded({ extended: true })); - // Logger middleware // Uncomment the following block if you want to enable IP logging if (process.env.LOGGER === 'true') { @@ -39,4 +37,4 @@ app.use(routes); // Error handling middleware app.use(handler404, errorsLogger, errorsHandler); -module.exports = app; +export default app; diff --git a/src/controllers/facts/randomFacts.js b/src/controllers/facts/randomFacts.js index 9cbb4d8..6c3da31 100644 --- a/src/controllers/facts/randomFacts.js +++ b/src/controllers/facts/randomFacts.js @@ -1,44 +1,58 @@ -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) { +import createError from 'http-errors'; +import Facts from '../../models/schemas/Facts.js'; +import tagsFilter from '../../utils/tagsFilter.js'; +import lengthFilter from '../../utils/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 + const { minLength, maxLength, tags } = req.query; - const filter = {} + // 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) + filter.length = lengthFilter(minLength, maxLength); } + // Apply tags filter (if tags are provided) if (tags) { - filter.tags = tagsFilter(tags) + filter.tags = tagsFilter(tags); } + // Aggregate to match the filter, select a random fact, and project excluding version field const [result] = await Facts.aggregate([ - // Apply filters (if any) - { $match: filter }, - // Select a random document from the results - { $sample: { size: 1 } }, + { $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')) + return next(createError(404, 'Could not find any matching fact')); } - res.status(200).json(result) + // Respond with the random fact + res.status(200).json(result); - await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facts: 1 } }) + // 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) + ); + return next(error); } -} +}; + +export default getRandomFact; \ No newline at end of file diff --git a/src/controllers/gifs/randomAngry.js b/src/controllers/gifs/randomAngry.js index c336680..9d9bd1f 100644 --- a/src/controllers/gifs/randomAngry.js +++ b/src/controllers/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/gifs/randomBaka.js index f04d74a..e09b778 100644 --- a/src/controllers/gifs/randomBaka.js +++ b/src/controllers/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/gifs/randomBite.js index d2aad16..1be27f3 100644 --- a/src/controllers/gifs/randomBite.js +++ b/src/controllers/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/gifs/randomBlush.js index 924f942..1525a41 100644 --- a/src/controllers/gifs/randomBlush.js +++ b/src/controllers/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/gifs/randomBonk.js index 003328f..61509da 100644 --- a/src/controllers/gifs/randomBonk.js +++ b/src/controllers/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/gifs/randomBored.js index a1d8b31..3cf093a 100644 --- a/src/controllers/gifs/randomBored.js +++ b/src/controllers/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/gifs/randomBully.js index 3e70dc1..38fac4d 100644 --- a/src/controllers/gifs/randomBully.js +++ b/src/controllers/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/gifs/randomBye.js index 2cb2dd7..9087e7b 100644 --- a/src/controllers/gifs/randomBye.js +++ b/src/controllers/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/gifs/randomChase.js index 661e16f..75a2aa4 100644 --- a/src/controllers/gifs/randomChase.js +++ b/src/controllers/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/gifs/randomCheer.js index cfc4371..3aed3ff 100644 --- a/src/controllers/gifs/randomCheer.js +++ b/src/controllers/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/gifs/randomCringe.js index d4242c9..3f6009e 100644 --- a/src/controllers/gifs/randomCringe.js +++ b/src/controllers/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/gifs/randomCry.js index 0dcd213..c259c71 100644 --- a/src/controllers/gifs/randomCry.js +++ b/src/controllers/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/gifs/randomCuddle.js index 5d567f9..7c7035e 100644 --- a/src/controllers/gifs/randomCuddle.js +++ b/src/controllers/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/gifs/randomDab.js index 15d34c8..3ce2df2 100644 --- a/src/controllers/gifs/randomDab.js +++ b/src/controllers/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/gifs/randomDance.js index cab5b04..0ac4d11 100644 --- a/src/controllers/gifs/randomDance.js +++ b/src/controllers/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/gifs/randomDie.js index e93091a..0b3a7e7 100644 --- a/src/controllers/gifs/randomDie.js +++ b/src/controllers/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/gifs/randomDisgust.js index da0d794..ecdfeaa 100644 --- a/src/controllers/gifs/randomDisgust.js +++ b/src/controllers/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/gifs/randomFacepalm.js index 3b975c1..50a1efe 100644 --- a/src/controllers/gifs/randomFacepalm.js +++ b/src/controllers/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/gifs/randomFeed.js index 2abc733..3c74951 100644 --- a/src/controllers/gifs/randomFeed.js +++ b/src/controllers/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/gifs/randomGlomp.js index e9cfc85..5d1e43c 100644 --- a/src/controllers/gifs/randomGlomp.js +++ b/src/controllers/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/gifs/randomHappy.js index d5e45f9..22bff31 100644 --- a/src/controllers/gifs/randomHappy.js +++ b/src/controllers/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/gifs/randomHi.js index 942a0ab..d56e856 100644 --- a/src/controllers/gifs/randomHi.js +++ b/src/controllers/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/gifs/randomHighfive.js index 44e0ba6..c94a980 100644 --- a/src/controllers/gifs/randomHighfive.js +++ b/src/controllers/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/gifs/randomHold.js index 7537186..eb47464 100644 --- a/src/controllers/gifs/randomHold.js +++ b/src/controllers/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/gifs/randomHug.js index 02bf136..317e0fe 100644 --- a/src/controllers/gifs/randomHug.js +++ b/src/controllers/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/gifs/randomKick.js index 6300439..fb79661 100644 --- a/src/controllers/gifs/randomKick.js +++ b/src/controllers/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/gifs/randomKill.js index 266ba69..a017684 100644 --- a/src/controllers/gifs/randomKill.js +++ b/src/controllers/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/gifs/randomKissu.js index 7d596da..b40508c 100644 --- a/src/controllers/gifs/randomKissu.js +++ b/src/controllers/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/gifs/randomLaugh.js index 8e95f98..20b03e9 100644 --- a/src/controllers/gifs/randomLaugh.js +++ b/src/controllers/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/gifs/randomLick.js index c62ee7e..1df6133 100644 --- a/src/controllers/gifs/randomLick.js +++ b/src/controllers/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/gifs/randomLove.js index e9f0e74..f4b5f66 100644 --- a/src/controllers/gifs/randomLove.js +++ b/src/controllers/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/gifs/randomLurk.js index 48a5a00..d5c1146 100644 --- a/src/controllers/gifs/randomLurk.js +++ b/src/controllers/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/gifs/randomMidfing.js b/src/controllers/gifs/randomMidfing.js index b1bb31c..c14d719 100644 --- a/src/controllers/gifs/randomMidfing.js +++ b/src/controllers/gifs/randomMidfing.js @@ -1,31 +1,31 @@ -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) { +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 Midfinger.aggregate([ + 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 Midfinger Gif')) + return next(createError(404, 'Could not find any Midfing Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { midfing: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { midfing: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomMidfing; diff --git a/src/controllers/gifs/randomNervous.js b/src/controllers/gifs/randomNervous.js index a33acef..d461f7d 100644 --- a/src/controllers/gifs/randomNervous.js +++ b/src/controllers/gifs/randomNervous.js @@ -1,31 +1,31 @@ -const createError = require('http-errors') -const Nervouse = require('../../models/schemas/Nervouse') -const Stats = require('../../models/schemas/Stat') + +import createError from 'http-errors'; +import Nervous from '../../models/schemas/Nervous.js'; +import Stats from '../../models/schemas/Stat.js'; // Get random Anime Nervous -module.exports = async function getRandomNervous(req, res, next) { +const getRandomNervous = async (req, res, next) => { try { - const [result] = await Nervouse.aggregate([ + 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')) + return next(createError(404, 'Could not find any Nervous Gif')); } - res.status(200).json(result) + res.status(200).json(result); - await Stats.findOneAndUpdate( - { _id: 'systemstats' }, - { $inc: { nervous: 1 } } - ) + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nervous: 1 } }); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} +}; + +export default getRandomNervous; diff --git a/src/controllers/gifs/randomNom.js b/src/controllers/gifs/randomNom.js index f75e8f6..454408f 100644 --- a/src/controllers/gifs/randomNom.js +++ b/src/controllers/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/gifs/randomNope.js index d4f640b..8b451ef 100644 --- a/src/controllers/gifs/randomNope.js +++ b/src/controllers/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/gifs/randomNuzzle.js index ad2e471..d00db1f 100644 --- a/src/controllers/gifs/randomNuzzle.js +++ b/src/controllers/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/gifs/randomPanic.js index 167cd10..115942a 100644 --- a/src/controllers/gifs/randomPanic.js +++ b/src/controllers/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/gifs/randomPat.js index 4749a17..57c3d2e 100644 --- a/src/controllers/gifs/randomPat.js +++ b/src/controllers/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/gifs/randomPeck.js index 408e512..40e06aa 100644 --- a/src/controllers/gifs/randomPeck.js +++ b/src/controllers/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/gifs/randomPoke.js index c817b6c..eeaf1cd 100644 --- a/src/controllers/gifs/randomPoke.js +++ b/src/controllers/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/gifs/randomPout.js index 6babcb2..162ae2d 100644 --- a/src/controllers/gifs/randomPout.js +++ b/src/controllers/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/gifs/randomPunch.js index fc7a704..fcb2174 100644 --- a/src/controllers/gifs/randomPunch.js +++ b/src/controllers/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/gifs/randomRun.js index 735f7a2..2203104 100644 --- a/src/controllers/gifs/randomRun.js +++ b/src/controllers/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/gifs/randomSad.js index 769866c..c23f407 100644 --- a/src/controllers/gifs/randomSad.js +++ b/src/controllers/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/gifs/randomShoot.js index 0df7c36..c41c592 100644 --- a/src/controllers/gifs/randomShoot.js +++ b/src/controllers/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/gifs/randomShrug.js index 51fbb42..b795f7c 100644 --- a/src/controllers/gifs/randomShrug.js +++ b/src/controllers/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/gifs/randomSip.js index f2c240f..d2fe08a 100644 --- a/src/controllers/gifs/randomSip.js +++ b/src/controllers/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/gifs/randomSlap.js index db83bbc..f118d16 100644 --- a/src/controllers/gifs/randomSlap.js +++ b/src/controllers/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/gifs/randomSleepy.js index a8d97b0..8902c72 100644 --- a/src/controllers/gifs/randomSleepy.js +++ b/src/controllers/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/gifs/randomSmile.js index 1131008..01f289f 100644 --- a/src/controllers/gifs/randomSmile.js +++ b/src/controllers/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/gifs/randomSmug.js index 55adb87..e1ff3d9 100644 --- a/src/controllers/gifs/randomSmug.js +++ b/src/controllers/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/gifs/randomStab.js index 93390e5..c97993f 100644 --- a/src/controllers/gifs/randomStab.js +++ b/src/controllers/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/gifs/randomStare.js index 221f32d..0ef1ab7 100644 --- a/src/controllers/gifs/randomStare.js +++ b/src/controllers/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/gifs/randomSuicide.js index 4247bd8..44d7254 100644 --- a/src/controllers/gifs/randomSuicide.js +++ b/src/controllers/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/gifs/randomTease.js index d698d21..2fcac09 100644 --- a/src/controllers/gifs/randomTease.js +++ b/src/controllers/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/gifs/randomThink.js index d7c73b9..53b937f 100644 --- a/src/controllers/gifs/randomThink.js +++ b/src/controllers/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/gifs/randomThumbsup.js index 05dc315..b8ba139 100644 --- a/src/controllers/gifs/randomThumbsup.js +++ b/src/controllers/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/gifs/randomTickle.js index b9da123..dfe579f 100644 --- a/src/controllers/gifs/randomTickle.js +++ b/src/controllers/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/gifs/randomTriggered.js index 8e6cdc4..a3d3579 100644 --- a/src/controllers/gifs/randomTriggered.js +++ b/src/controllers/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/gifs/randomWag.js index 964d847..51d0e66 100644 --- a/src/controllers/gifs/randomWag.js +++ b/src/controllers/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/gifs/randomWave.js index 688491f..eeb04e2 100644 --- a/src/controllers/gifs/randomWave.js +++ b/src/controllers/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/gifs/randomWink.js index d6b0c17..5bde7bc 100644 --- a/src/controllers/gifs/randomWink.js +++ b/src/controllers/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/gifs/randomYes.js index 31bdbe8..5d73426 100644 --- a/src/controllers/gifs/randomYes.js +++ b/src/controllers/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/quotes/randomQuotes.js b/src/controllers/quotes/randomQuotes.js index 455dbcf..adf068f 100644 --- a/src/controllers/quotes/randomQuotes.js +++ b/src/controllers/quotes/randomQuotes.js @@ -1,41 +1,49 @@ -const createError = require('http-errors') -const Quotes = require('../../models/schemas/Quotes') -const Stats = require('../../models/schemas/Stat') +import createError from 'http-errors'; +import Quotes from '../../models/schemas/Quotes.js'; +import Stats from '../../models/schemas/Stat.js'; -// Get random Anime Quote -module.exports = async function getRandomQuote(req, res, next) { +/** + * 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 + const { character } = req.query; - const filter = {} - - if (character) { - filter.author = character - } + // 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([ - // Apply filters (if any) - { $match: filter }, - // Select a random document from the results - { $sample: { size: 1 } }, + { $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')) + return next(createError(404, 'Could not find any matching Quote')); } - res.status(200).json(result) + // 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) + ); + return next(error); } -} +}; + +export default getRandomQuote; diff --git a/src/controllers/utils/listTags.js b/src/controllers/utils/listTags.js index 21334ec..17ea89b 100644 --- a/src/controllers/utils/listTags.js +++ b/src/controllers/utils/listTags.js @@ -1,19 +1,28 @@ -const Tags = require('../../models/schemas/Tags') -const parseOrder = require('../../utils/parseOrder') -const Stats = require('../../models/schemas/Stat') +import Tags from '../../models/schemas/Tags.js'; +import parseOrder from '../../utils/parseOrder.js'; +import Stats from '../../models/schemas/Stat.js'; -module.exports = async function listTags(req, res, next) { +/** + * 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 + let { sortBy, sortOrder } = req.query; // Supported parameter values - const Values = { sortBy: ['name', 'usedCount'] } + const Values = { sortBy: ['name', 'usedCount'] }; // The default sort order depends on the `sortBy` field - const defaultSortOrder = { name: 1, usedCount: -1 } + const defaultSortOrder = { name: 1, usedCount: -1 }; - sortBy = Values.sortBy.includes(sortBy) ? sortBy : 'name' - sortOrder = parseOrder(sortOrder) || defaultSortOrder[sortBy] || 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: { @@ -26,18 +35,24 @@ module.exports = async function listTags(req, res, next) { { $addFields: { usedCount: { $size: '$usedCount' } } }, { $sort: { [sortBy]: sortOrder } }, { $project: { __v: 0 } }, - ]) - res.json(results) + ]); - await Stats.findOneAndUpdate ( - { _id: "systemstats" }, - { $inc: { tags: 1 } }, - ) + // Respond with the sorted tags + res.json(results); + + // Update system statistics for tags + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { tags: 1 } } + ); } catch (error) { - await Stats.findOneAndUpdate ( - { _id: "systemstats" }, - { $inc: { failed_requests: 1 } }, - ) - return next(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/utils/owoify.js b/src/controllers/utils/owoify.js index 276629b..74dd638 100644 --- a/src/controllers/utils/owoify.js +++ b/src/controllers/utils/owoify.js @@ -1,27 +1,41 @@ -const createError = require('http-errors') -const owoify = require('owoify-js').default -const Stats = require('../../models/schemas/Stat') +import createError from 'http-errors'; +import owoify from 'owoify-js'; +import Stats from '../../models/schemas/Stat.js'; -module.exports = async function getOwofiyText(req, res, next) { +/** + * 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 + const { text } = req.query; + // Check for valid text input if (!text) { - return next(createError(404, 'Invalid text input.')) + return next(createError(404, 'Invalid text input.')); } + + // Owofy the text and send the response res.status(200).json({ text: owoify(text), - }) + }); - return await Stats.findOneAndUpdate( + // 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) + ); + return next(error); } -} +}; + +export default getOwofiyText; diff --git a/src/controllers/utils/randomPassword.js b/src/controllers/utils/randomPassword.js index c312187..5d662d0 100644 --- a/src/controllers/utils/randomPassword.js +++ b/src/controllers/utils/randomPassword.js @@ -1,11 +1,18 @@ -const pass = require('generate-password') -const Stats = require('../../models/schemas/Stat') +import pass from 'generate-password'; +import Stats from '../../models/schemas/Stat.js'; -// Get random Password -module.exports = async function getRandomPassword(req, res, next) { +/** + * 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 + const { charLength } = req.query; + // Generate a random password with specified characteristics const password = pass.generate({ length: charLength || 50, uppercase: true, @@ -13,21 +20,25 @@ module.exports = async function getRandomPassword(req, res, next) { 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) + ); + return next(error); } -} +}; + +export default getRandomPassword; diff --git a/src/controllers/utils/user.js b/src/controllers/utils/user.js index b5f1ce0..4b8765d 100644 --- a/src/controllers/utils/user.js +++ b/src/controllers/utils/user.js @@ -1,73 +1,83 @@ -// Assuming you have imported the required modules and set up the MongoDB connection. -const crypto = require('crypto') -const Users = require('../../models/schemas/Users') -const generateToken = require('../../utils/generateToken') +import crypto from 'crypto'; +import Users from '../../models/schemas/Users.js'; +import generateToken from '../../utils/generateToken.js'; -module.exports = async function userEndpoint(req, res, next) { +/** + * 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 + 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 + 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', - }) + }); } - // Assuming you have a MongoDB collection called "users" and you want to update the token for a specific user. - // Replace "Users" with your actual model name for users. + // Update user's token in the database await Users.updateOne( { _id: { $eq: id } }, { $set: { token: token } }, - { upsert: true } // This option creates the document if it doesn't exist. - ) + { 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 + 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', - }) + }); } - // Assuming you have a MongoDB collection called "users" and you want to fetch user details based on the provided user ID. - // Replace "Users" with your actual model name for users. - const user = await Users.findOne({ _id: { $eq: id } }) + // 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. + // 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), // Assuming you have a "token" field in your schema. - // Add other fields in the "newUser" object based on your schema. - } + token: generateToken(id, process.env.HMAC_KEY), + // Add other fields in the "newUser" object based on your schema + }; - await Users.create(newUser) + await Users.create(newUser); - return res.status(201).json(newUser.token) + return res.status(201).json(newUser.token); } - return res.status(200).json(user.token) + return res.status(200).json(user.token); } else { return res.status(405).json({ message: 'Method Not Allowed', - }) + }); } } catch (error) { - return next(error) + return next(error); } -} +}; + +export default userEndpoint; diff --git a/src/controllers/utils/uvuify.js b/src/controllers/utils/uvuify.js index 2245ac8..3d4175a 100644 --- a/src/controllers/utils/uvuify.js +++ b/src/controllers/utils/uvuify.js @@ -1,27 +1,30 @@ -const createError = require('http-errors') -const uwuify = require('owoify-js') -const Stats = require('../../models/schemas/Stat') +import createError from 'http-errors'; +import uwuify from 'owoify-js'; +import Stats from '../../models/schemas/Stat.js'; -module.exports = async function getOwofiyText(req, res, next) { +const getOwofiyText = async (req, res, next) => { try { - const { text } = req.query + const { text } = req.query; if (!text) { - return next(createError(404, 'Invalid text input.')) + return next(createError(404, 'Invalid text input.')); } + res.status(200).json({ text: uwuify(text), - }) + }); - return await Stats.findOneAndUpdate( + await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { uwuify: 1 } } - ) + ); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + return next(error); } -} \ No newline at end of file +}; + +export default getOwofiyText; diff --git a/src/controllers/utils/uwuify.js b/src/controllers/utils/uwuify.js index 9e5f9e2..cb69fba 100644 --- a/src/controllers/utils/uwuify.js +++ b/src/controllers/utils/uwuify.js @@ -1,27 +1,30 @@ -const createError = require('http-errors') -const uvuify = require('owoify-js') -const Stats = require('../../models/schemas/Stat') +import createError from 'http-errors'; +import uvuify from 'owoify-js'; +import Stats from '../../models/schemas/Stat.js'; -module.exports = async function getOwofiyText(req, res, next) { +const getOwofiyText = async (req, res, next) => { try { - const { text } = req.query + const { text } = req.query; if (!text) { - return next(createError(404, 'Invalid text input.')) + throw createError(404, 'Invalid text input.'); } + res.status(200).json({ text: uvuify(text), - }) + }); - return await Stats.findOneAndUpdate( + await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { uvuify: 1 } } - ) + ); } catch (error) { await Stats.findOneAndUpdate( { _id: 'systemstats' }, { $inc: { failed_requests: 1 } } - ) - return next(error) + ); + next(error); } -} \ No newline at end of file +}; + +export default getOwofiyText; diff --git a/src/controllers/waifus/randomWaifus.js b/src/controllers/waifus/randomWaifus.js index 0b9b3b8..a6817d5 100644 --- a/src/controllers/waifus/randomWaifus.js +++ b/src/controllers/waifus/randomWaifus.js @@ -1,26 +1,28 @@ -const Waifus = require('../../models/schemas/Waifus') -const Stats = require('../../models/schemas/Stat') +import Waifus from '../../models/schemas/Waifus.js'; +import Stats from '../../models/schemas/Stat.js'; // Get a random waifu -module.exports = async function getRandomWaifu(req, res, next) { +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) + 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) + ); + next(error); } -} +}; + +export default getRandomWaifu; diff --git a/src/handlers/auth/index.js b/src/handlers/auth/index.js index 2dbe53f..42219b7 100644 --- a/src/handlers/auth/index.js +++ b/src/handlers/auth/index.js @@ -1,16 +1,16 @@ -const createError = require('http-errors') -const Users = require('../../models/schemas/Users') -const Stats = require('../../models/schemas/Stat') +import createError from 'http-errors'; +import Users from '../../models/schemas/Users.js'; +import Stats from '../../models/schemas/Stat.js'; -module.exports = async function authHandler(req, res, next) { +const authHandler = async (req, res, next) => { try { // Request Header AUTH var - const key = req.headers.authorization + 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) { @@ -23,13 +23,13 @@ module.exports = async function authHandler(req, res, next) { 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) { @@ -42,8 +42,8 @@ module.exports = async function authHandler(req, res, next) { daily_requests: 1, }, } - ) - return next(createError(403, "You've been banned from using the API.")) + ); + 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) { @@ -52,7 +52,7 @@ module.exports = async function authHandler(req, res, next) { // 403, // "You've exhausted your request limits. Buy Premium to increase it more." // ) - // ) + // ); // } await Stats.findByIdAndUpdate( @@ -60,10 +60,12 @@ module.exports = async function authHandler(req, res, next) { { $inc: { endpoints_requests: 1, success_requests: 1, daily_requests: 1 }, } - ) + ); - return next() + return next(); } catch (error) { - return next(error) + return next(error); } -} +}; + +export default authHandler; diff --git a/src/handlers/errors/index.js b/src/handlers/errors/index.js index df639ee..f165612 100644 --- a/src/handlers/errors/index.js +++ b/src/handlers/errors/index.js @@ -1,22 +1,22 @@ -const createError = require('http-errors') -const chalk = require('chalk') +import createError from 'http-errors'; +import chalk from 'chalk'; // Handles 404 errors -module.exports.handler404 = function handler404(req, res, next) { - return next(createError(404, 'The requested resource could not be found')) -} +export const handler404 = (req, res, next) => { + next(createError(404, 'The requested resource could not be found')); +}; -module.exports.errorsLogger = function errorsLogger(error, req, res, next) { +export const errorsLogger = (error, req, res, next) => { if (process.env.NODE_ENV === 'development') { /* eslint-disable-next-line no-console */ - console.error(chalk.red('[ERROR]'), error.stack) + console.error(chalk.red('[ERROR]'), error.stack); } - return next(error) -} + 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 }) -} +export const 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 index 5757c75..3cffe06 100644 --- a/src/handlers/logger/ip.js +++ b/src/handlers/logger/ip.js @@ -1,28 +1,23 @@ -// const fs = require('fs') -const requestIp = require('request-ip') -const { Webhook } = require('discord-webhook-node') -const hook = new Webhook(process.env.DISCORD_WEBHOOK_URL) +import requestIp from 'request-ip'; +import { Webhook } from 'discord-webhook-node'; -// 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}\``) +const hook = new Webhook(process.env.DISCORD_WEBHOOK_URL); - // fs.appendFile('./logs/ip-logs.log', log, err => { - // if (err) throw err - // }) - console.log(log) +export const ipLogger = (req, res, next) => { + const auth = req.headers.auth || 'Null Auth'; - next() -} + 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..7e18faf 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,12 @@ /* eslint-disable no-console */ -require('dotenv').config() -const mongoose = require('mongoose') -const chalk = require('chalk') -const app = require('./app') +import 'dotenv/config'; +import mongoose from 'mongoose'; +import chalk from 'chalk'; +import app from './app.js'; // PORT -const PORT = process.env.PORT || 4000 +const PORT = process.env.PORT || 4000; // NODE ENV LOGGER if (process.env.NODE_ENV === 'development') { @@ -14,10 +14,10 @@ if (process.env.NODE_ENV === 'development') { `${chalk.yellow( '[DEBUG]' )} You've enabled developer mode. Now your console will be dirty.` - ) + ); } -// Connect to database, then start's the Express server +// Connect to the database, then start the Express server mongoose .connect(process.env.MONGODB_URI, { useUnifiedTopology: true, @@ -32,11 +32,11 @@ mongoose '[SUCCESS]' )} API is running on: http://localhost:${PORT}/api` ) - ) - }) - .catch(error => { - console.error(error) + ); }) + .catch((error) => { + console.error(error); + }); // const Users = require('./models/schemas/Users') diff --git a/src/models/index.js b/src/models/index.js index 072157a..d7abd93 100644 --- a/src/models/index.js +++ b/src/models/index.js @@ -1,144 +1,5 @@ -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 +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 +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/Facts.js b/src/models/schemas/Facts.js index c0987ab..5ff2ee0 100644 --- a/src/models/schemas/Facts.js +++ b/src/models/schemas/Facts.js @@ -1,10 +1,13 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = 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) +const Fact = model('Fact', FactSchema); + +export default Fact; 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/Quotes.js b/src/models/schemas/Quotes.js index 234182a..74aa14c 100644 --- a/src/models/schemas/Quotes.js +++ b/src/models/schemas/Quotes.js @@ -1,10 +1,13 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = 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) +const Quote = model('Quote', QuoteSchema); + +export default Quote; 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/Users.js b/src/models/schemas/Users.js index 248f603..1d852be 100644 --- a/src/models/schemas/Users.js +++ b/src/models/schemas/Users.js @@ -1,4 +1,5 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const UserSchema = new Schema({ _id: { type: String }, @@ -15,6 +16,8 @@ const UserSchema = new Schema({ type: Date, default: Date.now(), }, -}) +}); -module.exports = model('Users', UserSchema) +const User = model('Users', UserSchema); + +export default User; 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/Waifus.js b/src/models/schemas/Waifus.js index f224fc9..e89bf06 100644 --- a/src/models/schemas/Waifus.js +++ b/src/models/schemas/Waifus.js @@ -1,4 +1,5 @@ -const { Schema, model } = require('mongoose') +import mongoose from 'mongoose'; +const { Schema, model } = mongoose; const WaifuSchema = new Schema({ _id: { type: Number }, @@ -19,6 +20,9 @@ const WaifuSchema = new Schema({ upvote: { type: Number }, downvote: { type: Number }, }, -}) +}); + +const Waifu = model('Waifu', WaifuSchema); + +export default Waifu; -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..0904d39 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 }, -}) +}); + +export default model('Yesh', YeshSchema); -module.exports = model('Yesh', YeshSchema) diff --git a/src/routes.js b/src/routes.js index a14136c..09ec446 100644 --- a/src/routes.js +++ b/src/routes.js @@ -14,84 +14,85 @@ * * @module routes */ -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 userEndpoint = require('./controllers/utils/user') -const router = Router() +import { Router } from 'express'; +import rateLimit from 'express-rate-limit'; +import authHandler from './handlers/auth/index.js'; +import randomFacts from './controllers/facts/randomFacts.js'; +import getAllTags from './controllers/utils/listTags.js'; +import getOwoify from './controllers/utils/owoify.js'; +import getUwuify from './controllers/utils/uwuify.js'; +import getUvuify from './controllers/utils/uvuify.js'; +import randomWaifus from './controllers/waifus/randomWaifus.js'; +import randomPasswords from './controllers/utils/randomPassword.js'; +import randomQuotes from './controllers/quotes/randomQuotes.js'; +import randomKick from './controllers/gifs/randomKick.js'; +import randomKill from './controllers/gifs/randomKill.js'; +import randomKissu from './controllers/gifs/randomKissu.js'; +import randomMidfing from './controllers/gifs/randomMidfing.js'; +import randomNuzzle from './controllers/gifs/randomNuzzle.js'; +import randomPunch from './controllers/gifs/randomPunch.js'; +import randomShoot from './controllers/gifs/randomShoot.js'; +import randomSip from './controllers/gifs/randomSip.js'; +import randomSleepy from './controllers/gifs/randomSleepy.js'; +import randomSmile from './controllers/gifs/randomSmile.js'; +import randomStab from './controllers/gifs/randomStab.js'; +import randomStare from './controllers/gifs/randomStare.js'; +import randomSuicide from './controllers/gifs/randomSuicide.js'; +import randomTease from './controllers/gifs/randomTease.js'; +import randomWag from './controllers/gifs/randomWag.js'; +import randomBite from './controllers/gifs/randomBite.js'; +import randomBlush from './controllers/gifs/randomBlush.js'; +import randomBonk from './controllers/gifs/randomBonk.js'; +import randomBored from './controllers/gifs/randomBored.js'; +import randomBully from './controllers/gifs/randomBully.js'; +import randomBye from './controllers/gifs/randomBye.js'; +import randomChase from './controllers/gifs/randomChase.js'; +import randomCheer from './controllers/gifs/randomCheer.js'; +import randomDab from './controllers/gifs/randomDab.js'; +import randomDie from './controllers/gifs/randomDie.js'; +import randomDisgust from './controllers/gifs/randomDisgust.js'; +import randomFeed from './controllers/gifs/randomFeed.js'; +import randomHi from './controllers/gifs/randomHi.js'; +import randomHold from './controllers/gifs/randomHold.js'; +import randomHug from './controllers/gifs/randomHug.js'; +import randomNope from './controllers/gifs/randomNope.js'; +import randomPanic from './controllers/gifs/randomPanic.js'; +import randomPat from './controllers/gifs/randomPat.js'; +import randomPeck from './controllers/gifs/randomPeck.js'; +import randomPoke from './controllers/gifs/randomPoke.js'; +import randomPout from './controllers/gifs/randomPout.js'; +import randomRun from './controllers/gifs/randomRun.js'; +import randomSad from './controllers/gifs/randomSad.js'; +import randomShrug from './controllers/gifs/randomShrug.js'; +import randomSlap from './controllers/gifs/randomSlap.js'; +import randomSmug from './controllers/gifs/randomSmug.js'; +import randomThink from './controllers/gifs/randomThink.js'; +import randomThumbsup from './controllers/gifs/randomThumbsup.js'; +import randomTickle from './controllers/gifs/randomTickle.js'; +import randomTriggered from './controllers/gifs/randomTriggered.js'; +import randomWave from './controllers/gifs/randomWave.js'; +import randomWink from './controllers/gifs/randomWink.js'; +import randomYes from './controllers/gifs/randomYes.js'; +import randomAngry from './controllers/gifs/randomAngry.js'; +import randomCringe from './controllers/gifs/randomCringe.js'; +import randomCry from './controllers/gifs/randomCry.js'; +import randomCuddle from './controllers/gifs/randomCuddle.js'; +import randomDance from './controllers/gifs/randomDance.js'; +import randomFacepalm from './controllers/gifs/randomFacepalm.js'; +import randomGlomp from './controllers/gifs/randomGlomp.js'; +import randomHappy from './controllers/gifs/randomHappy.js'; +import randomHighfive from './controllers/gifs/randomHighfive.js'; +import randomLaugh from './controllers/gifs/randomLaugh.js'; +import randomLick from './controllers/gifs/randomLick.js'; +import randomLove from './controllers/gifs/randomLove.js'; +import randomLurk from './controllers/gifs/randomLurk.js'; +import randomNervous from './controllers/gifs/randomNervous.js'; +import randomNom from './controllers/gifs/randomNom.js'; +import randomBaka from './controllers/gifs/randomBaka.js'; +import userEndpoint from './controllers/utils/user.js'; + +const router = Router(); // Rate Limiter for Fact || Other endpoints const Limiter = rateLimit({ @@ -101,45 +102,45 @@ const Limiter = rateLimit({ status: 429, message: 'Too many requests, please try again later.', }, -}) +}); // Base -router.get('/', (req, res) => { +router.get('/api/', (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') -}) + res.redirect('https://docs.waifu.it/list-of-endpoints'); +}); // Fact Endpoints -router.get('/fact', Limiter, authHandler, randomFacts) +router.get('/api/fact', Limiter, randomFacts); /** * Retrieves a random fact from a predefined collection of facts. Requires authentication and is rate-limited to prevent abuse. */ // Waifu Endpoint -router.get('/waifu', Limiter, authHandler, randomWaifus) +router.get('/api/waifu', Limiter, randomWaifus); /** * Returns a randomly generated waifu character. Requires authentication and is rate-limited to manage the frequency of requests. */ -// Utils Endpoint -router.get('/password', Limiter, authHandler, randomPasswords) -router.get('/alltags', Limiter, authHandler, getAllTags) -router.get('/owoify', Limiter, authHandler, getOwoify) -router.get('/uwuify', Limiter, authHandler, getUwuify) -router.get('/uvuify', Limiter, authHandler, getUvuify) -router.all('/user', Limiter, userEndpoint) +// Utils Endpoints +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); +router.all('/api/user', Limiter, 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 @@ -153,80 +154,80 @@ router.all('/user', Limiter, userEndpoint) */ // Random Quote Endpoint -router.get('/quote', Limiter, authHandler, randomQuotes) +router.get('/api/quote', Limiter, authHandler, 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('/kick', Limiter, authHandler, randomKick) -router.get('/kill', Limiter, authHandler, randomKill) -router.get('/kiss', Limiter, authHandler, randomKissu) -router.get('/midfing', Limiter, authHandler, randomMidfing) -router.get('/nuzzle', Limiter, authHandler, randomNuzzle) -router.get('/punch', Limiter, authHandler, randomPunch) -router.get('/shoot', Limiter, authHandler, randomShoot) -router.get('/sip', Limiter, authHandler, randomSip) -router.get('/sleepy', Limiter, authHandler, randomSleepy) -router.get('/smile', Limiter, authHandler, randomSmile) -router.get('/stab', Limiter, authHandler, randomStab) -router.get('/stare', Limiter, authHandler, randomStare) -router.get('/suicide', Limiter, authHandler, randomSuicide) -router.get('/tease', Limiter, authHandler, randomTease) -router.get('/wag', Limiter, authHandler, randomWag) -router.get('/bite', Limiter, authHandler, randomBite) -router.get('/blush', Limiter, authHandler, randomBlush) -router.get('/bonk', Limiter, authHandler, randomBonk) -router.get('/bored', Limiter, authHandler, randomBored) -router.get('/bully', Limiter, authHandler, randomBully) -router.get('/bye', Limiter, authHandler, randomBye) -router.get('/chase', Limiter, authHandler, randomChase) -router.get('/cheer', Limiter, authHandler, randomCheer) -router.get('/dab', Limiter, authHandler, randomDab) -router.get('/die', Limiter, authHandler, randomDie) -router.get('/disgust', Limiter, authHandler, randomDisgust) -router.get('/feed', Limiter, authHandler, randomFeed) -router.get('/hi', Limiter, authHandler, randomHi) -router.get('/hold', Limiter, authHandler, randomHold) -router.get('/hug', Limiter, authHandler, randomHug) -router.get('/Nope', Limiter, authHandler, randomNope) -router.get('/panic', Limiter, authHandler, randomPanic) -router.get('/pat', Limiter, authHandler, randomPat) -router.get('/peck', Limiter, authHandler, randomPeck) -router.get('/poke', Limiter, authHandler, randomPoke) -router.get('/punch', Limiter, authHandler, randomPunch) -router.get('/pout', Limiter, authHandler, randomPout) -router.get('/run', Limiter, authHandler, randomRun) -router.get('/sad', Limiter, authHandler, randomSad) -router.get('/shrug', Limiter, authHandler, randomShrug) -router.get('/slap', Limiter, authHandler, randomSlap) -router.get('/smug', Limiter, authHandler, randomSmug) -router.get('/think', Limiter, authHandler, randomThink) -router.get('/thumbsup', Limiter, authHandler, randomThumbsup) -router.get('/tickle', Limiter, authHandler, randomTickle) -router.get('/triggered', Limiter, authHandler, randomTriggered) -router.get('/wave', Limiter, authHandler, randomWave) -router.get('/wink', Limiter, authHandler, randomWink) -router.get('/yes', Limiter, authHandler, randomYes) -router.get('/angry', Limiter, authHandler, randomAngry) -router.get('/cringe', Limiter, authHandler, randomCringe) -router.get('/cry', Limiter, authHandler, randomCry) -router.get('/cuddle', Limiter, authHandler, randomCuddle) -router.get('/dance', Limiter, authHandler, randomDance) -router.get('/facepalm', Limiter, authHandler, randomFacepalm) -router.get('/glomp', Limiter, authHandler, randomGlomp) -router.get('/happy', Limiter, authHandler, randomHappy) -router.get('/highfive', Limiter, authHandler, randomHighfive) -router.get('/hug', Limiter, authHandler, randomHug) -router.get('/laugh', Limiter, authHandler, randomLaugh) -router.get('/lick', Limiter, authHandler, randomLick) -router.get('/love', Limiter, authHandler, randomLove) -router.get('/lurk', Limiter, authHandler, randomLurk) -router.get('/nervous', Limiter, authHandler, randomNervous) -router.get('/nom', Limiter, authHandler, randomNom) -router.get('/baka', Limiter, authHandler, randomBaka) +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) // 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. -module.exports = router +export default router; \ No newline at end of file diff --git a/src/utils/generateToken.js b/src/utils/generateToken.js index 65f14be..574c073 100644 --- a/src/utils/generateToken.js +++ b/src/utils/generateToken.js @@ -1,53 +1,50 @@ -const crypto = require('crypto') +import crypto from 'crypto'; -module.exports = function generateToken(id, key) { +const generateToken = (id, key) => { // Function to generate a random hexadecimal string - function generateRandomHex(length) { + const generateRandomHex = (length) => { return crypto .randomBytes(Math.ceil(length / 2)) .toString('hex') - .slice(0, length) - } + .slice(0, length); + }; // Function to convert a timestamp to epoch and encode it to base64 - function encodeTimestampToBase64(timestamp) { - const epoch = Math.floor(timestamp / 1000) // Convert to seconds (Discord uses seconds for epoch) - return Buffer.from(epoch.toString()).toString('base64') - } + const encodeTimestampToBase64 = (timestamp) => { + const epoch = Math.floor(timestamp / 1000); // Convert to seconds (Discord uses seconds for epoch) + return Buffer.from(epoch.toString()).toString('base64'); + }; // Function to generate a random signature between 10 to 28 characters - function generateRandomSignature(minLength, maxLength) { + const generateRandomSignature = (minLength, maxLength) => { const length = - Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength - return generateRandomHex(length).replace(/M/g, 'N').replace(/=/g, '-') - } + Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; + return generateRandomHex(length).replace(/M/g, 'N').replace(/=/g, '-'); + }; // Function to generate a Discord-style token (64 characters) - function generateDiscordToken(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}` + const generateDiscordToken = (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) + .slice(0, 5); + const signature = generateRandomSignature(4, 7); // Combine payload and signature to form a 64-character token - const token = `${payload}.${hmac}${signature}` + const token = `${payload}.${hmac}${signature}`; - return token - } + return token; + }; // Return the generated Discord-style token - return generateDiscordToken(id, key) -} + return generateDiscordToken(id, key); +}; + +export default generateToken; \ No newline at end of file diff --git a/src/utils/lengthFilter.js b/src/utils/lengthFilter.js index 9b46332..d7f266f 100644 --- a/src/utils/lengthFilter.js +++ b/src/utils/lengthFilter.js @@ -1,6 +1,6 @@ -module.exports = function lengthFilter(minLength, maxLength) { - return { - $gte: Number(minLength) || 0, - $lte: Number(maxLength) || 1e4, - } -} +const lengthFilter = (minLength, maxLength) => ({ + $gte: Number(minLength) || 0, + $lte: Number(maxLength) || 1e4, +}); + +export default lengthFilter; diff --git a/src/utils/parseOrder.js b/src/utils/parseOrder.js index d2ac6df..d61f2c0 100644 --- a/src/utils/parseOrder.js +++ b/src/utils/parseOrder.js @@ -1,9 +1,13 @@ -module.exports = function parseOrder(input) { - let value = input +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 + value = /^asc/.test(input) ? 1 : -1; } - return Math.abs(value) === 1 ? Number(value) : null -} + + return Math.abs(value) === 1 ? Number(value) : null; +}; + +export default parseOrder; diff --git a/src/utils/tagsFilter.js b/src/utils/tagsFilter.js index d0f6378..cf00140 100644 --- a/src/utils/tagsFilter.js +++ b/src/utils/tagsFilter.js @@ -1,6 +1,8 @@ -module.exports = function tagsFilter(tags) { +const tagsFilter = (tags) => { if (tags.includes('|')) { - return { $in: tags.split('|') } + return { $in: tags.split('|') }; } - return { $all: tags.split(',') } -} + return { $all: tags.split(',') }; +}; + +export default tagsFilter;