<commit_before>import globalHooks = require('../../../hooks');
import hooks = require('feathers-hooks-common');
const auth = require('feathers-authentication').hooks;
import { updateStat } from '../../../hooks/stat';

const populateSchema = {
  include: [
    {
      service: 'questions',
      nameAs: 'question',
      parentField: 'questionId',
      childField: '_id',
      query: {
        $select: ['correctAnswer', 'category'],
      },
    },
  ],
};

const serializeSchema = {
  computed: {
    isCorrect: (item, hook) => {
      return item.chosenAnswer === +item.question.correctAnswer;
    },
    correctAnswer: (item, hook) => {
      return +item.question.correctAnswer;
    },
  },
};

export = {
  before: {
    all: [
      auth.verifyToken(),
      auth.populateUser(),
      auth.restrictToAuthenticated(),
    ],
    find: [],
    get: [],
    create: [hooks.populate({schema: populateSchema}), hooks.serialize(serializeSchema)],
    update: [],
    patch: [],
    remove: [],
  },
  after: {
    all: [],
    find: [],
    get: [],
    create: [updateStat('user', 'user')],
    update: [],
    patch: [],
    remove: [],
  },
};<commit_msg>Fix bug<commit_after>import globalHooks = require('../../../hooks');
import hooks = require('feathers-hooks-common');
const auth = require('feathers-authentication').hooks;
import { updateStat } from '../../../hooks/stat';

const populateSchema = {
  include: [
    {
      service: 'questions',
      nameAs: 'question',
      parentField: 'questionId',
      childField: '_id',
      query: {
        $select: ['correctAnswer', 'category'],
      },
    },
  ],
};

const serializeSchema = {
  computed: {
    isCorrect: (item, hook) => {
      return item.chosenAnswer === +item.question.correctAnswer;
    },
    correctAnswer: (item, hook) => {
      return +item.question.correctAnswer;
    },
  },
};

export = {
  before: {
    all: [
      auth.verifyToken(),
      auth.populateUser(),
      auth.restrictToAuthenticated(),
    ],
    find: [],
    get: [],
    create: [hooks.populate({schema: populateSchema}), hooks.serialize(serializeSchema)],
    update: [],
    patch: [],
    remove: [],
  },
  after: {
    all: [],
    find: [],
    get: [],
    create: [updateStat('users', 'user')],
    update: [],
    patch: [],
    remove: [],
  },
};
{'fraction_non_alphanumeric': 0.19388194743644982, 'fraction_numerical': 0.0, 'mean_word_length': 2.5944272445820435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7475385', 'n_tokens_mistral': 738, 'n_tokens_neox': 735, 'n_words': 135}