import { Request, Response, NextFunction } from 'express'
import { validate } from 'super-easy-validator'
import helpers from '../../utils/helpers'

async function getCommunities(req: Request, res: Response, next: NextFunction) {
	await helpers.runApi(res, () => {
		const rules = {
			limit: 'optional|string|natural',
			page: 'optional|string|natural',
			search: 'optional|string',
		}

		const { errors } = validate(rules, req.query)
		if (errors) {
			return res.status(400).json({ message: errors[0] })
		}

		return next()
	})
}

const validations = {
	getCommunities
}

export default validations
