1- const { Router } = require ( 'express' )
2- const { User, OrganisationFeedbackCorrespondent } = require ( '../../models' )
3- const { ApplicationError } = require ( '../../util/customErrors' )
4- const { getAccessAndOrganisation } = require ( './util' )
5- const { createOrganisationLog } = require ( '../../services/auditLog' )
6- const { ENABLE_CORRESPONDENT_MANAGEMENT } = require ( '../../util/config' )
7-
8- const addOrganisationFeedbackCorrespondent = async ( req , res ) => {
1+ import { Response , Router } from 'express'
2+ import { User , OrganisationFeedbackCorrespondent } from '../../models'
3+ import { ApplicationError } from '../../util/customErrors'
4+ import { getAccessAndOrganisation } from './util'
5+ import { createOrganisationLog } from '../../services/auditLog'
6+ import { ENABLE_CORRESPONDENT_MANAGEMENT } from '../../util/config'
7+ import { AuthenticatedRequest } from '../../types'
8+
9+ const addOrganisationFeedbackCorrespondent = async ( req : AuthenticatedRequest , res : Response ) => {
910 const { user } = req
1011 const { code } = req . params
1112 const { userId } = req . body
@@ -16,10 +17,10 @@ const addOrganisationFeedbackCorrespondent = async (req, res) => {
1617
1718 const userToAdd = await User . findByPk ( userId )
1819 if ( ! userToAdd ) {
19- throw new ApplicationError ( ` User not found` , 400 )
20+ throw new ApplicationError ( ' User not found' , 400 )
2021 }
2122 if ( await userToAdd . hasOrganisation ( organisation ) ) {
22- throw new ApplicationError ( ` User already is feedback correspondent of that organisation` , 400 )
23+ throw new ApplicationError ( ' User already is feedback correspondent of that organisation' , 400 )
2324 }
2425
2526 await OrganisationFeedbackCorrespondent . create ( {
@@ -36,10 +37,10 @@ const addOrganisationFeedbackCorrespondent = async (req, res) => {
3637
3738 const users = await organisation . getUsers ( )
3839
39- return res . send ( users )
40+ res . send ( users )
4041}
4142
42- const removeOrganisationFeedbackCorrespondent = async ( req , res ) => {
43+ const removeOrganisationFeedbackCorrespondent = async ( req : AuthenticatedRequest , res : Response ) => {
4344 const { user } = req
4445 const { code, userId } = req . params
4546
@@ -70,14 +71,12 @@ const removeOrganisationFeedbackCorrespondent = async (req, res) => {
7071
7172 const users = await organisation . getUsers ( )
7273
73- return res . send ( users )
74+ res . send ( users )
7475}
7576
76- const router = Router ( )
77+ export const router = Router ( )
7778
7879if ( ENABLE_CORRESPONDENT_MANAGEMENT ) {
7980 router . post ( '/:code/feedback-correspondents' , addOrganisationFeedbackCorrespondent )
8081 router . delete ( '/:code/feedback-correspondents/:userId' , removeOrganisationFeedbackCorrespondent )
8182}
82-
83- module . exports = router
0 commit comments