0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 22:52:40 +00:00

Apply defaults on load and before saving

This commit is contained in:
G.Ambatte
2022-10-09 21:49:25 +13:00
parent a3c7e2f807
commit 41fa0f2c77

View File

@@ -9,6 +9,18 @@ const yaml = require('js-yaml');
const asyncHandler = require('express-async-handler');
const { nanoid } = require('nanoid');
const DEFAULT_BREW = {
title : 'Untitled Brew',
description : '',
renderer : 'V3',
tags : [],
systems : [],
thumbnail : '',
published : false,
pageCount : 1,
theme : '5ePHB'
};
// const getTopBrews = (cb) => {
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
// cb(brews);
@@ -66,6 +78,8 @@ const getBrew = (accessType)=>{
if(typeof stub.tags === 'string') {
stub.tags = [];
}
_.defaults(stub, DEFAULT_BREW);
req.brew = stub;
next();
@@ -130,6 +144,8 @@ const beforeNewSave = (account, brew)=>{
brew.authors = (account) ? [account.username] : [];
brew.text = mergeBrewText(brew);
_.defaults(brew, DEFAULT_BREW);
};
const newGoogleBrew = async (account, brew, res)=>{