<commit_before>const moment = require('moment');

const validator = require('../validator.js');
const config = require('../config.js');
const { getRoute, getTimeout } = config;
const ROUTE_NAME = 'agreementCreate';

/**
 * @api {post} /agreements Create agreement
 * @apiVersion 1.0.0
 * @apiName CreateAgreement
 * @apiGroup Agreements
 * @apiPermission UserPermission
 *
 * @apiDescription
 * Makes PayPal request to create new agreement based on pre-defined plan.
 * Returns new agreement object and link to approve it by user.
 *
 * @apiHeader (Authorization) {String} Authorization JWT :accessToken
 * @apiHeaderExample Authorization-Example:
 *   "Authorization: JWT <PASSWORD>"
 *
 * @apiParam (Params) {Object} data Data container.
 * @apiParam (Params) {String} data.type Data type, must be 'agreement'.
 * @apiParam (Params) {Object} data.attributes New agreement details.
 * @apiParam (Params) {String} data.attributes.name Any name, required.
 * @apiParam (Params) {String} data.attributes.description Any description, optional.
 * @apiParam (Params) {String} data.attributes.start_date Optional date-time to start billing cycle. If not specified, current moment will be used.
 * @apiParam (Params) {String} data.attributes.plan Plan id, required.
 *
 * @apiSuccess (Return) {Object} data Data container.
 * @apiSuccess (Return) {String} data.id Id of newly created agreement.
 * @apiSuccess (Return) {String} data.type Data type, always is 'agreement'.
 * @apiSuccess (Return) {Object} data.attributes Full agreement object returned by PayPal (contains additional data from plan).
 * @apiSuccess (Return) {Object} data.links
 * @apiSuccess (Return) {String} data.links.approve Link user must open to choose desired cycle option (monthly or annual) and approve agreement.
 * @apiSuccess (Return) {Object} data.meta
 * @apiSuccess (Return) {String} data.meta.token Agreement token, this must be used to execute approved agreement (see agreementExecute).
 *
 * @apiExample {curl} Example usage:
 *   curl -i -X POST -H 'Accept-Version: *' \
 *    -H 'Accept: application/vnd.api+json' \
 *    -H 'Content-Type: application/vnd.api+json' \
 *    -H "Authorization: JWT <KEY>" \
 *    "https://api-sandbox.cappasity.matic.ninja/api/payments/agreements" -d '{
 *    	"data": {
 *    		"type": "agreement",
 *     		"attributes": {
 *      		"name": "professional-monthly-test",
 *       		"description": "test professional subscription payment with id PD-3EH44571MW10700544AOMJ3I",
 *         "plan": "PD-3EH44571MW10700544AOMJ3I"
 *        }
 *      }
 *    }'
 *
 * @apiUse ValidationError
 * @apiUse UnauthorizedError
 *
 * @apiSuccessExample {json} Success-Created:
 *  HTTP/1.1 201 Created
 *  {
 *    data:
 *    {
 *      id: 'PP-10200414C5',
 *      type: 'agreement',
 *      attributes: {...},
 *      links: {
 *        approve: 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<KEY>6V451950C'
 *      },
 *      meta: {
 *        token: '<KEY>6V451950C'
 *      }
 *    }
 *  }
 */
exports.post = {
  path: '/agreements',
  middleware: ['auth'],
  handlers: {
    '1.0.0': (req, res, next) => {
      return validator.validate('agreement.create', req.body)<commit_msg>add name to a func<commit_after>const moment = require('moment');

const validator = require('../validator.js');
const config = require('../config.js');
const { getRoute, getTimeout } = config;
const ROUTE_NAME = 'agreementCreate';

/**
 * @api {post} /agreements Create agreement
 * @apiVersion 1.0.0
 * @apiName CreateAgreement
 * @apiGroup Agreements
 * @apiPermission UserPermission
 *
 * @apiDescription
 * Makes PayPal request to create new agreement based on pre-defined plan.
 * Returns new agreement object and link to approve it by user.
 *
 * @apiHeader (Authorization) {String} Authorization JWT :accessToken
 * @apiHeaderExample Authorization-Example:
 *   "Authorization: JWT myreallyniceandvalidjsonwebtoken"
 *
 * @apiParam (Params) {Object} data Data container.
 * @apiParam (Params) {String} data.type Data type, must be 'agreement'.
 * @apiParam (Params) {Object} data.attributes New agreement details.
 * @apiParam (Params) {String} data.attributes.name Any name, required.
 * @apiParam (Params) {String} data.attributes.description Any description, optional.
 * @apiParam (Params) {String} data.attributes.start_date Optional date-time to start billing cycle. If not specified, current moment will be used.
 * @apiParam (Params) {String} data.attributes.plan Plan id, required.
 *
 * @apiSuccess (Return) {Object} data Data container.
 * @apiSuccess (Return) {String} data.id Id of newly created agreement.
 * @apiSuccess (Return) {String} data.type Data type, always is 'agreement'.
 * @apiSuccess (Return) {Object} data.attributes Full agreement object returned by PayPal (contains additional data from plan).
 * @apiSuccess (Return) {Object} data.links
 * @apiSuccess (Return) {String} data.links.approve Link user must open to choose desired cycle option (monthly or annual) and approve agreement.
 * @apiSuccess (Return) {Object} data.meta
 * @apiSuccess (Return) {String} data.meta.token Agreement token, this must be used to execute approved agreement (see agreementExecute).
 *
 * @apiExample {curl} Example usage:
 *   curl -i -X POST -H 'Accept-Version: *' \
 *    -H 'Accept: application/vnd.api+json' \
 *    -H 'Content-Type: application/vnd.api+json' \
 *    -H "Authorization: JWT <KEY>" \
 *    "https://api-sandbox.cappasity.matic.ninja/api/payments/agreements" -d '{
 *    	"data": {
 *    		"type": "agreement",
 *     		"attributes": {
 *      		"name": "professional-monthly-test",
 *       		"description": "test professional subscription payment with id PD-3EH44571MW10700544AOMJ3I",
 *         "plan": "PD-3EH44571MW10700544AOMJ3I"
 *        }
 *      }
 *    }'
 *
 * @apiUse ValidationError
 * @apiUse UnauthorizedError
 *
 * @apiSuccessExample {json} Success-Created:
 *  HTTP/1.1 201 Created
 *  {
 *    data:
 *    {
 *      id: 'PP-10200414C5',
 *      type: 'agreement',
 *      attributes: {...},
 *      links: {
 *        approve: 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0JP008296V451950C'
 *      },
 *      meta: {
 *        token: 'EC-<PASSWORD>'
 *      }
 *    }
 *  }
 */
exports.post = {
  path: '/agreements',
  middleware: ['auth'],
  handlers: {
    '1.0.0': function agreementCreate(req, res, next) {
      return validator.validate('agreement.create', req.body)
{'fraction_non_alphanumeric': 0.13860163605494674, 'fraction_numerical': 0.019601790399753048, 'mean_word_length': 3.6252676659528906, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '1763310', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1997, 'n_words': 562}