<commit_before>import { mongoose } from '@graphite/mongoose';
import { graphQl, query } from '@graphite/decorators';
import jwt from 'jsonwebtoken';
import debug from 'debug';

@mongoose
@graphQl
class Account {
  logger = debug('mongoose-account');

  @query()
  accounts() {
    return this.Model.find();
  }

  JwSToken = { SECRET: 'Graphite', EXPIRES_IN: 10000 };

  constructor() {
    this.logger('Init accounts.');
  }

  setConfig(JwSToken) {
    this.JwSToken = JwSToken;
    this.logger(`JwSToken - SECRET: ${JwSToken.SECRET} - EXPIRES_IN:  ${JwSToken.EXPIRES_IN}`);
  }

  initialize(app) {
    app.use(this.verifyToken(jwt).bind(this));
  }

  verifyToken(jsonwebtoken) {
    return (req, res, next) => {
      const { JwSToken } = this;
      try {
        const { token } = req.headers;
        req.userId = jsonwebtoken.verify(token, JwSToken.SECRET)._doc.userId;
      } catch (error) {
        req.userId = undefined;
      }
      next();
    };
  }

  onBeforeCreate(callback = (value) => value ) {
    if (this.onBeforeCreateCallback) {
      throw new Error('Can only call onBeforeCreate once');
    }

    this.onBeforeCreateCallback = callback;
  }

  onAfterCreate(callback = (value) => value ) {
    if (this.onAfterCreateCallback) {
      throw new Error('Can only call onAfterCreate once');
    }

    this.onAfterCreateCallback = callback;
  }
}

export default new Account();<commit_msg>[IMPROVE] - better logic<commit_after>import { mongoose } from '@graphite/mongoose';
import { graphQl, query } from '@graphite/decorators';
import jwt from 'jsonwebtoken';
import debug from 'debug';

@mongoose
@graphQl
class Account {
  logger = debug('mongoose-account');

  @query()
  accounts() {
    return this.Model.find();
  }

  JwSToken = { SECRET: 'Graphite', EXPIRES_IN: 10000 };

  constructor() {
    this.logger('Init accounts.');
  }

  setConfig(JwSToken) {
    this.JwSToken = JwSToken;
    this.logger(`JwSToken - SECRET: ${JwSToken.SECRET} - EXPIRES_IN:  ${JwSToken.EXPIRES_IN}`);
  }

  initialize(app) {
    app.use(this.verifyToken(jwt).bind(this));
  }

  verifyToken(jsonwebtoken) {
    return (req, res, next) => {
      const { JwSToken } = this;
      try {
        const { token } = req.headers;
        req.userId = jsonwebtoken.verify(token, JwSToken.SECRET)._doc.userId;
      } catch (error) {
        req.userId = undefined;
      }
      next();
    };
  }

  onBeforeCreate(callback) {
    if (this.onBeforeCreateCallback) {
      throw new Error('Can only call onBeforeCreate once');
    }

    if (typeof callback === 'function') {
      this.onBeforeCreateCallback = callback;
    }
  }

  onAfterCreate(callback) {
    if (this.onAfterCreateCallback) {
      throw new Error('Can only call onAfterCreate once');
    }

    if (typeof callback === 'function') {
      this.onAfterCreateCallback = callback;
    }
  }
}

export default new Account();
{'fraction_non_alphanumeric': 0.13951085084395454, 'fraction_numerical': 0.003444712366517396, 'mean_word_length': 3.0729312762973353, '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': '2267919', 'n_tokens_mistral': 1012, 'n_tokens_neox': 1004, 'n_words': 199}