mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 06:32:39 +00:00
Adding a new script from populating the DB with a bunch of random brews
This commit is contained in:
@@ -22,7 +22,7 @@ const BrewSchema = mongoose.Schema({
|
||||
updatedAt : { type: Date, default: Date.now},
|
||||
lastViewed : { type: Date, default: Date.now},
|
||||
views : {type:Number, default:0},
|
||||
version : {type: Number, default:1}
|
||||
version : {type: Number, default:1}
|
||||
}, {
|
||||
versionKey: false,
|
||||
toJSON : {
|
||||
@@ -33,6 +33,7 @@ const BrewSchema = mongoose.Schema({
|
||||
}
|
||||
});
|
||||
|
||||
//Index these fields for fast text searching
|
||||
BrewSchema.index({ title: "text", description: "text" });
|
||||
|
||||
BrewSchema.methods.increaseView = function(){
|
||||
@@ -42,9 +43,6 @@ BrewSchema.methods.increaseView = function(){
|
||||
|
||||
|
||||
const Brew = mongoose.model('Brew', BrewSchema);
|
||||
|
||||
|
||||
|
||||
const BrewData = {
|
||||
schema : BrewSchema,
|
||||
model : Brew,
|
||||
@@ -96,6 +94,12 @@ const BrewData = {
|
||||
return BrewData.get({ editId });
|
||||
},
|
||||
|
||||
|
||||
//TODO: Add a 'core search' which just takes a search object
|
||||
//TODO: extend the core search with a user search and a term search
|
||||
//TODO: break these functions off into a 'brew.search.js' file
|
||||
//TODO: pagniation, sorting and full access should be an 'opts' param
|
||||
|
||||
search : (searchTerms, pagination, sorting, fullAccess = true) => {
|
||||
let query = {};
|
||||
if(searchTerms){
|
||||
|
||||
@@ -8,14 +8,14 @@ module.exports = {
|
||||
connect : ()=>{
|
||||
return new Promise((resolve, reject)=>{
|
||||
if(mongoose.connection.readyState == 1){
|
||||
log.info('DB already connected');
|
||||
log.warn('DB already connected');
|
||||
return resolve();
|
||||
}
|
||||
mongoose.connect(dbPath,
|
||||
(err) => {
|
||||
if(err){
|
||||
log.info('Error : Could not connect to a Mongo Database.');
|
||||
log.info(' If you are running locally, make sure mongodb.exe is running.');
|
||||
log.error('Error : Could not connect to a Mongo Database.');
|
||||
log.error(' If you are running locally, make sure mongodb.exe is running.');
|
||||
return reject(err);
|
||||
}
|
||||
log.info('DB connected.');
|
||||
|
||||
Reference in New Issue
Block a user