advaya-mongo
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -34,4 +34,4 @@ var db= require('./db'); | ||
connect: db.connect, | ||
initialize: initialize | ||
initialize: initialize(models) | ||
} | ||
} |
@@ -1,5 +0,44 @@ | ||
module.exports= function () { | ||
return new Promise(function (resolve,reject) { | ||
resolve(1); | ||
}); | ||
module.exports= function (models) { | ||
return function () { | ||
var db = require('./db').getDb(); | ||
return new Promise(function (resolve,reject) { | ||
var indexPromiseArr= Object.keys(models) | ||
.map(function (modelName) { | ||
return models[modelName]; | ||
}) | ||
.filter(function (model) { | ||
if(model.schema.hasOwnProperty('index') && Array.isArray(model.schema.index)) | ||
return true; | ||
}) | ||
.map(function (model) { | ||
if(model.schema.hasOwnProperty('embeded')) | ||
{ | ||
var transformIndex= model.schema.index.map(function (index) { | ||
var keyObj={} | ||
Object.keys(index.key) | ||
.map(function (key) { | ||
keyObj[model.modelName+'.'+key]=index.key[key]; | ||
}); | ||
index.key= keyObj; | ||
return index; | ||
}); | ||
var idUnique={ key: { }, unique: true }; | ||
idUnique.key[model.modelName+'._id']=1; | ||
transformIndex.push(idUnique); | ||
// console.log(transformIndex); | ||
return db.collection(model.schema.embeded).createIndexes(transformIndex); | ||
} | ||
else | ||
{ | ||
return db.collection(model.modelName).createIndexes(model.schema.index); | ||
} | ||
}) | ||
resolve(Promise.all(indexPromiseArr)); | ||
}); | ||
} | ||
} |
{ | ||
"name": "advaya-mongo", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Advaya mongo plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26732
866