<commit_before>var Joi = require('joi');
var log = require('server/helpers/logger');
var render = require('server/views/ticket');
var renderUsers = require('server/views/user');


var handlers = module.exports;

exports.registerTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'session.inRegistrationPeriod(pre.session)' },
    { method: 'ticket.addUser(params.sessionId, auth.credentials.user.id, pre.session)', assign: 'ticket' },
    { method: 'ticket.registrationEmail(pre.ticket, pre.session, auth.credentials.user)'}
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Registers a ticket for the current user.',
};


exports.voidTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'ticket.get(params.sessionId)', assign: 'ticket'},
    { method: 'ticket.removeUser(pre.session.id, auth.credentials.user.id, pre.session)', assign: 'removedTicket' },
    { method: 'ticket.getAcceptedUser(ticket)', assign: 'user'},
    { method: 'ticket.registrationAcceptedEmail(pre.ticket, pre.session, pre.user)'}
  ],
  handler: function (request, reply) {
    reply(render(request.pre.removedTicket, request.pre.session));
  },
  description: 'Voids a ticket for the current user.',
};


exports.confirmTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'session.inConfirmationPeriod(pre.session)' },
    { method: 'ticket.confirmUser(params.sessionId, auth.credentials.user.id, pre.session)', assign: 'ticket' }
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Lets a user confirm that he is going on the day of the session.',
};


exports.get = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin'],
    mode: 'try'
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    }
  },
  pre: [
    [
      { method: 'session.get(params.sessionId)', assign: 'session' },
      { method: 'ticket.get(params.sessionId)', assign: 'ticket' }
    ]
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Gets a ticket'
};


exports.list = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user','admin']
  },
  pre: [
    { method: 'ticket.list(query)', assign: 'tickets' }
  ],
  handler: function (request, reply) {
    reply(render(request.pre.tickets));
  },
  description: 'Gets all the tickets'
};


exports.registerPresence = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
      userId: Joi.string().required().description('Id of the user'),
    },
  },
  pre: [
    [
      { method: 'session.get(params.sessionId)', assign: 'session' },
      { method: 'ticket.registerUserPresence(params.sessionId, params.userId)', assign: 'ticket' }
    ]
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Lets an admin confirm that the user showed up on the session.',
};


exports.getUsers = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin'],
    mode: 'try'
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    }
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'ticket.getRegisteredUsers(params.sessionId, pre.session)', assign: 'userIds' },
    { method: 'user.getMulti(pre.userIds)', assign: 'users' }
  ],
  handler: function (request, reply) {
    console.log(request.pre.userIds);

    reply(renderUsers(request.pre.users, request.auth.credentials && request.auth.credentials.user));
  },
  description: 'Gets a ticket'
};


<commit_msg>added failAction ignore on mail pres #38<commit_after>var Joi = require('joi');
var log = require('server/helpers/logger');
var render = require('server/views/ticket');
var renderUsers = require('server/views/user');


var handlers = module.exports;

exports.registerTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'session.inRegistrationPeriod(pre.session)' },
    { method: 'ticket.addUser(params.sessionId, auth.credentials.user.id, pre.session)', assign: 'ticket' },
    { method: 'ticket.registrationEmail(pre.ticket, pre.session, auth.credentials.user)', failAction: 'log'}
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Registers a ticket for the current user.',
};


exports.voidTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'ticket.get(params.sessionId)', assign: 'ticket'},
    { method: 'ticket.removeUser(pre.session.id, auth.credentials.user.id, pre.session)', assign: 'removedTicket' },
    { method: 'ticket.getAcceptedUser(ticket)', assign: 'user', failAction: 'ignore'},
    { method: 'ticket.registrationAcceptedEmail(pre.ticket, pre.session, pre.user)', failAction: 'ignore'}
  ],
  handler: function (request, reply) {
    reply(render(request.pre.removedTicket, request.pre.session));
  },
  description: 'Voids a ticket for the current user.',
};


exports.confirmTicket = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    },
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'session.ticketsNeeded(pre.session)' },
    { method: 'session.inConfirmationPeriod(pre.session)' },
    { method: 'ticket.confirmUser(params.sessionId, auth.credentials.user.id, pre.session)', assign: 'ticket' }
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Lets a user confirm that he is going on the day of the session.',
};


exports.get = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin'],
    mode: 'try'
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    }
  },
  pre: [
    [
      { method: 'session.get(params.sessionId)', assign: 'session' },
      { method: 'ticket.get(params.sessionId)', assign: 'ticket' }
    ]
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Gets a ticket'
};


exports.list = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user','admin']
  },
  pre: [
    { method: 'ticket.list(query)', assign: 'tickets' }
  ],
  handler: function (request, reply) {
    reply(render(request.pre.tickets));
  },
  description: 'Gets all the tickets'
};


exports.registerPresence = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['admin']
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
      userId: Joi.string().required().description('Id of the user'),
    },
  },
  pre: [
    [
      { method: 'session.get(params.sessionId)', assign: 'session' },
      { method: 'ticket.registerUserPresence(params.sessionId, params.userId)', assign: 'ticket' }
    ]
  ],
  handler: function (request, reply) {
    reply(render(request.pre.ticket, request.pre.session));
  },
  description: 'Lets an admin confirm that the user showed up on the session.',
};


exports.getUsers = {
  tags: ['api','ticket'],
  auth: {
    strategies: ['default', 'backup'],
    scope: ['user', 'admin'],
    mode: 'try'
  },
  validate: {
    params: {
      sessionId: Joi.string().required().description('Id of the session'),
    }
  },
  pre: [
    { method: 'session.get(params.sessionId)', assign: 'session' },
    { method: 'ticket.getRegisteredUsers(params.sessionId, pre.session)', assign: 'userIds' },
    { method: 'user.getMulti(pre.userIds)', assign: 'users' }
  ],
  handler: function (request, reply) {
    console.log(request.pre.userIds);

    reply(renderUsers(request.pre.users, request.auth.credentials && request.auth.credentials.user));
  },
  description: 'Gets a ticket'
};



{'fraction_non_alphanumeric': 0.1861553784860558, 'fraction_numerical': 0.00019920318725099602, 'mean_word_length': 3.7030444964871196, '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': '2114737', 'n_tokens_mistral': 3274, 'n_tokens_neox': 3223, 'n_words': 674}