From aba91e342ceaa80f280a097c9d49b5c554f09739 Mon Sep 17 00:00:00 2001 From: Yongworry Date: Fri, 26 Apr 2024 21:56:27 +0900 Subject: [PATCH 1/2] showBoard --- src/admin/components/uploadZabo.jsx | 2 ++ src/controllers/admin.js | 4 +++- src/controllers/zabo.js | 9 +++++++-- src/db/schema.js | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/admin/components/uploadZabo.jsx b/src/admin/components/uploadZabo.jsx index 411cd7b..cfc89d4 100644 --- a/src/admin/components/uploadZabo.jsx +++ b/src/admin/components/uploadZabo.jsx @@ -71,6 +71,7 @@ const uploadZaboComponent = (props) => { const [description, setDescription] = useState(""); const [category, setCategory] = useState(""); const [schedule, setSchedule] = useState({}); + const [showBoard, setShowBoard] = useState(false); const handleZaboChange = (e) => { const files = Array.from(e.target.files); @@ -119,6 +120,7 @@ const uploadZaboComponent = (props) => { zaboJSON.append("title", title); zaboJSON.append("description", description); zaboJSON.append("category", category); + zaboJSON.append("showBoard", showBoard); //TODO: handle if schedule exists // formData.append("schedule", schedule); diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 65a1a5d..a10467c 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -101,7 +101,7 @@ export const checkAdmin = ash(async (req, res, next) => { export const postNewZabo = ash(async (req, res) => { const self = req.adminUser.user; - const { title, description, schedules: jsonSchedules } = req.body; + const { title, description, schedules: jsonSchedules, showBoard } = req.body; const schedules = parseJSON(jsonSchedules, []); let { category } = req.body; logger.zabo.info( @@ -111,6 +111,7 @@ export const postNewZabo = ash(async (req, res) => { description, category, schedules, + showBoard, req.files, ); category = (category || "") @@ -142,6 +143,7 @@ export const postNewZabo = ash(async (req, res) => { description, category, schedules, + showBoard, }); const calSizes = []; diff --git a/src/controllers/zabo.js b/src/controllers/zabo.js index 06d5d6d..03882f5 100644 --- a/src/controllers/zabo.js +++ b/src/controllers/zabo.js @@ -64,7 +64,7 @@ export const getZabo = ash(async (req, res) => { export const postNewZabo = ash(async (req, res) => { const { self } = req; - const { title, description, schedules: jsonSchedules } = req.body; + const { title, description, schedules: jsonSchedules, showBoard } = req.body; const schedules = parseJSON(jsonSchedules, []); let { category } = req.body; logger.zabo.info( @@ -74,6 +74,7 @@ export const postNewZabo = ash(async (req, res) => { description, category, schedules, + showBoard, req.files, ); category = (category || "") @@ -99,6 +100,7 @@ export const postNewZabo = ash(async (req, res) => { description, category, schedules, + showBoard, }); const calSizes = []; @@ -133,7 +135,7 @@ export const postNewZabo = ash(async (req, res) => { export const editZabo = ash(async (req, res) => { const { zabo } = req; - const { title, description, schedules = [] } = req.body; + const { title, description, schedules = [], showBoard } = req.body; let { category } = req.body; logger.zabo.info( "post /zabo/%s/edit request; title: %s, description: %s, category: %s, schedules: %s", @@ -142,6 +144,7 @@ export const editZabo = ash(async (req, res) => { description, category, schedules, + showBoard, ); category = (category || "") .toLowerCase() @@ -151,12 +154,14 @@ export const editZabo = ash(async (req, res) => { zabo.description = description; zabo.category = category; zabo.schedules = schedules; + zabo.showBoard = showBoard; await zabo.save(); return res.json({ title: zabo.title, description: zabo.description, category: zabo.category, schedules: zabo.schedules, + showBoard: zabo.showBoard, }); }); diff --git a/src/db/schema.js b/src/db/schema.js index 446690f..2ecb8c5 100644 --- a/src/db/schema.js +++ b/src/db/schema.js @@ -74,6 +74,7 @@ const zaboSchemaObject = { eventType: String, // '행사' or '신청' }, ], + showBoard: Boolean, pins: [ { type: mongoose.Schema.ObjectId, From ea1867ae824dc9ed9ea3af05d9e3a5fe180e6b8c Mon Sep 17 00:00:00 2001 From: Jinho-Choi123 Date: Sun, 5 May 2024 21:30:03 +0900 Subject: [PATCH 2/2] migrate: add showBoard field to zabo schema --- .../1714912017538-add_showBoard_field.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 migrations/1714912017538-add_showBoard_field.js diff --git a/migrations/1714912017538-add_showBoard_field.js b/migrations/1714912017538-add_showBoard_field.js new file mode 100644 index 0000000..398747e --- /dev/null +++ b/migrations/1714912017538-add_showBoard_field.js @@ -0,0 +1,25 @@ +require ('@babel/register'); +require ('../config/env'); + +const {Zabo} = require('../src/db'); + +/** + * Make any changes you need to make to the database here + */ +async function up () { + // Write migration here + // eslint-disable-next-line no-restricted-syntax + for await (const zabo of Zabo.find()) { + zabo.showBoard = false; + await zabo.save (); + } +} + +/** + * Make any changes that UNDO the up function side effects here (if possible) + */ +async function down () { + // Write migration here +} + +module.exports = { up, down };