proton-model
Advanced tools
Comparing version 1.2.4 to 1.2.5
37
index.js
'use strict' | ||
const _ = require('lodash') | ||
const Schema = require('mongoose').Schema | ||
@@ -44,8 +45,8 @@ module.exports = class MongooseModel { | ||
_buildSchema() { | ||
const prototype = this.constructor.prototype | ||
const constructor = this.constructor | ||
this._schema = this.mongoose.Schema(this.schema()) | ||
let prototype = this.constructor.prototype | ||
let constructor = this.constructor | ||
this._schema = new Schema(this.schema(), {}) | ||
this._createStaticMethods(constructor) | ||
// this._createInstanceMethods(prototype) | ||
// this._createVirtualMethods(prototype) | ||
this._createInstanceMethods(prototype) | ||
this._createVirtualMethods(prototype) | ||
return this._schema | ||
@@ -59,3 +60,2 @@ | ||
if (this._isInstanceMethod(name, method)) { | ||
this.proton.log.silly('Instance method', name, method.value) | ||
this._schema.method(name, method.value) | ||
@@ -71,4 +71,3 @@ } | ||
if (this._isStaticMethod(name, method)) { | ||
console.log('Static method', _.isUndefined(name)) | ||
this._schema.statics.metodo = method.value | ||
this._schema.static(name, method.value) | ||
} | ||
@@ -83,3 +82,2 @@ }) | ||
if (this._isVirtualMethod(name, method)) { | ||
this.proton.log.silly('Virtual method', name, method.value) | ||
this._setVirtualMethod(name, method) | ||
@@ -91,26 +89,15 @@ } | ||
_isStaticMethod(name, method) { | ||
return ( | ||
name && | ||
name !== 'prototype' && | ||
name != 'schema' && | ||
name !== 'length' | ||
) | ||
return (name !== 'prototype' && name != 'schema' && name !== 'length') | ||
} | ||
_isInstanceMethod(name, method) { | ||
return ( | ||
name && | ||
name !== 'constructor' && | ||
return (name !== 'constructor' && | ||
name != 'schema' && | ||
!(method.set || method.get) | ||
) | ||
!(method.set || method.get)) | ||
} | ||
_isVirtualMethod(name, method) { | ||
return ( | ||
name && | ||
name !== 'constructor' && | ||
return (name !== 'constructor' && | ||
name != 'schema' && | ||
(_.has(method, 'set') || _.has(method, 'get')) | ||
) | ||
(_.has(method, 'set') || _.has(method, 'get'))) | ||
} | ||
@@ -117,0 +104,0 @@ |
{ | ||
"name": "proton-model", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "", | ||
@@ -12,4 +12,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"mongoose": "^4.3.6" | ||
"mongoose": "^4.3.7" | ||
} | ||
} |
3485
89
Updatedmongoose@^4.3.7