{"size": 802, "ext": "es6", "max_stars_repo_path": "app/es6/repository.es6", "max_stars_repo_name": "palsingh/nodejs-unittest-sample", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/es6/repository.es6", "max_issues_repo_name": "palsingh/nodejs-unittest-sample", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/es6/repository.es6", "max_forks_repo_name": "palsingh/nodejs-unittest-sample", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 14.8518518519, "max_line_length": 45, "alphanum_fraction": 0.5162094763}
var q = require('q');

class SearchRepository {

	constructor (db) {
		this.db = db;
	}
	
	search (keyword) {
		// Sample data
		var data = [{
			firstName: 'foo',
			lastName: 'bar'
		}, {
			firstName: 'foo1',
			lastName: 'bar1'
		}, {
			firstName: 'foo2',
			lastName: 'bar2'
		}, {
			firstName: 'foo3',
			lastName: 'bar3'
		}];
		var promise = q.defer();

		db.find({
			'name': keyword
		})
		.then(data => {
			promise.resolve(data);
		}, error => {
			promise.reject(error);
		});

		return promise.defer;

		/*return new Promise((resolve, reject) => {
			var promise = db.find({});

			promise.then(data => {
				resolve(data);
			});
			
			setTimeout(() => {
				if (keyword.length % 2 === 0) {
					resolve(data);
				} else {
					reject('some error');
				}
			}, 2000);
		});*/
	
	}
}