Commit 53792c65 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

오류수정

parent 80239d34
...@@ -18,6 +18,11 @@ const logout = async () => { ...@@ -18,6 +18,11 @@ const logout = async () => {
return data return data
}; };
const saveGuestInfo = async (guest) => {
const { data } = await axios.post(`${baseUrl}/api/auth/guest/save`, guest);
return data
}
const guestLogin = async (guest) => { const guestLogin = async (guest) => {
const { data } = await axios.post(`${baseUrl}/api/auth/guest`, guest); const { data } = await axios.post(`${baseUrl}/api/auth/guest`, guest);
return data return data
...@@ -68,6 +73,7 @@ const authApi = { ...@@ -68,6 +73,7 @@ const authApi = {
getUser, getUser,
login, login,
logout, logout,
saveGuestInfo,
guestLogin, guestLogin,
signup, signup,
confirmMbnum, confirmMbnum,
......
...@@ -2,8 +2,9 @@ import axios from "axios"; ...@@ -2,8 +2,9 @@ import axios from "axios";
import { baseUrl } from "../utils/baseUrl.js"; import { baseUrl } from "../utils/baseUrl.js";
const findReservedSeats = async (timeTable) => { const findReservedSeats = async (timeTable) => {
console.log(timeTable)
const url = `${baseUrl}/api/reservation/findreservation`; const url = `${baseUrl}/api/reservation/findreservation`;
const { data } = await axios.post(url, timeTable); const { data } = await axios.post(url,{timeTable:timeTable});
return data return data
} }
......
import axios from 'axios' import axios from 'axios'
import { useAuth } from '../context/auth_context' import { useAuth } from '../context/auth_context'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import catchErrors from '../utils/catchErrors' import catchErrors from '../utils/catchErrors'
import reservationApi from '../apis/reservation.api' import reservationApi from '../apis/reservation.api'
...@@ -9,79 +8,70 @@ import reservationApi from '../apis/reservation.api' ...@@ -9,79 +8,70 @@ import reservationApi from '../apis/reservation.api'
const PaymentCompletePage = () => { const PaymentCompletePage = () => {
const { user } = useAuth() const { user } = useAuth()
const [error, setError] = useState() const [error, setError] = useState()
const [success, setSuccess] = useState(false)
const [paymentData, setPaymentData] = useState()
useEffect(() => { useEffect(() => {
if (user.role === "member") { if (user.id > 0) {
getUserInfo()
} else {
getGuestInfo()
const tid = localStorage.getItem('tid') const tid = localStorage.getItem('tid')
approveKakaopay(tid) approveKakaopay(tid)
if (user.role === "member") {
saveUserReservation()
} else {
saveGuestReservation()
}
} }
}, [user]) }, [user])
async function getGuestInfo() { async function saveGuestReservation() {
try { try {
if (user.id > 0) {
const response = await axios.get(`/api/auth/guestinfo/${user.id}`); const response = await axios.get(`/api/auth/guestinfo/${user.id}`);
const guest = { // const response2 = await reservationApi.save({
userType: "guest", // userType: "guest",
user: user.id // user: user.id,
}; // ...paymentData,
const response2 = await reservationApi.findOneReservation(guest); // timetableId: 1
console.log({ // })
reservationData: [...response2.data], // if (response.data) {
userData: { ...response.data }, // const responseEmail = await axios.post('/api/email/send', {
}) // reservationData: [...response2.data],
if (response.data || response2.data) { // userData: { ...response.data },
const responseEmail = await axios.post('/api/email/send', { // cinema: "Butter Studio 조치원",
reservationData: [...response2.data], // title: "더 수어사이드 스쿼드",
userData: { ...response.data }, // theater: "1",
cinema: "Butter Studio 조치원", // time: "2021/07/21 10:00"
title: "더 수어사이드 스쿼드", // })
theater: "1", // console.log(responseEmail.data)
time: "2021/07/21 10:00" // }
})
console.log(responseEmail.data)
}
console.log(response.data) console.log(response.data)
}
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
} }
async function getUserInfo() { async function saveUserReservation() {
try { try {
const response = await axios.post(`/api/auth/getuserinfo`, { const response = await axios.post(`/api/auth/getuserinfo`, {
id: user.id id: user.id
}) })
const member = {
userType: "member",
user: user.id
}
const response2 = await reservationApi.findOneReservation(member);
console.log(response2.data)
if (response.data || response2.data) {
const responseEmail = await axios.post('/api/email/send', {
...response2.data,
...response.data,
}) // if (response.data) {
console.log(responseEmail.data) // const responseEmail = await axios.post('/api/email/send', {
} // ...response2.data,
// ...response.data,
// })
// console.log(responseEmail.data)
// }
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
} }
async function approveKakaopay(tid) { async function approveKakaopay(tid) {
try {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const pg_token = urlParams.get('pg_token'); const pg_token = urlParams.get('pg_token');
try {
if (user.id > 0) {
console.log(user.id)
const response = await axios.post(`/api/kakaopay/success`, { const response = await axios.post(`/api/kakaopay/success`, {
'tid': tid, 'tid': tid,
cid: 'TC0ONETIME', cid: 'TC0ONETIME',
...@@ -89,8 +79,7 @@ const PaymentCompletePage = () => { ...@@ -89,8 +79,7 @@ const PaymentCompletePage = () => {
partner_user_id: '000000' + user.id, partner_user_id: '000000' + user.id,
pg_token: pg_token pg_token: pg_token
}) })
console.log(response.data) setPaymentData(response.data)
}
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
} }
......
import axios from 'axios' import axios from 'axios'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import authApi from '../../apis/auth.api'
import reservationApi from '../../apis/reservation.api' import reservationApi from '../../apis/reservation.api'
import { useAuth } from '../../context/auth_context' import { useAuth } from '../../context/auth_context'
import catchErrors from '../../utils/catchErrors' import catchErrors from '../../utils/catchErrors'
...@@ -46,10 +47,10 @@ const Payment = ({ location }) => { ...@@ -46,10 +47,10 @@ const Payment = ({ location }) => {
async function handleClickGuest() { async function handleClickGuest() {
try { try {
const response = await reservationApi.save({ const response = await authApi.saveGuestInfo({
...guestInfo ...guestInfo
}); });
setGuestID(response.data.id); setGuestID(response.id);
alert("비회원 정보가 저장되었습니다."); alert("비회원 정보가 저장되었습니다.");
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
...@@ -71,7 +72,6 @@ const Payment = ({ location }) => { ...@@ -71,7 +72,6 @@ const Payment = ({ location }) => {
if (user.role === "member") { if (user.role === "member") {
const response = await reservationApi.save({ const response = await reservationApi.save({
userType: "member", userType: "member",
// payment: "카카오페이",
user: userInfo.id, user: userInfo.id,
...ticketInfo, ...ticketInfo,
timetable: 1 timetable: 1
...@@ -98,14 +98,14 @@ const Payment = ({ location }) => { ...@@ -98,14 +98,14 @@ const Payment = ({ location }) => {
userType: "guest", userType: "guest",
user: guestID, user: guestID,
...ticketInfo, ...ticketInfo,
// payment: "카카오페이", timetableId: 1
timetable: 1
}) })
const responsekakao = await axios.post('/api/kakaopay/test/single', { const responsekakao = await axios.post('/api/kakaopay/test/single', {
cid: 'TC0ONETIME', cid: 'TC0ONETIME',
partner_order_id: 'butter_studio', partner_order_id: 'butter_studio',
partner_user_id: '000000'+ guestID, partner_user_id: '000000'+ guestID,
item_name: ticketInfo.title, item_name: ticketInfo.title,
item_code: ticketInfo.movieId,
quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior, quantity: ticketInfo.adult + ticketInfo.youth + ticketInfo.senior,
total_amount: ticketInfo.totalFee, total_amount: ticketInfo.totalFee,
vat_amount: 0, vat_amount: 0,
...@@ -114,7 +114,7 @@ const Payment = ({ location }) => { ...@@ -114,7 +114,7 @@ const Payment = ({ location }) => {
fail_url: 'http://localhost:3000/ticket', fail_url: 'http://localhost:3000/ticket',
cancel_url: 'http://localhost:3000/ticket', cancel_url: 'http://localhost:3000/ticket',
}) })
if (response && responsekakao) { if (responsekakao) {
localStorage.setItem('tid',responsekakao.data.tid) localStorage.setItem('tid',responsekakao.data.tid)
window.location.href = responsekakao.data.redirect_url window.location.href = responsekakao.data.redirect_url
} }
...@@ -187,7 +187,7 @@ const Payment = ({ location }) => { ...@@ -187,7 +187,7 @@ const Payment = ({ location }) => {
</div> </div>
<div className="my-1"> <div className="my-1">
<label className={styles.labelStyle}>비밀번호</label> <label className={styles.labelStyle}>비밀번호</label>
<input type="password" name="guestPassword" placeholder="비밀번호" onChange={handleChangeGuest} required style={{ width: "178px" }} /> <input type="password" name="password" placeholder="비밀번호" onChange={handleChangeGuest} required style={{ width: "178px" }} />
</div> </div>
<div className="m-2"> <div className="m-2">
<p className={`text-muted ${styles.warningText}`}> <p className={`text-muted ${styles.warningText}`}>
......
...@@ -40,12 +40,10 @@ const TicketingSeatPage = ({ location }) => { ...@@ -40,12 +40,10 @@ const TicketingSeatPage = ({ location }) => {
async function getInfo() { async function getInfo() {
try { try {
const response = await axios.post('/api/theater/getInfo', { const response = await axios.post('/api/theater/getInfo', {
theaterName: ticketInfo.selectedTheater theaterId: ticketInfo.selectedTheater
}) })
setTheaterInfo(response.data) setTheaterInfo(response.data)
const response2 = await reservationApi.findReservedSeats({ const response2 = await reservationApi.findReservedSeats(1);
timetable: 1
});
const reserve = response2.data.map((el) => const reserve = response2.data.map((el) =>
el.row + '-' + el.col el.row + '-' + el.col
); );
......
...@@ -4,10 +4,11 @@ import config from '../config/app.config.js' ...@@ -4,10 +4,11 @@ import config from '../config/app.config.js'
const findReservedSeats = async (req, res) => { const findReservedSeats = async (req, res) => {
try { try {
const { timetable } = req.body const { timeTable } = req.body
console.log("타임테이블===============",timeTable)
const reservedSeats = await Reservation.findAll({ const reservedSeats = await Reservation.findAll({
where: { where: {
timetable: timetable timetableId: timeTable
} }
}) })
res.json(reservedSeats) res.json(reservedSeats)
...@@ -49,10 +50,10 @@ const findOneReservation = async (req, res, next) => { ...@@ -49,10 +50,10 @@ const findOneReservation = async (req, res, next) => {
} }
} }
const saveReservation = async (req, res) => { const saveReservation = async (req, res) => {
try {
const { movieId, selectedTheater, timetable, payment, user, userType, totalFee } = req.body const { movieId, selectedTheater, timetable, payment, user, userType, totalFee } = req.body
const rows = req.body.selectedSeats.map(el => el.split('-')[0]) const rows = req.body.selectedSeats.map(el => el.split('-')[0])
const cols = req.body.selectedSeats.map(el => el.split('-')[1]) const cols = req.body.selectedSeats.map(el => el.split('-')[1])
try {
for (let index = 0; index < rows.length; index++) { for (let index = 0; index < rows.length; index++) {
const reservation = await Reservation.create({ const reservation = await Reservation.create({
user: user, user: user,
...@@ -63,7 +64,7 @@ const saveReservation = async (req, res) => { ...@@ -63,7 +64,7 @@ const saveReservation = async (req, res) => {
col: cols[index], col: cols[index],
timetableId: timetable, timetableId: timetable,
payment: payment, payment: payment,
totalFee: totalFee totalFee: totalFee,
}) })
} }
const movie = await Movie.findOne({ const movie = await Movie.findOne({
......
import { Theater, TheaterType } from "../db/index.js"; import { Theater, TheaterType } from "../db/index.js";
const getTheaterInfo = async (req, res) => { const getTheaterInfo = async (req, res) => {
const { theaterName } = req.body
try { try {
const { theaterId } = req.body
const theaterInfo = await Theater.findOne({ const theaterInfo = await Theater.findOne({
where: { theaterName: String(theaterName) }, where: { id: theaterId },
attributes: ['theaterName', 'rows', 'columns'] attributes: ['theaterName', 'rows', 'columns']
}) })
// console.log("theaterInfo====",theaterInfo) // console.log("theaterInfo====",theaterInfo)
......
...@@ -461,16 +461,17 @@ const getUserInfo = async (req, res) => { ...@@ -461,16 +461,17 @@ const getUserInfo = async (req, res) => {
} }
const saveGuestInfo = async (req, res) => { const saveGuestInfo = async (req, res) => {
const { name, email, birth, phoneNumber, password } = req.body
try { try {
const { name, email, birth, phoneNumber, password } = req.body
const newGuest = await Guest.create({ const newGuest = await Guest.create({
name: name, name: name,
email: email, email: email,
birth: birth, birth: birth,
phoneNumber: phoneNumber, phoneNumber: phoneNumber,
password: password, password: password,
roleId:1
}); });
// console.log(newGuest) console.log(newGuest)
res.clearCookie(config.cookieName); res.clearCookie(config.cookieName);
const token = jwt.sign({id: newGuest.id, role: "user"}, config.jwtSecret, { const token = jwt.sign({id: newGuest.id, role: "user"}, config.jwtSecret, {
expiresIn: config.jwtExpires, expiresIn: config.jwtExpires,
......
...@@ -10,7 +10,7 @@ dotenv.config({ ...@@ -10,7 +10,7 @@ dotenv.config({
}); });
sequelize sequelize
.sync({ force: false}) .sync({ force: false })
.then(async () => { .then(async () => {
await Promise.all( await Promise.all(
Object.keys(ROLE_NAME).map((name) => { Object.keys(ROLE_NAME).map((name) => {
...@@ -32,7 +32,7 @@ sequelize ...@@ -32,7 +32,7 @@ sequelize
img: "970aaa79673a39331d45d4b55ca05d25", img: "970aaa79673a39331d45d4b55ca05d25",
roleId: adminRole?.id, roleId: adminRole?.id,
}); });
} else {} } else { }
app.listen(appConfig.port, () => { app.listen(appConfig.port, () => {
console.log(`Server is running on port ${appConfig.port}`); console.log(`Server is running on port ${appConfig.port}`);
......
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