0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Update API to support homebrew tags

#758
This commit is contained in:
Charlie Humphreys
2021-11-17 22:22:33 -06:00
parent 0d685acfca
commit 22f9efd58a
2 changed files with 20 additions and 1 deletions

View File

@@ -76,6 +76,7 @@ const updateBrew = (req, res)=>{
const updateBrew = excludePropsFromUpdate(req.body);
brew = _.merge(brew, updateBrew);
brew.text = mergeBrewText(brew.text, brew.style);
brew.tags = updateBrew.tags;
// Compress brew text to binary before saving
brew.textBin = zlib.deflateRawSync(brew.text);

View File

@@ -12,7 +12,7 @@ const HomebrewSchema = mongoose.Schema({
pageCount : { type: Number, default: 1 },
description : { type: String, default: '' },
tags : { type: String, default: '' },
tags : [String],
systems : [String],
renderer : { type: String, default: '' },
authors : [String],
@@ -66,6 +66,24 @@ HomebrewSchema.statics.getByUser = function(username, allowAccess=false){
const Homebrew = mongoose.model('Homebrew', HomebrewSchema);
Homebrew.count({ tags: '' }, async (err, count)=>{
if(!err) {
if(count > 0) {
Homebrew.updateMany({ tags: '' }, { tags: [] }, { multi: true }, function(err, data) {
if(!err) {
console.log('Successfully updated all brews to new schema definition');
} else {
console.log('An error occurred while updating brews to the new schema', err);
}
});
} else {
console.log('No brews to update');
}
} else {
console.log('An error occurred while counting brews with the old schema', err);
}
});
module.exports = {
schema : HomebrewSchema,
model : Homebrew,