diff --git a/client/package-lock.json b/client/package-lock.json
index 57c573795..47862a988 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -19,6 +19,7 @@
"@testing-library/user-event": "^13.5.0",
"aws-sdk": "^2.1130.0",
"axios": "^0.26.1",
+ "qs": "^6.10.3",
"react": "^18.0.0",
"react-aws-s3": "^1.5.0",
"react-dom": "^18.0.0",
@@ -15062,14 +15063,6 @@
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz",
"integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg=="
},
- "node_modules/react-intersection-observer": {
- "version": "9.1.0",
- "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.1.0.tgz",
- "integrity": "sha512-XSDWQGzgJ4/B4eW39+qa3S+uc4Gb+m6lxXR54m/uD5lqeL5sLrgYdntbjl4BlTYAblgUhz+JB5obINhZaD+c0Q==",
- "peerDependencies": {
- "react": "^15.0.0 || ^16.0.0 || ^17.0.0|| ^18.0.0"
- }
- },
"node_modules/react-is": {
"version": "18.0.0",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz",
@@ -32159,12 +32152,6 @@
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz",
"integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg=="
},
- "react-intersection-observer": {
- "version": "9.1.0",
- "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.1.0.tgz",
- "integrity": "sha512-XSDWQGzgJ4/B4eW39+qa3S+uc4Gb+m6lxXR54m/uD5lqeL5sLrgYdntbjl4BlTYAblgUhz+JB5obINhZaD+c0Q==",
- "requires": {}
- },
"react-is": {
"version": "18.0.0",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.0.0.tgz",
diff --git a/client/package.json b/client/package.json
index ddb1a0633..45a50a380 100644
--- a/client/package.json
+++ b/client/package.json
@@ -14,6 +14,7 @@
"@testing-library/user-event": "^13.5.0",
"aws-sdk": "^2.1130.0",
"axios": "^0.26.1",
+ "qs": "^6.10.3",
"react": "^18.0.0",
"react-aws-s3": "^1.5.0",
"react-dom": "^18.0.0",
diff --git a/client/src/component/MypageCompo/FreeWriting.js b/client/src/component/MypageCompo/FreeWriting.js
index 396649201..d3a571af0 100644
--- a/client/src/component/MypageCompo/FreeWriting.js
+++ b/client/src/component/MypageCompo/FreeWriting.js
@@ -80,6 +80,13 @@ const WritingContainer = styled.div`
}
`;
+const Btn = styled.button`
+ &.need {
+ display: none;
+ color: red;
+ }
+`;
+
function Writing() {
const { id, accToken } = useSelector(selectUserInfo);
const config = {
@@ -162,10 +169,11 @@ function Writing() {
)
.then((res) => {
setTextValues({
- title: null,
- content: null,
+ title: '',
+ content: '',
});
- setSelectedFile(null);
+ setSelectedFile('');
+ fileInput.current.value = '';
if (res.data.infoId) alert('글이 등록되었습니다.');
})
.catch((err) => {
@@ -210,7 +218,7 @@ function Writing() {
rows="1"
cols="55"
placeholder="제목"
- maxlength="100"
+ maxlength="100" //삭제?
value={textValues.title}
onChange={(e) =>
setTextValues({ ...textValues, title: e.target.value })
@@ -232,7 +240,9 @@ function Writing() {
onChange={handleInputChange}
ref={fileInput}
/>
-
+
+ 파일 취소
+
{
axios
- .get(`${process.env.REACT_APP_SERVER_DEV_URL}/users/${id}`, getConfig)
+ .get(
+ `${process.env.REACT_APP_SERVER_DEV_URL}/users/userInfo/${id}`,
+ getConfig,
+ )
.then((res) => {
const { user } = res.data;
if (user) {
@@ -278,26 +281,20 @@ function UserInfo() {
myBucket
.putObject(params, (err, data) => {
//서버로 profileImg 값 보내주기.(일단 임시로 작성)
- // axios
- // .post(
- // `${process.env.REACT_APP_SERVER_DEV_URL}/users/${id}/img`,
- // { profileImg: fileName },
- // postConfig,
- // )
- // .then((res) => {
- // dispatch(
- // updateState({
- // profileImg: fileName,
- // }),
- // );
- // })
- // .catch((err) => alert('파일업로드 주소가 서버에 반영 안 됨.'));
- //아래 코드는 서버랑 연동되면 삭제
- dispatch(
- updateState({
- profileImg: fileName,
- }),
- );
+ axios
+ .post(
+ `${process.env.REACT_APP_SERVER_DEV_URL}/users/${id}/img`,
+ { profileImg: fileName },
+ postConfig,
+ )
+ .then((res) => {
+ dispatch(
+ updateState({
+ profileImg: fileName,
+ }),
+ );
+ })
+ .catch((err) => alert('파일업로드 주소가 서버에 반영 안 됨.'));
})
.on('httpUploadProgress', (evt) => {
dispatch(
diff --git a/client/src/component/Search.js b/client/src/component/Search.js
index 72d621e9c..fe51dfab3 100644
--- a/client/src/component/Search.js
+++ b/client/src/component/Search.js
@@ -3,8 +3,8 @@ import React, { useRef, useState, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons';
-import { selectSearch, updateSearch } from '../store/slices/search';
-import { useNavigate } from 'react-router-dom';
+import { useNavigate, useLocation } from 'react-router-dom';
+import QueryString from 'qs';
const boxShadow = '0 4px 6px rgb(32 33 36 / 28%)';
// const activeBorderRadius = '1rem 1rem 0 0';
@@ -83,32 +83,9 @@ export const InputContainer = styled.div`
} */
`;
-function SelectBox({ items, className, role }) {
- const dispatch = useDispatch();
- const { selectBox1, selectBox2 } = useSelector(selectSearch);
-
- const handleSelect = (e) => {
- if (role === 'first') {
- dispatch(
- updateSearch({
- selectBox1: e.target.value,
- }),
- );
- } else {
- dispatch(
- updateSearch({
- selectBox2: e.target.value,
- }),
- );
- }
- };
-
+function SelectBox({ items, className, selectVal, handleSelect }) {
return (
-
diff --git a/client/src/pages/user/Mainpage.js b/client/src/pages/user/Mainpage.js
index d908dbbbd..b37d3bc2d 100644
--- a/client/src/pages/user/Mainpage.js
+++ b/client/src/pages/user/Mainpage.js
@@ -64,7 +64,7 @@ function Post({ post, order }) {
const { id: postId, title, nickname, userId } = post;
const handleClick = () => {
- navigate(`main/search/${postId}`);
+ navigate(`/main/search/${postId}`);
};
return (
@@ -89,7 +89,6 @@ function List({ posts, className }) {
}
function Mainpage() {
- const { posts } = freeBoardData; //임시
const { accToken } = useSelector(selectUserInfo);
const [list, setList] = useState([]);
diff --git a/client/src/pages/user/Post.js b/client/src/pages/user/Post.js
index ea2d8d740..2d5c548b1 100644
--- a/client/src/pages/user/Post.js
+++ b/client/src/pages/user/Post.js
@@ -39,7 +39,6 @@ function Post() {
reviews: [...info.Replies],
}),
);
- //조회수는 애초에 get 요청 보내질 때 서버에서 조회수 1 더하고 응답하는 걸로...
})
.catch((err) => {
alert('게시물을 불러올 수 없습니다.');
diff --git a/client/src/pages/user/PostList.js b/client/src/pages/user/PostList.js
index 5023694a6..0ca66cc92 100644
--- a/client/src/pages/user/PostList.js
+++ b/client/src/pages/user/PostList.js
@@ -5,7 +5,8 @@ import Pagination from '../../component/Pagination';
import { useSelector, useDispatch } from 'react-redux';
import { selectUserInfo } from '../../store/slices/userInfo';
import { updateSearch, selectSearch } from '../../store/slices/search';
-import { useNavigate } from 'react-router-dom';
+import { useNavigate, useLocation } from 'react-router-dom';
+import QueryString from 'qs';
import axios from 'axios';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faThumbsUp } from '@fortawesome/free-regular-svg-icons';
@@ -77,9 +78,16 @@ function Post({ post }) {
function PostList() {
const dispatch = useDispatch();
const navigate = useNavigate();
+ const location = useLocation();
+ const { search_type, info_type, input_value } = QueryString.parse(
+ location.search,
+ {
+ ignoreQueryPrefix: true,
+ },
+ );
+
const { accToken } = useSelector(selectUserInfo);
- const { inputVal, selectBox1, selectBox2, page, list, totalPage } =
- useSelector(selectSearch);
+ const { page, list } = useSelector(selectSearch);
const getConfig = {
headers: {
@@ -94,13 +102,15 @@ function PostList() {
useEffect(() => {
//아래 코드는 그때 그때 다시 받지 않게 함.
if (list.length > offset) return;
+ const select1 = search_type || 'title';
+ const select2 = info_type || 'All';
const params = {
- search_type: selectBox1,
- info_type: selectBox2,
+ search_type: select1,
+ info_type: select2,
pages: page,
limit: LIMIT,
- [selectBox1]: inputVal,
+ [select1]: input_value,
};
axios
@@ -110,9 +120,11 @@ function PostList() {
})
.then((res) => {
const { count, rows } = res.data.info;
+ console.log('검색 결과', res.data);
if (count && page === 1) {
const totalPage = Math.ceil(Number(count) / LIMIT);
const totalMark = Math.ceil(totalPage / 10);
+
dispatch(
updateSearch({
totalCount: count,
@@ -124,8 +136,8 @@ function PostList() {
if (rows) dispatch(updateSearch({ list: [...rows] }));
})
.catch((err) => {
- alert(err.response.message);
- navigate(-1);
+ console.log('###', err);
+ // navigate(-1);
});
}, [page]);
diff --git a/client/src/store/slices/search.js b/client/src/store/slices/search.js
index be284d3a9..6def01b4d 100644
--- a/client/src/store/slices/search.js
+++ b/client/src/store/slices/search.js
@@ -1,9 +1,6 @@
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
- inputVal: null,
- selectBox1: 'title',
- selectBox2: 'All',
page: 1,
mark: 1,
totalCount: null, //삭제?
diff --git a/server/src/app.ts b/server/src/app.ts
index 178e2b028..a18023f11 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -6,8 +6,8 @@ import dotenv from 'dotenv';
import cookieParser from 'cookie-parser';
const indexRouter = require('./routes/index');
import { sequelize } from './models';
-import passport from 'passport';
-const passportConfig = require('./passport/index');
+// import passport from 'passport';
+// const passportConfig = require('./passport/index');
dotenv.config();
diff --git a/server/src/config/config.js b/server/src/config/config.js
index 48d34b7e7..8c37d03a3 100644
--- a/server/src/config/config.js
+++ b/server/src/config/config.js
@@ -36,7 +36,7 @@ dotenv.config({ path: '../../.env' });
module.exports = {
development: {
username: process.env.username || 'root',
- password: process.env.password || '0905',
+ password: process.env.password || '3837',
database: process.env.database || 'info_market',
host: '127.0.0.1',
port: 3306,
diff --git a/server/src/controlloers/info.ts b/server/src/controlloers/info.ts
index 5b8b82f6c..2d5e63433 100644
--- a/server/src/controlloers/info.ts
+++ b/server/src/controlloers/info.ts
@@ -1,6 +1,7 @@
import Info from '../models/info';
import { Request, Response } from 'express';
import * as infoDb from '../db/info';
+import * as paymentDb from '../db/payment';
import * as likeDb from '../db/like';
module.exports = {
@@ -24,6 +25,19 @@ module.exports = {
await infoDb.viewsAdd(info.id, Number(info.totalViews));
+ let isPurchased;
+
+ const checkPay = await paymentDb.getUserPayment(
+ Number(infoId),
+ Number(req.userId),
+ );
+
+ if (!checkPay) {
+ isPurchased = false;
+ } else {
+ isPurchased = true;
+ }
+
return res.status(200).json({
info,
like: like ? true : false,
@@ -173,11 +187,13 @@ module.exports = {
await infoDb.editInfoFile(Number(infoId), req.body.file);
},
+
getFreeInfo: async (req: Request, res: Response) => {
let { pages, limit, like_type } = req.query;
let cursor: number;
let like;
+ console.log(req.query.lastId);
if (!req.query.lastId) {
cursor = await Info.count();
@@ -207,6 +223,7 @@ module.exports = {
message: `${pages} 번 페이지 게시물들을 불러왔습니다.`,
});
},
+
getPaidInfo: async (req: Request, res: Response) => {
let { pages, limit, like_type } = req.query;
const activate = true;
diff --git a/server/src/controlloers/point.ts b/server/src/controlloers/point.ts
index 3c3b8e553..f5198028d 100644
--- a/server/src/controlloers/point.ts
+++ b/server/src/controlloers/point.ts
@@ -3,6 +3,7 @@ import * as pointDb from '../db/point';
import axios from 'axios';
import { config } from '../config';
import * as userDb from '../db/user';
+import * as pointRefundDb from '../db/pointRefund';
module.exports = {
getToken: async (req: Request, res: Response) => {
@@ -111,5 +112,123 @@ module.exports = {
return res.status(400).json({ message: '위조된 결제시도가 있습니다.' });
}
},
- cancel: async (req: Request, res: Response) => {},
+ cancel: async (req: Request, res: Response) => {
+ const imp_key = config.imp.imp_key;
+
+ const imp_secret = config.imp.imp_secret;
+ const url: string = 'https://api.iamport.kr/users/getToken';
+ const { userId } = req;
+
+ const user = await userDb.findPkUser(Number(userId));
+
+ if (!user) {
+ return res.status(403).json({ message: '유저가 존재하지 않습니다.' });
+ }
+
+ if (!req.body.merchant_uid) {
+ return res.status(400).json({ message: '주문 번호를 받지 못했습니다.' });
+ }
+
+ const response: any = await axios
+ .post(
+ url,
+ {
+ imp_key,
+ imp_secret,
+ },
+ {
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ },
+ )
+ .catch((err) => {
+ return res
+ .status(400)
+ .json({ message: 'iamport 토큰을 받아오는데 실패하였습니다.' });
+ });
+
+ const imp_token: string = response.data.response.access_token;
+
+ const payment = await pointDb.findUserChargePoint(
+ Number(req.userId),
+ req.body.merchant_uid,
+ );
+
+ if (!payment) {
+ return res
+ .status(406)
+ .json({ message: '포인트를 결제한 내역이 없습니다.' });
+ }
+
+ const paymentData = payment;
+
+ const { merchant_uid, reason, cancel_point } = req.body;
+
+ const cancelablePoint = paymentData.point - cancel_point;
+
+ if (cancelablePoint < 0) {
+ return res
+ .status(400)
+ .json({ message: '환불할 금액이 구매한 금액 보다 큽니다.' });
+ }
+
+ const getCancelData = await axios
+ .post(
+ 'https://api.iamport.kr/payments/cancel',
+ {
+ reason,
+ imp_uid: paymentData.imp_uid,
+ amount: cancel_point,
+ checksum: cancelablePoint,
+ },
+ {
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: imp_token,
+ },
+ },
+ )
+ .catch((err) => {
+ return res.status(400).json({ message: '환불 하는데 실패하였습니다.' });
+ });
+
+ const { responses } = getCancelData.data;
+
+ if (cancelablePoint === 0) {
+ await pointDb.removePoint(
+ Number(req.userId),
+ paymentData.merchant_uid,
+ paymentData.imp_uid,
+ );
+ const pointRefund = await pointRefundDb.createPointRefund(
+ paymentData.imp_uid,
+ merchant_uid,
+ Number(req.userId),
+ cancel_point,
+ reason,
+ 'AllRefund',
+ );
+ } else {
+ await pointDb.partPointRefund(
+ Number(req.userId),
+ paymentData.merchant_uid,
+ paymentData.imp_uid,
+ cancelablePoint,
+ );
+ const pointRefund = await pointRefundDb.createPointRefund(
+ paymentData.imp_uid,
+ merchant_uid,
+ Number(req.userId),
+ cancel_point,
+ reason,
+ 'PartRefund',
+ );
+ }
+
+ return res
+ .status(200)
+ .json({ result: responses, message: '환불 하는데 성공하였습니다.' });
+ },
};
diff --git a/server/src/controlloers/search.ts b/server/src/controlloers/search.ts
index 3438e57e3..4fabd9538 100644
--- a/server/src/controlloers/search.ts
+++ b/server/src/controlloers/search.ts
@@ -2,6 +2,7 @@ import { Request, Response } from 'express';
import * as searchDb from '../db/search';
module.exports = {
+ // 무한 스크롤
get: async (req: Request, res: Response) => {
const { search_type, info_type, pages, limit, like_type } = req.query;
let like;
@@ -13,15 +14,15 @@ module.exports = {
}
if (search_type === 'titles') {
- const { titles } = req.query;
+ const { title } = req.query;
- if (!titles) {
+ if (!title) {
return res.status(400).json({ message: '제목을 입력해 주세요.' });
}
if (info_type === 'All') {
const findInfoBy = await searchDb.searchAllTitle(
- String(titles),
+ String(title),
Number(pages),
Number(limit),
String(like),
@@ -36,7 +37,7 @@ module.exports = {
.json({ info: findInfoBy, message: '해당 게시물을 불러왔습니다.' });
} else {
const findInfoBy = await searchDb.searchByTitle(
- String(titles),
+ String(title),
Number(pages),
Number(limit),
String(info_type),
diff --git a/server/src/controlloers/users.ts b/server/src/controlloers/users.ts
index 9eac2fa72..ddb828d0b 100644
--- a/server/src/controlloers/users.ts
+++ b/server/src/controlloers/users.ts
@@ -3,6 +3,8 @@ import { Request, Response } from 'express';
const bcrypt = require('./functions/bcrypt');
import * as infoDb from '../db/info';
import * as paymentDb from '../db/payment';
+import * as pointDb from '../db/point';
+import * as pointRefundDb from '../db/pointRefund';
module.exports = {
getUsersInfo: async (req: Request, res: Response) => {
@@ -38,26 +40,39 @@ module.exports = {
.json({ message: '해당 유저가 존재하지 않습니다.' });
}
- const { email, nickname, phone, password } = req.body;
+ let email: string;
+ let password: string;
+ let phone: string;
+ let nickname: string;
- const editInfo = await userDb.findUser(email);
-
- if (editInfo) {
- return res.status(400).json({ message: '중복된 email 입니다.' });
+ if (req.body.email) {
+ email = req.body.email;
+ } else {
+ email = user.email;
}
- const findNickname = await userDb.checkNickname(nickname);
+ if (req.body.password) {
+ password = await bcrypt.hash(req.body.password).catch((err: Error) => {
+ console.log(err);
+ });
+ } else {
+ password = user.password;
+ }
- if (findNickname) {
- return res.status(400).json({ message: '중복된 닉네임 입니다.' });
+ if (req.body.phone) {
+ phone = req.body.phone;
+ } else {
+ phone = user.phone;
}
- const hashPw = await bcrypt.hash(password).catch((err: Error) => {
- console.log(err);
- });
+ if (req.body.nickname) {
+ nickname = req.body.nickname;
+ } else {
+ nickname = user.nickname;
+ }
await userDb
- .editUserInfo(Number(userId), email, hashPw, nickname, phone)
+ .editUserInfo(Number(userId), email, password, nickname, phone)
.catch(() => {
return res
.status(400)
@@ -71,19 +86,13 @@ module.exports = {
const { pages, limit } = req.query;
const { userId } = req;
- console.log('userId : ', userId);
+ // console.log('userId : ', userId);
const info = await infoDb.getMyInfos(
Number(pages),
Number(limit),
Number(userId),
);
- // .catch(() => {
- // return res
- // .status(400)
- // .json({ message: '게시물을 불러오는데 실패하였습니다.' });
- // });
- console.log(info);
if (info.count === 0) {
return res
@@ -146,4 +155,61 @@ module.exports = {
.status(200)
.json({ message: '이미지를 업로드 하는데 성공하였습니다.' });
},
+ checkNickname: async (req: Request, res: Response) => {
+ const findNickname = await userDb.checkNickname(req.body.nickname);
+
+ if (findNickname) {
+ return res.status(400).json({ message: '중복된 닉네임 입니다.' });
+ }
+
+ return res.status(200).json({ message: '사용할 수 있는 닉네임 입니다.' });
+ },
+ paidPoint: async (req: Request, res: Response) => {
+ const { userId } = req.params;
+
+ if (userId != req.userId) {
+ return res.status(403).json({ message: '유저가 일치하지 않습니다.' });
+ }
+
+ const user = await userDb.findPkUser(Number(userId));
+
+ if (!user) {
+ return res
+ .status(406)
+ .json({ message: '해당 유저가 존재하지 않습니다.' });
+ }
+
+ const paidPoint = await pointDb.findUserPaidbyUserId(Number(userId));
+
+ if (!paidPoint) {
+ return res
+ .status(406)
+ .json({ message: '포인트를 충전한 내역이 없습니다.' });
+ }
+
+ return res
+ .status(200)
+ .json({ paidPoint, message: '포인트 충전 내역을 불러왔습니다.' });
+ },
+ checkEmail: async (req: Request, res: Response) => {
+ const editInfo = await userDb.findUser(req.body.email);
+
+ if (editInfo) {
+ return res.status(400).json({ message: '중복된 Email 입니다.' });
+ }
+
+ return res.status(200).json({ message: '사용할 수 있는 Email 입니다.' });
+ },
+ getRefundPoint: async (req: Request, res: Response) => {
+ const refundPoint = await pointRefundDb.findRefund(Number(req.userId));
+
+ if (!refundPoint) {
+ return res.status(406).json({ message: '포인트 환불 내역이 없습니다.' });
+ }
+
+ return res.status(200).json({
+ refund: refundPoint,
+ message: '포인트 환불 내역을 불러왔습니다.',
+ });
+ },
};
diff --git a/server/src/db/info.ts b/server/src/db/info.ts
index c9419fbdf..50a50e501 100644
--- a/server/src/db/info.ts
+++ b/server/src/db/info.ts
@@ -16,6 +16,7 @@ export async function getInfo(infoId: number) {
'createdAt',
'targetPoint',
'type',
+ 'file',
'totalViews',
'totalLikes',
],
@@ -53,6 +54,8 @@ export async function getInfos() {
'targetPoint',
'activate',
'type',
+ 'totalViews',
+ 'totalLikes',
],
include: [
{
@@ -83,6 +86,8 @@ export async function AdminGetInfo(
'targetPoint',
'activate',
'type',
+ 'totalViews',
+ 'totalLikes',
],
include: [
{
@@ -114,6 +119,8 @@ export async function getMyInfos(pages: number, limit: number, userId: number) {
'updatedAt',
'targetPoint',
'type',
+ 'totalViews',
+ 'totalLikes',
],
include: [
{
diff --git a/server/src/db/payment.ts b/server/src/db/payment.ts
index 46715ed59..d959397b3 100644
--- a/server/src/db/payment.ts
+++ b/server/src/db/payment.ts
@@ -99,3 +99,12 @@ export async function getPayments(
],
});
}
+
+export async function getUserPayment(infoId: number, userId: number) {
+ return await Payment.findOne({
+ where: {
+ userId,
+ infoId,
+ },
+ });
+}
diff --git a/server/src/db/point.ts b/server/src/db/point.ts
index 141cf5069..4b884a410 100644
--- a/server/src/db/point.ts
+++ b/server/src/db/point.ts
@@ -1,4 +1,6 @@
import Point from '../models/point';
+import { Sequelize, Op, where } from 'sequelize';
+import User from '../models/user';
export async function createPoint(
imp_uid: string,
@@ -27,6 +29,21 @@ export async function findUserChargePoint(
userId,
merchant_uid,
},
+ attributes: [
+ 'point',
+ 'merchant_uid',
+ 'imp_uid',
+ 'payment_method_type',
+ 'createdAt',
+ 'state',
+ [Sequelize.col('User.nickname'), 'nickname'],
+ ],
+ include: [
+ {
+ model: User,
+ attributes: [],
+ },
+ ],
});
}
@@ -43,6 +60,40 @@ export async function editPoint(tid: string) {
);
}
+export async function removePoint(
+ userId: number,
+ merchant_uid: string,
+ imp_uid: string,
+) {
+ return await Point.destroy({
+ where: {
+ userId,
+ merchant_uid,
+ imp_uid,
+ },
+ });
+}
+
+export async function partPointRefund(
+ userId: number,
+ merchant_uid: string,
+ imp_uid: string,
+ cancel_point: number,
+) {
+ return await Point.update(
+ {
+ point: cancel_point,
+ },
+ {
+ where: {
+ userId,
+ merchant_uid,
+ imp_uid,
+ },
+ },
+ );
+}
+
// export async function findAndUpdate(
// imp_uid: string,
// state: string,
@@ -56,3 +107,25 @@ export async function editPoint(tid: string) {
// state: '',
// });
// }
+
+export async function findUserPaidbyUserId(userId: number) {
+ return await Point.findAll({
+ where: {
+ userId,
+ },
+ attributes: [
+ 'id',
+ 'state',
+ 'point',
+ [Sequelize.col('User.nickname'), 'nickname'],
+ 'createdAt',
+ 'merchant_uid',
+ 'imp_uid',
+ 'payment_method_type',
+ ],
+ include: {
+ model: User,
+ attributes: [],
+ },
+ });
+}
diff --git a/server/src/db/pointRefund.ts b/server/src/db/pointRefund.ts
new file mode 100644
index 000000000..428d1a96b
--- /dev/null
+++ b/server/src/db/pointRefund.ts
@@ -0,0 +1,30 @@
+import Point from '../models/point';
+import { Sequelize, Op, where } from 'sequelize';
+import User from '../models/user';
+import PointRefund from '../models/pointRefund';
+
+export async function createPointRefund(
+ imp_uid: string,
+ merchant_uid: string,
+ userId: number,
+ cancel_point: number,
+ reason: string,
+ state: string,
+) {
+ return await PointRefund.create({
+ userId,
+ reason,
+ merchant_uid,
+ imp_uid,
+ cancel_point,
+ state,
+ });
+}
+
+export async function findRefund(userId: number) {
+ return await PointRefund.findAll({
+ where: {
+ userId,
+ },
+ });
+}
diff --git a/server/src/migrations/create-table/8.create-table-pointRefund.ts b/server/src/migrations/create-table/8.create-table-pointRefund.ts
new file mode 100644
index 000000000..75341f43b
--- /dev/null
+++ b/server/src/migrations/create-table/8.create-table-pointRefund.ts
@@ -0,0 +1,14 @@
+import PointRefund from '../../models/pointRefund';
+
+console.log('======Create Table======');
+const create_table_pointRefund = async () => {
+ await PointRefund.sync({ force: true })
+ .then(() => {
+ console.log('✅Success Create Table');
+ })
+ .catch((err: Error) => {
+ console.log('❗️Error in Create users Table : ', err);
+ });
+};
+
+create_table_pointRefund();
diff --git a/server/src/models/index.ts b/server/src/models/index.ts
index fdc0ef725..d246fd60b 100644
--- a/server/src/models/index.ts
+++ b/server/src/models/index.ts
@@ -5,6 +5,7 @@ import Payment, { associate as associatePayment } from './payment';
import Reply, { associate as associateReply } from './reply';
import Like, { associate as associateLike } from './like';
import Point, { associate as associatePoint } from './point';
+import PointRefund, { associate as associatePointRefund } from './pointRefund';
export * from './sequelize';
const db = {
@@ -15,6 +16,7 @@ const db = {
Reply,
Like,
Point,
+ PointRefund,
};
export type dbType = typeof db;
@@ -25,3 +27,4 @@ associatePayment(db);
associateReply(db);
associateLike(db);
associatePoint(db);
+associatePointRefund(db);
diff --git a/server/src/models/point.ts b/server/src/models/point.ts
index 474b487ef..06cb7c0b0 100644
--- a/server/src/models/point.ts
+++ b/server/src/models/point.ts
@@ -8,7 +8,7 @@ class Point extends Model {
id: number;
userId: number;
point: number;
- status: string;
+ state: string;
imp_uid: string;
merchant_uid: string;
payment_method_type: string;
@@ -84,6 +84,12 @@ export const associate = (db: dbType) => {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
+ db.Point.hasMany(db.PointRefund, {
+ foreignKey: 'pointId',
+ sourceKey: 'id',
+ onDelete: 'CASCADE',
+ onUpdate: 'CASCADE',
+ });
};
export default Point;
diff --git a/server/src/models/pointRefund.ts b/server/src/models/pointRefund.ts
new file mode 100644
index 000000000..a83614ade
--- /dev/null
+++ b/server/src/models/pointRefund.ts
@@ -0,0 +1,107 @@
+import { BelongsToGetAssociationMixin, DataTypes, Model } from 'sequelize';
+import { sequelize } from './sequelize';
+import { dbType } from './index';
+import User from './user';
+import Point from './point';
+
+class PointRefund extends Model {
+ public dataValues!: {
+ id: number;
+ userId: number;
+ pointId: number;
+ cancel_point: number;
+ state: string;
+ imp_uid: string;
+ merchant_uid: string;
+ reason: string;
+ };
+
+ public readonly id!: number;
+ public userId!: BelongsToGetAssociationMixin
;
+ public pointId!: BelongsToGetAssociationMixin;
+ public cancel_point!: number;
+ public readonly imp_uid!: string;
+ public readonly merchant_uid!: string;
+ public state!: string;
+ public reason!: string;
+ public readonly createdAt!: Date;
+ public readonly updatedAt!: Date;
+ public readonly deletedAt!: Date;
+}
+
+PointRefund.init(
+ {
+ id: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ autoIncrement: true,
+ primaryKey: true,
+ },
+ state: {
+ type: DataTypes.STRING(50),
+ allowNull: false,
+ },
+ userId: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ references: {
+ model: 'User',
+ key: 'id',
+ },
+ },
+ pointId: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ references: {
+ model: 'Point',
+ key: 'id',
+ },
+ },
+ cancel_point: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ defaultValue: 0,
+ },
+ merchant_uid: {
+ type: DataTypes.STRING(100),
+ allowNull: false,
+ },
+ imp_uid: {
+ type: DataTypes.STRING(100),
+ allowNull: false,
+ unique: true,
+ },
+ reason: {
+ type: DataTypes.STRING(100),
+ allowNull: false,
+ },
+ },
+ {
+ sequelize,
+ timestamps: true,
+ underscored: false,
+ modelName: 'PointRefund',
+ tableName: 'PointRefund',
+ paranoid: true,
+ // mb4 -> 이모티콘도 사용 가능
+ charset: 'utf8',
+ collate: 'utf8_general_ci',
+ },
+);
+
+export const associate = (db: dbType) => {
+ db.PointRefund.belongsTo(db.User, {
+ foreignKey: 'userId',
+ targetKey: 'id',
+ onDelete: 'CASCADE',
+ onUpdate: 'CASCADE',
+ });
+ db.PointRefund.belongsTo(db.Point, {
+ foreignKey: 'pointId',
+ targetKey: 'id',
+ onDelete: 'CASCADE',
+ onUpdate: 'CASCADE',
+ });
+};
+
+export default PointRefund;
diff --git a/server/src/models/user.ts b/server/src/models/user.ts
index f1d0480ed..91e3cf27d 100644
--- a/server/src/models/user.ts
+++ b/server/src/models/user.ts
@@ -111,6 +111,12 @@ export const associate = (db: dbType) => {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
+ db.User.hasMany(db.PointRefund, {
+ foreignKey: 'userId',
+ sourceKey: 'id',
+ onDelete: 'CASCADE',
+ onUpdate: 'CASCADE',
+ });
};
export default User;
diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts
index 6b427f35f..a0506cfd5 100644
--- a/server/src/routes/auth.ts
+++ b/server/src/routes/auth.ts
@@ -2,8 +2,8 @@ import express from 'express';
const router = express.Router();
const authControllers = require('../controlloers/auth');
const authMe = require('../middlewares/auth');
-const validation = require('../middlewares/validator');
-import { body } from 'express-validator';
+// const validation = require('../middlewares/validator');
+// import { body } from 'express-validator';
// 로그인
router.post('/login', authControllers.login);
diff --git a/server/src/routes/oauth.ts b/server/src/routes/oauth.ts
index d85859bae..7131e4738 100644
--- a/server/src/routes/oauth.ts
+++ b/server/src/routes/oauth.ts
@@ -1,29 +1,29 @@
-import express from 'express';
-import passport from 'passport';
-const router = express.Router();
+// import express from 'express';
+// import passport from 'passport';
+// const router = express.Router();
-//네이버
-router.get('/naver', passport.authenticate('naver'));
-router.get(
- '/naver/callback',
- passport.authenticate('naver', {
- failureRedirect: '/',
- }),
- (req, res) => {
- res.redirect('/');
- },
-);
+// //네이버
+// router.get('/naver', passport.authenticate('naver'));
+// router.get(
+// '/naver/callback',
+// passport.authenticate('naver', {
+// failureRedirect: '/',
+// }),
+// (req, res) => {
+// res.redirect('/');
+// },
+// );
-//카카오
-router.get('/kakao', passport.authenticate('kakao'));
-router.get(
- '/kakao/callback',
- passport.authenticate('kakao', {
- failureRedirect: '/',
- }),
- (req, res) => {
- res.redirect('/');
- },
-);
+// //카카오
+// router.get('/kakao', passport.authenticate('kakao'));
+// router.get(
+// '/kakao/callback',
+// passport.authenticate('kakao', {
+// failureRedirect: '/',
+// }),
+// (req, res) => {
+// res.redirect('/');
+// },
+// );
-module.exports = router;
+// module.exports = router;
diff --git a/server/src/routes/point.ts b/server/src/routes/point.ts
index f8d61c3b5..0ecf6982f 100644
--- a/server/src/routes/point.ts
+++ b/server/src/routes/point.ts
@@ -7,7 +7,7 @@ router.get('/getToken', auth.me, pointControllers.getToken);
router.post('/approve', auth.me, pointControllers.approve);
-// router.post('/cancel', pointControllers.cancel);
+router.post('/cancel', pointControllers.cancel);
// router.post('/order', pointControllers.order);
diff --git a/server/src/routes/users.ts b/server/src/routes/users.ts
index 4aa574caf..7eb5f4294 100644
--- a/server/src/routes/users.ts
+++ b/server/src/routes/users.ts
@@ -9,5 +9,9 @@ router.get('/info', auth.me, usersControllers.usersWriteInfo);
router.get('/info/order', auth.me, usersControllers.usersOrderInfo);
router.get('/info/refund', auth.me, usersControllers.usersRefundInfo);
router.post('/:userId/img', auth.me, usersControllers.postImg);
+router.post('/nickname', usersControllers.checkNickname);
+router.get('/:userId/point', auth.me, usersControllers.paidPoint);
+router.post('/email', usersControllers.checkEmail);
+router.get('/:userId/pointRefund', auth.me, usersControllers.getRefundPoint);
module.exports = router;