{"size": 936, "ext": "js", "max_stars_repo_path": "aggregation-server/src/route/root.js", "max_stars_repo_name": "ng-the-engineer/datahog", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aggregation-server/src/route/root.js", "max_issues_repo_name": "ng-the-engineer/datahog", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aggregation-server/src/route/root.js", "max_forks_repo_name": "ng-the-engineer/datahog", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.2, "max_line_length": 75, "alphanum_fraction": 0.7136752137}
import koaRouter from "koa-router"
import createJobs from '../controllers/datahog'
import config from '../config'

const router = koaRouter()
const baseUrl = config.baseUrl

router.post(`${baseUrl}/requests`, async (ctx) => {
  const requestId = ctx.query.requestId
  const providers = ctx.request.body.providers
  const callbackUrl = ctx.request.body.callbackUrl

  ctx.assert(requestId, 422, 'Query parameter "requestId" is mandatory')
  ctx.assert(providers, 422, 'Body parameter "providers" is mandatory')
  ctx.assert(callbackUrl, 422, 'Body parameter "callbackUrl" is mandatory')

  try {
    const record = createJobs({ requestId, providers, callbackUrl })
    createResponse({ ctx, body: record, status: 200 })
  } catch (err) {
    createResponse({ ctx, body: err, status: 400})
  }
})

const createResponse = (context) => {
  const { ctx, body, status} = context
  ctx.body = body
  ctx.status = status
}
export default router