mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
37 lines
943 B
TypeScript
37 lines
943 B
TypeScript
import { Router, Request, Response } from 'express'
|
|
import SendgridMail from '@sendgrid/mail'
|
|
import config from '../config'
|
|
|
|
SendgridMail.setApiKey(config.sendgridApiKey)
|
|
|
|
export class ReportRouter {
|
|
public router: Router
|
|
|
|
public constructor() {
|
|
this.router = Router()
|
|
}
|
|
|
|
public async sendMessage(req: Request, res: Response) {
|
|
if (!req.body.msg) {
|
|
return res.send({ status: 'error', message: 'missing message' })
|
|
}
|
|
|
|
try {
|
|
await SendgridMail.send(req.body.msg)
|
|
return res.send({ status: 'success' })
|
|
} catch (error) {
|
|
console.error(`${error.code} - ${error.message}`) // eslint-disable-line
|
|
res.send(`${error.code} - ${error.message}`)
|
|
}
|
|
}
|
|
|
|
public init() {
|
|
this.router.post('/', this.sendMessage)
|
|
}
|
|
}
|
|
|
|
const reportRoutes = new ReportRouter()
|
|
reportRoutes.init()
|
|
|
|
export default reportRoutes.router
|