Comments (5)
This isn't a reproducible code example, just the code that you linked to. At this point I'm unable to help since I don't have enough information to work with. I'd also venture to say that you shouldn't need to transpile your model code since it's not intended for the browser.
from mongo-models.
You may want to make an exception and not run your models through a transpiler like babel
.
Though I am curious how are you using the constructor without the new
keyword. Can you share example code that produces this error?
from mongo-models.
i exactly use aqua source, this is my code https://github.com/jedireza/aqua/blob/master/server/models/session.js
from mongo-models.
That's the model. However it sounds like how that model get's instantiated is the problem (not using a new
keyword.
Sharing a reproducible code snippet that I can run to get the same error would be most helpful.
from mongo-models.
'use strict';
const Async = require('async');
const Bcrypt = require('bcrypt');
const Joi = require('joi');
const MongoModels = require('mongo-models');
const Uuid = require('uuid');
class Session extends MongoModels {
static generateKeyHash(callback) {
const key = Uuid.v4();
Async.auto({
salt: function (done) {
Bcrypt.genSalt(10, done);
},
hash: ['salt', function (results, done) {
Bcrypt.hash(key, results.salt, done);
}]
}, (err, results) => {
if (err) {
return callback(err);
}
callback(null, {
key,
hash: results.hash
});
});
}
static create(userId, callback) {
const self = this;
Async.auto({
keyHash: this.generateKeyHash.bind(this),
newSession: ['keyHash', function (results, done) {
const document = {
userId,
key: results.keyHash.hash,
time: new Date()
};
self.insertOne(document, done);
}],
clean: ['newSession', function (results, done) {
const query = {
userId,
key: { $ne: results.keyHash.hash }
};
self.deleteOne(query, done);
}]
}, (err, results) => {
if (err) {
return callback(err);
}
results.newSession[0].key = results.keyHash.key;
callback(null, results.newSession[0]);
});
}
static findByCredentials(id, key, callback) {
const self = this;
Async.auto({
session: function (done) {
self.findById(id, done);
},
keyMatch: ['session', function (results, done) {
if (!results.session) {
return done(null, false);
}
const source = results.session.key;
Bcrypt.compare(key, source, done);
}]
}, (err, results) => {
if (err) {
return callback(err);
}
if (results.keyMatch) {
return callback(null, results.session);
}
callback();
});
}
}
Session.collection = 'sessions';
Session.schema = Joi.object({
_id: Joi.object(),
userId: Joi.string(),
key: Joi.string(),
time: Joi.date()
});
Session.constructWithSchema = true;
Session.indexes = [
{ key: { userId: 1 } }
];
module.exports = Session;
from mongo-models.
Related Issues (20)
- Support for other WriteResult parameters HOT 1
- Add mongodb to dependencies HOT 1
- Promise support HOT 2
- Native Async/Await Support HOT 2
- Mongo Lookup Support HOT 1
- Migrate callbacks patterns to async/await
- MongoClient.connect function incompatible with Node MongoDB 3.6 driver HOT 2
- MongoModels#aggregate does not pass test case HOT 3
- v2.x.x Release Notes
- *byId methods don't work with custom IDs HOT 1
- How to declare a view with mongo-models HOT 1
- [Question] createIndexes guide HOT 1
- Using dynamic schema HOT 4
- [Question] Hoek dependency HOT 2
- [Question] Models schema validation breaks partial fields loading HOT 1
- Question: why I have to pass db though db is already included in the uri? HOT 1
- Proposal: Add an option that allows one to not validate mongo query results HOT 14
- Compatibility with @hapi/joi 17 HOT 4
- Would you consider an alternative? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo-models.