Skip to content

Commit

Permalink
Merge pull request #145 from sparcs-kaist/feature/showBoard
Browse files Browse the repository at this point in the history
feature: Zabo 추가 / 수정 페이지에서 Zabo Board 게시 여부 선택
  • Loading branch information
withSang authored May 5, 2024
2 parents 16ad29e + ea1867a commit db6e744
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
25 changes: 25 additions & 0 deletions migrations/1714912017538-add_showBoard_field.js
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 2 additions & 0 deletions src/admin/components/uploadZabo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -111,6 +111,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
req.files,
);
category = (category || "")
Expand Down Expand Up @@ -142,6 +143,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
});

const calSizes = [];
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/zabo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -74,6 +74,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
req.files,
);
category = (category || "")
Expand All @@ -99,6 +100,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
});

const calSizes = [];
Expand Down Expand Up @@ -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",
Expand All @@ -142,6 +144,7 @@ export const editZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
);
category = (category || "")
.toLowerCase()
Expand All @@ -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,
});
});

Expand Down
1 change: 1 addition & 0 deletions src/db/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const zaboSchemaObject = {
eventType: String, // '행사' or '신청'
},
],
showBoard: Boolean,
pins: [
{
type: mongoose.Schema.ObjectId,
Expand Down

0 comments on commit db6e744

Please sign in to comment.