mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 10:52:46 +00:00
Add default loading properties using custom assign
This commit is contained in:
@@ -9,6 +9,7 @@ const yaml = require('js-yaml');
|
|||||||
const asyncHandler = require('express-async-handler');
|
const asyncHandler = require('express-async-handler');
|
||||||
const { nanoid } = require('nanoid');
|
const { nanoid } = require('nanoid');
|
||||||
|
|
||||||
|
// Default brew properties in most cases
|
||||||
const DEFAULT_BREW = {
|
const DEFAULT_BREW = {
|
||||||
title : 'Untitled Brew',
|
title : 'Untitled Brew',
|
||||||
description : '',
|
description : '',
|
||||||
@@ -20,6 +21,11 @@ const DEFAULT_BREW = {
|
|||||||
pageCount : 1,
|
pageCount : 1,
|
||||||
theme : '5ePHB'
|
theme : '5ePHB'
|
||||||
};
|
};
|
||||||
|
// Default brew properties for loading
|
||||||
|
const DEFAULT_BREW_LOAD = {
|
||||||
|
renderer : 'legacy',
|
||||||
|
published : true
|
||||||
|
};
|
||||||
|
|
||||||
// const getTopBrews = (cb) => {
|
// const getTopBrews = (cb) => {
|
||||||
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
||||||
@@ -79,7 +85,11 @@ const getBrew = (accessType)=>{
|
|||||||
stub.tags = [];
|
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;
|
req.brew = stub;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user