moved api from monorepo
This commit is contained in:
8
utils/errorResponse.js
Normal file
8
utils/errorResponse.js
Normal file
@ -0,0 +1,8 @@
|
||||
class ErrorResponse extends Error {
|
||||
constructor(message, statusCode) {
|
||||
super(message)
|
||||
this.statusCode = statusCode
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorResponse
|
12
utils/getTag.js
Normal file
12
utils/getTag.js
Normal file
@ -0,0 +1,12 @@
|
||||
import Game from '../models/Game.js'
|
||||
|
||||
const getTag = async (tag) => {
|
||||
const fullTags = await Game.find().distinct(tag)
|
||||
let tags = []
|
||||
for (let i = 0; i < fullTags.length; i++) {
|
||||
if (fullTags[i] !== '') tags.push(fullTags[i])
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
export default getTag
|
30
utils/sendEmail.js
Normal file
30
utils/sendEmail.js
Normal file
@ -0,0 +1,30 @@
|
||||
import nodemailer from 'nodemailer'
|
||||
import yn from 'yn'
|
||||
|
||||
const sendEmail = async options => {
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: Bun.env.SMTP_HOST,
|
||||
port: Bun.env.SMTP_PORT,
|
||||
secure: yn(Bun.env.SECURE), // true for 465, false for other ports
|
||||
auth: {
|
||||
user: Bun.env.SMTP_USER, // generated ethereal user
|
||||
pass: Bun.env.SMTP_PASSWORD, // generated ethereal password
|
||||
},
|
||||
})
|
||||
|
||||
// send mail with defined transport object
|
||||
const message = {
|
||||
from: `${Bun.env.FROM_NAME} <${Bun.env.FROM_EMAIL}>`, // sender address
|
||||
to: options.email, // list of receivers
|
||||
subject: options.subject, // Subject line
|
||||
html: options.message.html, // HTML body
|
||||
text: options.message.text, // plain text body
|
||||
}
|
||||
|
||||
const info = await transporter.sendMail(message).catch((err) => console.error(err))
|
||||
|
||||
console.log('Message sent: %s', info.messageId)
|
||||
}
|
||||
|
||||
export default sendEmail
|
Reference in New Issue
Block a user