cinema.controller.js 1.04 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
4
5
6
import { Cinema } from "../db/index.js";

const getAll = async (req, res) => {
    try {
        const info = await Cinema.findOne({
            where: { id: 1 },
Kim, Subin's avatar
Kim, Subin committed
7
            attributes: ['cinemaName', 'transportation', 'parking', 'address', 'moreFeeInfo']
Kim, Subin's avatar
Kim, Subin committed
8
        })
Jiwon Yoon's avatar
Jiwon Yoon committed
9
        // console.log("INfo====",info)
Kim, Subin's avatar
Kim, Subin committed
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
        return res.json(info)
    } catch (error) {
        return res.status(500).send(error.message || "영화관 정보 가져오는 중 에러 발생")
    }
}

const edit = async (req, res) => {
    try {
        let response = null
        const result = await Cinema.findOrCreate({
            where: { id: 1 },
            defaults: { ...req.body }
        })
        if (!result[1]) {
            const updateData = await Cinema.update({ ...req.body }, { where: { id: 1 } })
            response = updateData
        } else response = result[0]
        return res.json(response)
    } catch (error) {
        return res.status(500).send(error.message || "영화관 정보 수정 중 에러 발생")
    }
}

export default {
    getAll,
    edit
}