This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/api/assets/functions/main/randomQuote.js

25 lines
712 B
JavaScript
Raw Permalink Normal View History

2020-08-03 12:04:07 +02:00
const errorHandling = require('../../utils/errorHandling')
const { serverError } = require('../../config/errors')
const Quotes = require('../../../models/quotes')
const Users = require('../../../models/users')
const sequelize = require('../../utils/database')
2020-08-03 12:04:07 +02:00
module.exports = async ({ res, next }, _argsObject) => {
try {
const quote = await Quotes.findOne({
order: sequelize.random(),
2020-08-03 14:14:45 +02:00
include: [{ model: Users, attributes: ['name', 'logo'] }],
2020-08-03 12:04:07 +02:00
attributes: {
exclude: ['isValidated']
},
where: {
isValidated: 1
}
})
return res.status(200).json(quote)
} catch (error) {
console.log(error)
return errorHandling(next, serverError)
}
}