Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return self.getModel(name);
}
// Sometimes self has a bad assignation and be Global scope, for this reason
// we assign mongoose as self an try to return required model.
if(!self.db){
self = mongoose;
return self.model(name);
}
// Normal flow should return model as is.
return this.db.model(name);
};
module.exports = mongoose.Model.prototype.model;
module.exports = function (yaktor, done) {
require('mongoose-pagination')
var f1nU = mongoose.Model.findOneAndUpdate
// Monkey Patch for update existing doc.
mongoose.Model.findOneAndUpdate = function (q, doc) {
if (doc != null && doc.toObject != null) {
var newDoc = doc.toObject()
delete newDoc._id
arguments[1] = newDoc
return f1nU.apply(this, arguments)
} else {
return f1nU.apply(this, arguments)
}
}
if (mongoose.connection._readyState !== 0) return done()
var opened = false
function denodifyMethod(funcName){
return function(){
return Q.npost(this, funcName, arguments);
}
};
// Query
mongoose.Query.prototype.findQ = denodifyMethod("find");
mongoose.Query.prototype.findOneQ = denodifyMethod("findOne");
mongoose.Query.prototype.countQ = denodifyMethod("count");
mongoose.Query.prototype.removeQ = denodifyMethod("remove");
// Model
mongoose.Model.prototype.saveQ = denodifyMethod("save");
mongoose.Model.prototype.removeQ = denodifyMethod("remove");
mongoose.connectQ = connectQ;
module.exports = mongoose;
var sinon = require('sinon')
, mongoose = require('mongoose');
sinon.stub(mongoose.Model.prototype, 'save', function(cb) {
var model = this;
this.validate(function(err) {
if (!err) {
model.isNew = false;
}
cb(err, model);
});
});
export function model(type: Constructor) {
class ModelMock { }
return new Proxy(Mongoose.Model as Mongoose.Model, new ModelProxyHandler(type))
}
this.model = model;
this.defaultQueryFields = ['name', 'description', 'permissions'];
}
querySearch(keyword, page, size, sort) {
const _super = Object.create(null, {
query: { get: () => super.query }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.query.call(this, page, size, {}, { keyword, field: 'name' }, this.defaultQueryFields, sort);
});
}
};
RolesService = __decorate([
common_1.Injectable(),
__param(0, mongoose_2.InjectModel('Role')),
__metadata("design:paramtypes", [mongoose_1.Model])
], RolesService);
exports.RolesService = RolesService;
//# sourceMappingURL=roles.service.js.map
this.model = model;
this.defaultQueryFields = ['name', 'translate', 'expand'];
}
querySearch(keyword, page, size, sort) {
const _super = Object.create(null, {
query: { get: () => super.query }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.query.call(this, page, size, {}, { keyword, field: 'name' }, this.defaultQueryFields, sort);
});
}
};
WidgetService = __decorate([
common_1.Injectable(),
__param(0, mongoose_2.InjectModel('Widget')),
__metadata("design:paramtypes", [mongoose_1.Model])
], WidgetService);
exports.WidgetService = WidgetService;
//# sourceMappingURL=widget.service.js.map
}
}
};
/*
* Register statics for this model
* @param {Model} model
* @param {Schema} schema
*/
var applyStatics = function(model, schema) {
for (var i in schema.statics) {
model[i] = schema.statics[i];
}
};
module.exports = mongoose.Model.discriminator;
addUserToTeam({ token, user }: { token: string; user: IUserDocument });
}
function generateToken() {
const gen = () =>
Math.random()
.toString(36)
.substring(2, 12) +
Math.random()
.toString(36)
.substring(2, 12);
return `${gen()}`;
}
class InvitationClass extends mongoose.Model {
public static async add({ userId, teamId, email }) {
if (!teamId || !email) {
throw new Error('Bad data');
}
const team = await Team.findById(teamId).setOptions({ lean: true });
if (!team || team.teamLeaderId !== userId) {
throw new Error('Team does not exist or you have no permission');
}
const registeredUser = await User.findOne({ email })
.select('defaultTeamSlug')
.setOptions({ lean: true });
if (registeredUser) {
if (team.memberIds.includes(registeredUser._id.toString())) {
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
var mongoose_1 = require('mongoose')
exports.Model = mongoose_1.Model
exports.Schema = mongoose_1.Schema
var ModelFactory = /** @class */ (function() {
function ModelFactory(_config) {
this._config = _config
}
Object.defineProperty(ModelFactory.prototype, 'schema', {
get: function() {
if (!this._schema) {
this._schema = new mongoose_1.Schema(
this._config.paths,
this._config.options
)
this._schema.method(this._config.methods || {})
this._schema.static(this._config.statics || {})
}
return this._schema