<commit_before>import { mongoose } from '@graphite/mongoose';
import { extendTypeGraphQl } from '@graphite/utils';
import account, { Model as accountModel } from '@graphite/mongoose-account';
import { property, graphQl, mutation, type, query } from '@graphite/decorators';
import { Facebook } from 'fb';
import jwt from 'jsonwebtoken';
import debug from 'debug';

@mongoose
@graphQl
export default class AccountFacebook {
  logger = debug('mongoose-account-facebook');

  @property('String | required | unique')
  userId;

  @property('String | required | unique')
  facebookId;

  @property('String | required')
  accessToken;

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

  saltRounds = 10;

  constructor(appId = '', secret = '', redirect = '') {
    this.logger('Init accountFacebook.');
    this.redirect = redirect;
    this.appId = appId;
    this.secret = secret;
    this.facebook = new Facebook({ appId, secret });

    const scope = 'email,user_likes';
    /* eslint-disable camelcase */
    const redirect_uri = this.redirect;
    this.url = this.facebook.getLoginUrl({ scope, redirect_uri });
    extendTypeGraphQl(account, 'accountFacebook: AccountFacebook', this.findAccount.bind(this));
  }

  async findAccount({ _id }) {
    return await this.Model.findOne({ userId: _id });
  }

  initialize(app) {
    app.get('/login/facebook', this.callbackFacebook.bind(this));
  }

  getAccessToken(appId, secret, code, redirect) {
    return new Promise((resolve, reject) => {
      this.facebook.napi('oauth/access_token', {
        client_id: appId,
        client_secret: secret,
        redirect_uri: redirect,
        code: code,
      }, function(error, result) {
        if (error) {
          reject(error);
        }

        resolve({ token: result.access_token, expires: result.expires ? result.expires : 0 });
      });
    });
  }

  getExtendAccessToken(appId, secret, token) {
    return new Promise((resolve, reject) => {
      this.facebook.napi('oauth/access_token', {
        client_id: appId,
        client_secret: secret,
        grant_type: 'fb_exchange_token',
        fb_exchange_token: token,
      }, function(error, result) {
        if (error !== null) {
          reject(!error ? 'error occurred' : error);
        }

        resolve({ token: result.access_token, expires: result.expires ? result.expires : 0 });
      });
    });
  }<commit_msg>[UPDATE] - remove logic error<commit_after>import { mongoose } from '@graphite/mongoose';
import { extendTypeGraphQl } from '@graphite/utils';
import account, { Model as accountModel } from '@graphite/mongoose-account';
import { property, graphQl, mutation, type, query } from '@graphite/decorators';
import { Facebook } from 'fb';
import jwt from 'jsonwebtoken';
import debug from 'debug';

@mongoose
@graphQl
export default class AccountFacebook {
  logger = debug('mongoose-account-facebook');

  @property('String | required | unique')
  userId;

  @property('String | required | unique')
  facebookId;

  @property('String | required')
  accessToken;

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

  saltRounds = 10;

  constructor(appId = '', secret = '', redirect = '') {
    this.logger('Init accountFacebook.');
    this.redirect = redirect;
    this.appId = appId;
    this.secret = secret;
    this.facebook = new Facebook({ appId, secret });

    const scope = 'email,user_likes';
    /* eslint-disable camelcase */
    const redirect_uri = this.redirect;
    this.url = this.facebook.getLoginUrl({ scope, redirect_uri });
    extendTypeGraphQl(account, 'accountFacebook: AccountFacebook', this.findAccount.bind(this));
  }

  async findAccount({ _id }) {
    return await this.Model.findOne({ userId: _id });
  }

  initialize(app) {
    app.get('/login/facebook', this.callbackFacebook.bind(this));
  }

  getAccessToken(appId, secret, code, redirect) {
    return new Promise((resolve, reject) => {
      this.facebook.napi('oauth/access_token', {
        client_id: appId,
        client_secret: secret,
        redirect_uri: redirect,
        code: code,
      }, function(error, result) {
        if (error) {
          reject(error);
        }

        resolve({ token: result.access_token, expires: result.expires ? result.expires : 0 });
      });
    });
  }

  getExtendAccessToken(appId, secret, token) {
    return new Promise((resolve, reject) => {
      this.facebook.napi('oauth/access_token', {
        client_id: appId,
        client_secret: secret,
        grant_type: 'fb_exchange_token',
        fb_exchange_token: token,
      }, function(error, result) {
        if (error) {
          reject(error);
        }

        resolve({ token: result.access_token, expires: result.expires ? result.expires : 0 });
      });
    });
  }
{'fraction_non_alphanumeric': 0.138326726476111, 'fraction_numerical': 0.001669100771959107, 'mean_word_length': 3.1795989537925022, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '829016', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1433, 'n_words': 327}