0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Add default loading properties using custom assign

This commit is contained in:
G.Ambatte
2022-10-20 19:11:31 +13:00
parent 9ccf9d0a83
commit 52a79b4f75

View File

@@ -9,6 +9,7 @@ const yaml = require('js-yaml');
const asyncHandler = require('express-async-handler');
const { nanoid } = require('nanoid');
// Default brew properties in most cases
const DEFAULT_BREW = {
title : 'Untitled Brew',
description : '',
@@ -20,6 +21,11 @@ const DEFAULT_BREW = {
pageCount : 1,
theme : '5ePHB'
};
// Default brew properties for loading
const DEFAULT_BREW_LOAD = {
renderer : 'legacy',
published : true
};
// const getTopBrews = (cb) => {
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
@@ -79,7 +85,11 @@ const getBrew = (accessType)=>{
stub.tags = [];
}
_.defaults(stub, DEFAULT_BREW);
// Use _.assignWith instead of _.defaults - does this need to be replicated at all other uses of _.defaults???
_.assignWith(stub, DEFAULT_BREW_LOAD, DEFAULT_BREW, (objValue, srcValue)=>{
if(typeof objValue === 'boolean') return objValue;
return objValue || srcValue;
});
req.brew = stub;
next();