{"size": 2062, "ext": "js", "max_stars_repo_path": "services/journal.js", "max_stars_repo_name": "longlc/EasyERP_open_source", "max_stars_repo_stars_event_min_datetime": "2016-12-22T01:36:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T06:14:35.000Z", "max_issues_repo_path": "services/journal.js", "max_issues_repo_name": "longlc/EasyERP_open_source", "max_issues_repo_issues_event_min_datetime": "2017-01-04T20:41:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-24T22:18:12.000Z", "max_forks_repo_path": "services/journal.js", "max_forks_repo_name": "longlc/EasyERP_open_source", "max_forks_repo_forks_event_min_datetime": "2016-12-19T07:34:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T06:14:38.000Z"}
{"max_stars_count": 199, "max_issues_count": 21, "max_forks_count": 223, "avg_line_length": 26.7792207792, "max_line_length": 98, "alphanum_fraction": 0.4767216295}
'use strict';
var mongoose = require('mongoose');
var journalSchema = mongoose.Schemas.journal;

module.exports = function (models) {
    return new function () {
        this.journalFinder = function (options, callback) {
            var Journal;
            var dbName;
            var err;
            var journalId;

            if (typeof options === 'function') {
                callback = options;
                options = {};
            }

            if (typeof callback !== 'function') {
                callback = function () {
                    return false;
                };
            }

            dbName = options.dbName;
            delete options.dbName;

            if (!dbName) {
                err = new Error('Invalid input parameters');
                err.status = 400;

                return callback(err);
            }

            Journal = models.get(dbName, 'journal', journalSchema);
            journalId = options.journal;

            Journal.findById(journalId, callback);
        };

        this.journalFinderByAccounts = function (options, callback) {
            var Journal;
            var dbName;
            var err;
            var debitAccount;
            var creditAccount;

            if (typeof options === 'function') {
                callback = options;
                options = {};
            }

            if (typeof callback !== 'function') {
                callback = function () {
                    return false;
                };
            }

            dbName = options.dbName;
            delete options.dbName;

            if (!dbName) {
                err = new Error('Invalid input parameters');
                err.status = 400;

                return callback(err);
            }

            Journal = models.get(dbName, 'journal', journalSchema);
            debitAccount = options.debitAccount;
            creditAccount = options.creditAccount;

            Journal.findOne({debitAccount: debitAccount, creditAccount: creditAccount}, callback);
        };
    };
};

