Skip to content

Commit

Permalink
✨ feat: added active contacts middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jul 8, 2024
1 parent b525758 commit 54c1f98
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/tom-server/src/active-contacts-api/middlewares/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Response, NextFunction } from 'express'
import type { AuthRequest } from '../../types'
import type { IActiveContactsApiValidationMiddleware } from '../types'

export default class ActiveContactsApiValidationMiddleWare
implements IActiveContactsApiValidationMiddleware
{
/**
* Check the creation requirements of the active contacts API
*
* @param {AuthRequest} req - the request object
* @param {Response} res - the response object
* @param {NextFunction} next - the next function
* @returns {void}
* @example
* router.post('/', checkCreationRequirements, create)
*/
checkCreationRequirements = (
req: AuthRequest,
res: Response,
next: NextFunction
): void => {
try {
const { contacts } = req.body

if (contacts === undefined) {
throw new Error('Missing required fields', {
cause: 'userId or contacts is missing'
})
}

next()
} catch (error) {
res.status(400).json({ message: 'Bad Request' })
}
}
}

0 comments on commit 54c1f98

Please sign in to comment.