theater.controller.js 1.79 KB
Newer Older
Kim, Subin's avatar
theater    
Kim, Subin committed
1
import { Theater, TicketFee } from "../db/index.js";
2
3

const getTheaterInfo = async (req, res) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
4
    const { theaterName } = req.body
5
6
    try {
        const theaterInfo = await Theater.findOne({
Jiwon Yoon's avatar
Jiwon Yoon committed
7
8
            where: { theaterName: String(theaterName) },
            attributes: ['theaterName', 'rows', 'columns']
9
10
11
        })
        // console.log("theaterInfo====",theaterInfo)
        return res.json(theaterInfo)
Jiwon Yoon's avatar
Jiwon Yoon committed
12
13
14
15
    } catch (error){
        console.log(error)
    }
}
Kim, Subin's avatar
theater    
Kim, Subin committed
16
17
18
19
20
const getAll = async (req, res) => {
    try {
        const findList = await Theater.findAll({ include: [{ model: TicketFee, attributes: ["theaterType"] }] })
        console.log("Ads==", findList)
        return res.json(findList)
21
22
23
24
25
    } catch (error) {
        return res.status(500).send(error.message || "상영관 정보 가져오는 중 에러 발생")
    }
}

Kim, Subin's avatar
theater    
Kim, Subin committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const getTypes = async (req, res) => {
    try {
        const findTypes = await TicketFee.findAll({ attributes: ['id', 'theaterType'] })
        return res.json(findTypes)
    } catch (error) {
        return res.status(500).send(error.message || "상영관 정보 가져오는 중 에러 발생")
    }
}

const submit = async (req, res) => {
    try {
        const { id } = req.body
        let response = null
        if (id) response = await Theater.update({ ...req.body }, { where: { id: id } })
        else response = await Theater.create({ ...req.body })
        return res.json(response)
    } catch (error) {
        return res.status(500).send(error.message || "상영관 정보 저장 중 에러 발생")
    }
}

const remove = async (req, res) => {
    try {

    } catch (error) {
        return res.status(500).send(error.message || "상영관 정보 삭제 중 에러 발생")
    }
}

export default {
    getAll,
    getTypes,
    submit,
Jiwon Yoon's avatar
Jiwon Yoon committed
59
60
61
    remove,
    getTheaterInfo
}