<commit_before>

const _ = require('lodash');
const auth = require('../lib/authentications');
const handlerFactory = require('./handlers.js');
const Joi = require('joi');

exports.register = function (server, eOptions, next) {
  const options = _.extend({ basePath: '/api/2.0' }, eOptions);
  const handlers = handlerFactory(server, 'cd-badges');

  server.route([{
    method: 'GET',
    path: `${options.basePath}/badges`,
    handler: handlers.actHandler('listBadges'),
    config: {
      description: 'List all possible badges',
      cors: { origin: ['*'], credentials: false },
      tags: ['api', 'users'],
    },
  }, {
    method: 'GET',
    path: `${options.basePath}/badges/{slug}`,
    handler: handlers.actHandler('getBadge', 'slug'),
    config: {
      description: 'Get badge by slug',
      cors: { origin: ['*'], credentials: false },
      tags: ['api', 'users'],
    },
  }, {
    method: 'POST',
    path: `${options.basePath}/badges/applications`,
    handler: handlers.actHandlerNeedsUser('sendBadgeApplication'),
    config: {
      auth: auth.apiUser,
      description: 'Create badge application',
      tags: ['api', 'users'],
      validate: {
        payload: {
          applicationData: {
            user: Joi.object().required(),
            badge: Joi.object().required(),
            emailSubject: Joi.string().valid('You have been awarded a new CoderDojo digital badge!').required(),
          },
        },
      },
    },
  }, {
    method: 'POST',
    path: `${options.basePath}/badges/accept`,
    handler: handlers.actHandlerNeedsUser('acceptBadge'),
    config: {
      auth: auth.apiUser,
      description: 'Accept badge',
      tags: ['api', 'users'],
    },
  }, {
    method: 'GET',
    path: `${options.basePath}/badges/user/{userId}`,
    handler: handlers.actHandlerNeedsUser('loadUserBadges', 'userId'),
    config: {<commit_msg>Allow evidence to be passed down as part of hte badge<commit_after>

const _ = require('lodash');
const auth = require('../lib/authentications');
const handlerFactory = require('./handlers.js');
const Joi = require('joi');

exports.register = function (server, eOptions, next) {
  const options = _.extend({ basePath: '/api/2.0' }, eOptions);
  const handlers = handlerFactory(server, 'cd-badges');

  server.route([{
    method: 'GET',
    path: `${options.basePath}/badges`,
    handler: handlers.actHandler('listBadges'),
    config: {
      description: 'List all possible badges',
      cors: { origin: ['*'], credentials: false },
      tags: ['api', 'users'],
    },
  }, {
    method: 'GET',
    path: `${options.basePath}/badges/{slug}`,
    handler: handlers.actHandler('getBadge', 'slug'),
    config: {
      description: 'Get badge by slug',
      cors: { origin: ['*'], credentials: false },
      tags: ['api', 'users'],
    },
  }, {
    method: 'POST',
    path: `${options.basePath}/badges/applications`,
    handler: handlers.actHandlerNeedsUser('sendBadgeApplication'),
    config: {
      auth: auth.apiUser,
      description: 'Create badge application',
      tags: ['api', 'users'],
      validate: {
        payload: {
          applicationData: {
            user: Joi.object().required(),
            badge: Joi.object().required(),
            emailSubject: Joi.string().valid('You have been awarded a new CoderDojo digital badge!').required(),
            evidence: Joi.string().optional(),
          },
        },
      },
    },
  }, {
    method: 'POST',
    path: `${options.basePath}/badges/accept`,
    handler: handlers.actHandlerNeedsUser('acceptBadge'),
    config: {
      auth: auth.apiUser,
      description: 'Accept badge',
      tags: ['api', 'users'],
    },
  }, {
    method: 'GET',
    path: `${options.basePath}/badges/user/{userId}`,
    handler: handlers.actHandlerNeedsUser('loadUserBadges', 'userId'),
    config: {
{'fraction_non_alphanumeric': 0.17666926474408937, 'fraction_numerical': 0.0010392309690828788, 'mean_word_length': 2.9568345323741005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6673187', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1166, 'n_words': 258}