Commit 4397ad6f authored by Kim, Subin's avatar Kim, Subin
Browse files

timetable Api 및 서버쪽 기능 구현 중

parent 28bba9d9
import axios from "axios";
import { baseUrl } from "../utils/baseUrl.js";
const submit = async (sendData) => {
const { data } = await axios.post(`${baseUrl}/api/timetable`, sendData)
return data
}
const timetableApi = {
submit
}
export default timetableApi
\ No newline at end of file
import { TimeTable } from "../db/index.js";
import sequelize from 'sequelize'
const { Op } = sequelize
const submit = async (req, res) => {
try {
console.log("req.body==", req.body)
const { theater, runtime } = req.body
const result = theater.filter(async (theater) => {
const startDate = getDate(theater.start)
const endDate = getDate(theater.start, runtime)
// const isTimeTable = await TimeTable.findAll({
// where: {
// [Op.and]: [
// { theater: theater.theater },
// {
// [Op.and]: [
// { start_date: { [Op.lte]: endDate } },
// { end_date: { [Op.gte]: startDate } }
// ]
// }
// ]
// }
// })
// [Op.or]: [{ [Op.and]: [{ start_date: { [Op.gt]: startDate } }, { start_date: { [Op.gt]: endDate } }] },
// { [Op.and]: [{ end_date: { [Op.lt]: startDate } }, { end_date: { [Op.lt]: endDate } }] }]
console.log("isTimeTable==", isTimeTable)
return isTimeTable
})
console.log("result==", result)
} catch (error) {
return res.status(500).send(error.message || "상영시간표 저장 중 에러 발생")
}
}
const getDate = (string, runtime = 0) => {
const arr = string.split(':')
const date = new Date(0, 0, 0, Number(arr[0]), Number(arr[1]) + runtime)
// console.log("custom==", date.toString())
return date
}
export default {
submit
}
\ No newline at end of file
...@@ -20,11 +20,19 @@ const TimeTableModel = (sequelize) => { ...@@ -20,11 +20,19 @@ const TimeTableModel = (sequelize) => {
title: { title: {
type: DataTypes.STRING, type: DataTypes.STRING,
}, },
runtime: {
type: DataTypes.INTEGER,
},
release_date: { release_date: {
type: DataTypes.STRING type: DataTypes.STRING
}, },
date: { start_date: {
type: DataTypes.STRING, type: DataTypes.DATE,
defaultValue: new Date(0)
},
end_date: {
type: DataTypes.DATE,
defaultValue: new Date(0)
}, },
time: { time: {
type: DataTypes.TIME, type: DataTypes.TIME,
......
...@@ -2,6 +2,7 @@ import express from "express"; ...@@ -2,6 +2,7 @@ import express from "express";
import userRouter from './user.route.js' import userRouter from './user.route.js'
import movieRouter from './movie.route.js' import movieRouter from './movie.route.js'
import theaterRouter from "./theater.route.js"; import theaterRouter from "./theater.route.js";
import timetableRouter from "./timetable.route.js";
import cinemaRouter from "./cinema.route.js"; import cinemaRouter from "./cinema.route.js";
import kakaopayRouter from "./kakaopay.route.js"; import kakaopayRouter from "./kakaopay.route.js";
import emailRouter from './email.route.js' import emailRouter from './email.route.js'
...@@ -14,5 +15,6 @@ router.use('/kakaopay',kakaopayRouter) ...@@ -14,5 +15,6 @@ router.use('/kakaopay',kakaopayRouter)
router.use('/email',emailRouter) router.use('/email',emailRouter)
router.use('/info', cinemaRouter) router.use('/info', cinemaRouter)
router.use('/theater', theaterRouter) router.use('/theater', theaterRouter)
router.use('/timetable', timetableRouter)
export default router; export default router;
\ No newline at end of file
import express from "express";
import timetableCtrl from "../controllers/timetable.controller.js";
const router = express.Router();
router
.route("/")
.post(timetableCtrl.submit)
export default router;
\ No newline at end of file
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