theater.controller.js 1.36 KB
Newer Older
Kim, Subin's avatar
theater    
Kim, Subin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Theater, TicketFee } from "../db/index.js";

const getAll = async (req, res) => {
    try {
        const findList = await Theater.findAll({ include: [{ model: TicketFee, attributes: ["theaterType"] }] })
        console.log("Ads==", findList)
        return res.json(findList)
    } catch (error) {
        return res.status(500).send(error.message || "상영관 정보 가져오는 중 에러 발생")
    }
}

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,
    remove
}