// Data access : User --
// Based on OrientDB : https://www.npmjs.com/package/orientjs
"use strict"

var path = require('path');
var crypto = require('crypto');
var db = require(path.resolve('./src/modules/database'));
var object = require(path.resolve('./src/models/object'));

var hash = function(value) {
  return crypto.createHash('sha256').update(value).digest('base64');
};

// -- Class --

var addMethods = function(obj) {
  obj.test = function(password) {
    return hash(password) === this.password;
  };
};

var Class = function(username, password) {

  this.username = username;
  this.password = password;

  object.helper.addMethodsToObject(this, 'User');
  addMethods(this);
};

var transform = function(user) {
  var objects = object.helper.transformRecordsIntoObjects(user, 'User');
  object.helper.apply(objects, addMethods);
  return objects;
};


// -- Module exports --

exports.class = Class;

exports.createRecords = function(objects) {
  var records = object.helper.transformObjectsIntoRecords(objects, 'User');
  return db.helper.createRecord('User', records);
};

exports.getByUsername = function(username) {
  // Find OUser in OrientDB --
  return db.select().from('User').where({username: username}).one()
    .then(transform);
};

exports.getByRid = function(username) {
  // Find OUser in OrientDB --
  return db.select().from('User').where({'@rid': username}).one()
    .then(transform);
};
@@ -1078,24 +1078,53 @@
 cords);%0A%7D;%0A%0A
+// Find User in OrientDB --%0A%0A
 exports.getB
@@ -1160,39 +1160,8 @@
 ) %7B%0A
-  // Find OUser in OrientDB --%0A
   re
@@ -1282,50 +1282,14 @@
 ion(
-username) %7B%0A  // Find OUser in OrientDB --
+rid) %7B
 %0A  r
@@ -1334,24 +1334,19 @@
 '@rid': 
-username
+rid
 %7D).one()

Refactor User model for better readability