Commit 931380b0 authored by Kim, Subin's avatar Kim, Subin
Browse files

timetableCtrl 수정 완료

parent 002ed01f
import { TimeTable, Theater } from "../db/index.js"; import { TimeTable, Theater, TheaterType } from "../db/index.js";
import moment from 'moment'; import moment from 'moment';
import sequelize from 'sequelize' import sequelize from 'sequelize'
const { Op } = sequelize const { Op } = sequelize
...@@ -8,21 +8,18 @@ const getAll = async (req, res) => { ...@@ -8,21 +8,18 @@ const getAll = async (req, res) => {
const { when } = req.query const { when } = req.query
const selectDate = new Date(when) const selectDate = new Date(when)
const theaterArr = [] const theaterArr = []
// const timeTableArr = []
const findAll = await TimeTable.findAll({ where: { date: selectDate }, attributes: { exclude: ['createdAt', 'updatedAt'] }, order: [["theater", "ASC"], ["start_time", "ASC"]] }) const findAll = await TimeTable.findAll({ where: { date: selectDate }, attributes: { exclude: ['createdAt', 'updatedAt'] }, order: [["theater", "ASC"], ["start_time", "ASC"]] })
findAll.forEach(element => { findAll.forEach(element => {
if (!theaterArr.includes(element.theater)) theaterArr.push(element.theater) if (!theaterArr.includes(element.theater)) theaterArr.push(element.theater)
}) })
const findTheater = await Theater.findAll({ where: { id: theaterArr }, attributes: { exclude: ['createdAt', 'updatedAt'] }, order: [['theaterName']] }) const findTheater = await Theater.findAll({ where: { id: theaterArr }, attributes: { exclude: ['createdAt', 'updatedAt'] }, include: [TheaterType], order: [['theaterName']] })
findTheater.forEach(el => { findTheater.forEach(el => {
const arr = findAll.filter(timetable => { const arr = findAll.filter(timetable => {
if (el.id === timetable.theater) return timetable.dataValues if (el.id === timetable.theater) return timetable.dataValues
}) })
el.dataValues.timetable = arr el.dataValues.timetable = arr
// timeTableArr.push({ id: el.id, info: arr })
}) })
return res.json(findTheater) return res.json(findTheater)
// return res.json({findTheater, timeTableArr})
} catch (error) { } catch (error) {
return res.status(500).send(error.message || "상영시간표 정보 가져오는 중 에러 발생") return res.status(500).send(error.message || "상영시간표 정보 가져오는 중 에러 발생")
} }
...@@ -62,7 +59,7 @@ const submit = async (req, res) => { ...@@ -62,7 +59,7 @@ const submit = async (req, res) => {
await Promise.all( await Promise.all(
theater.map(async (theater) => { theater.map(async (theater) => {
let partTime = "" let partTime = ""
if ('06:00' <= theater.start < '10:00') partTime = "morning" if ('06:00' <= theater.start && theater.start < '10:00') partTime = "morning"
else if ('00:00' <= theater.start < '06:00') partTime = "night" else if ('00:00' <= theater.start < '06:00') partTime = "night"
else partTime = "day" else partTime = "day"
await TimeTable.create({ theater: theater.theater, movieId, title, release_date, date: curDate, start_time: getTime(theater.start), end_time: getTime(theater.start, runtime), partTime: partTime, week: (day === 0 || day === 6) ? "weekend" : "weekdays" }) await TimeTable.create({ theater: theater.theater, movieId, title, release_date, date: curDate, start_time: getTime(theater.start), end_time: getTime(theater.start, runtime), partTime: partTime, week: (day === 0 || day === 6) ? "weekend" : "weekdays" })
...@@ -85,7 +82,7 @@ const getTime = (string, runtime = 0) => { ...@@ -85,7 +82,7 @@ const getTime = (string, runtime = 0) => {
const remove = async (req, res) => { const remove = async (req, res) => {
try { try {
const { timeId } = req.params const { timeId } = req.params
const delNum = await TimeTable.destroy({ where: {} }) const delNum = await TimeTable.destroy({ where: { id: timeId } })
if (delNum) res.json(delNum) if (delNum) res.json(delNum)
else throw new Error("해당 정보를 서버에서 삭제하는데 실패했습니다.") else throw new Error("해당 정보를 서버에서 삭제하는데 실패했습니다.")
} catch (error) { } catch (error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment