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

오류수정

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