diff --git a/services/backend/src/routes/feedback.js b/services/backend/src/routes/feedback.js new file mode 100644 index 0000000000..af5d17006d --- /dev/null +++ b/services/backend/src/routes/feedback.js @@ -0,0 +1,20 @@ +const router = require('express').Router() + +const { sendFeedbackToToska } = require('../services/mailService') +const logger = require('../util/logger') + +router.post('/email', async req => { + const { + body: { content }, + user, + } = req + + await sendFeedbackToToska({ + feedbackContent: content, + user, + }) + + logger.info(`${user.userId} succesfully sent feedback to toska`) +}) + +module.exports = router diff --git a/services/backend/src/routes/feedback.ts b/services/backend/src/routes/feedback.ts deleted file mode 100644 index 05f17072f2..0000000000 --- a/services/backend/src/routes/feedback.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Router } from 'express' - -import { sendFeedbackToToska } from '../services/mailService' -import { OodikoneRequest } from '../types' -import { ApplicationError } from '../util/customErrors' -import logger from '../util/logger' - -const router = Router() - -interface EmailRequest extends OodikoneRequest { - body: { - content: string - } -} - -router.post('/email', async (req: EmailRequest) => { - const { - body: { content }, - user, - } = req - - if (!user) { - throw new ApplicationError('User not found', 404) - } - - await sendFeedbackToToska({ - feedbackContent: content, - user, - }) - - logger.info(`${user.userId} succesfully sent feedback to Toska`) -}) - -export default router diff --git a/services/backend/src/routes/login.ts b/services/backend/src/routes/login.ts index 704900c26b..28c4859042 100644 --- a/services/backend/src/routes/login.ts +++ b/services/backend/src/routes/login.ts @@ -1,16 +1,17 @@ -import { Response, Router } from 'express' +import { Request, Response, Router } from 'express' import { omit } from 'lodash' -import { OodikoneRequest } from '../types' +import { FormattedUser } from '../types' import { ApplicationError } from '../util/customErrors' const router = Router() -interface LoginRequest extends OodikoneRequest { +interface CustomRequest extends Request { + user?: FormattedUser logoutUrl?: string } -router.get('/', async (req: LoginRequest, res: Response) => { +router.get('/', async (req: CustomRequest, res: Response) => { const { user, logoutUrl } = req if (!user) { diff --git a/services/backend/src/services/mailService.ts b/services/backend/src/services/mailService.ts index 2981da52b8..dbc16da9b4 100644 --- a/services/backend/src/services/mailService.ts +++ b/services/backend/src/services/mailService.ts @@ -1,7 +1,6 @@ import axios from 'axios' import { isProduction, pateToken } from '../config' -import { FormattedUser } from '../types' import { ApplicationError } from '../util/customErrors' const pateClient = axios.create({ @@ -32,7 +31,7 @@ export const sendFeedbackToToska = async ({ user, }: { feedbackContent: string - user: FormattedUser + user: { name: string; userId: string; email: string } }) => { const { name, userId, email } = user const userDetails = `Sent by ${name}, userid: ${userId}, email: ${email}` diff --git a/services/backend/src/types/index.ts b/services/backend/src/types/index.ts index 5bd671bbb7..9210f4a23d 100644 --- a/services/backend/src/types/index.ts +++ b/services/backend/src/types/index.ts @@ -7,7 +7,6 @@ import { ExtentCode } from './extentCode' import { GenderCode } from './genderCode' import { Language } from './language' import { Name } from './name' -import { OodikoneRequest } from './oodikoneRequest' import { Phase } from './phase' import { PriorityCode } from './priorityCode' import { Role } from './role' @@ -25,7 +24,6 @@ export { GenderCode, Language, Name, - OodikoneRequest, Phase, PriorityCode, Role, diff --git a/services/backend/src/types/oodikoneRequest.ts b/services/backend/src/types/oodikoneRequest.ts deleted file mode 100644 index 372fbc9be9..0000000000 --- a/services/backend/src/types/oodikoneRequest.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint-disable import/no-cycle */ -import { Request } from 'express' - -import { FormattedUser } from './user' - -export interface OodikoneRequest extends Request { - user?: FormattedUser -}