<commit_before>import {check_authentication, validate_request} from '../utils/errors'
import express from 'express'

function validate_request_body(request, response, next_handler) {
  request.checkBody({
    'screen_name': {
      notEmpty: {
        errorMessage: 'parameter is required',
      },
    },
  })

  validate_request(request, next_handler)
}

const all_groups_router = express.Router()
all_groups_router.route('/groups')
  .get(check_authentication, (request, response) => {
    response.json({})
  })
  .post(check_authentication, validate_request_body, (request, response) => {
    response.json({
      group: request.body,
    })
  })

const one_group_router = express.Router()
one_group_router.param('group_id', (request, response, next_handler) => {
  request.checkParams('group_id', 'parameter is required').notEmpty()
  request
    .checkParams('group_id', 'parameter must be a MongoDB ObjectId')
    .isMongoId()

  validate_request(request, next_handler)
})
one_group_router.route('/groups/:group_id')
  .delete(check_authentication, (request, response) => {
    response.json({
      group_id: request.params.group_id,
    })
  })<commit_msg>Implement group routes<commit_after>import {check_authentication, validate_request} from '../utils/errors'
import express from 'express'
import {group_model} from '../models/group_model'

function validate_request_body(request, response, next_handler) {
  request.checkBody({
    'screen_name': {
      notEmpty: {
        errorMessage: 'parameter is required',
      },
    },
  })

  validate_request(request, next_handler)
}

const all_groups_router = express.Router()
all_groups_router.route('/groups')
  .get(check_authentication, (request, response, next_handler) => {
    group_model
      .find({
        user_id: request.user.id,
      })
      .then(groups => response.json(groups))
      .catch(next_handler)
  })
  .post(check_authentication, validate_request_body, (
    request,
    response,
    next_handler
  ) => {
    group_model
      .create({
        user_id: request.user.id,
        screen_name: request.body.screen_name,
      })
      .then(group => response.json(group))
      .catch(next_handler)
  })

const one_group_router = express.Router()
one_group_router.param('group_id', (request, response, next_handler) => {
  request.checkParams('group_id', 'parameter is required').notEmpty()
  request
    .checkParams('group_id', 'parameter must be a MongoDB ObjectId')
    .isMongoId()

  validate_request(request, next_handler)
})
one_group_router.route('/groups/:group_id')
  .delete(check_authentication, (request, response, next_handler) => {
    group_model
      .remove({
        _id: request.params.group_id,
      })
      .then(() => response.json(true))
      .catch(next_handler)
  })
{'fraction_non_alphanumeric': 0.1336438552490147, 'fraction_numerical': 0.0, 'mean_word_length': 3.898245614035088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3922174', 'n_tokens_mistral': 866, 'n_tokens_neox': 862, 'n_words': 157}