Skip to content

Commit

Permalink
Refactor: api 변수값 uppercase 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehafe committed Mar 12, 2023
1 parent ec3e0c9 commit 4617f3b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<link rel="stylesheet" href="./src/scss/index.scss" />
<!-- kakao 우편번호 찾기 api -->
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script src="//dapi.kakao.com/v2/maps/sdk.js?appkey=7c9e5a646386af3e36b1fffb93f2ffcc&libraries=services"></script>
<script src="//dapi.kakao.com/v2/maps/sdk.js?appkey=26e53c394ca0000e128fe5483eb64985&libraries=services"></script>
<!-- javascript -->
<script type="module" src="./src/ts/main.ts" defer></script>
</head>
Expand Down
68 changes: 32 additions & 36 deletions src/ts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {

// dotenv 사용 예시
import dotenv from 'dotenv';
import { base_url, api_key, user_name } from './db';
import { BASE_URL, API_KEY, USER_NAME } from './db';
import { $ } from './utils/dom';
dotenv.config();

export const HEADERS = {
'content-type': 'application/json',
apikey: api_key,
username: user_name,
apikey: API_KEY,
username: USER_NAME,
};

/** API headers 함수 */
Expand All @@ -39,8 +39,8 @@ const createHeaders = ({
}: HeadersOptions = {}): HeadersInit => {
const headers: HeadersInit = {
'content-type': 'application/json',
apikey: api_key,
username: user_name,
apikey: API_KEY,
username: USER_NAME,
};

if (isMasterKey) {
Expand All @@ -63,7 +63,7 @@ export let tokenHeaders = createHeaders({
/** 전체 제품 가져오기api */
export const getAllProducts = async (): Promise<GetAllProductsInterface[]> => {
try {
const res = await fetch(`${base_url}/products`, {
const res = await fetch(`${BASE_URL}/products`, {
headers: createHeaders({ isMasterKey: true }),
});
const data = await res.json();
Expand All @@ -78,7 +78,7 @@ export const getSearchedProducts = async (
title: string,
): Promise<GetAllProductsInterface[]> => {
try {
const res = await fetch(`${base_url}/products/search`, {
const res = await fetch(`${BASE_URL}/products/search`, {
method: 'POST',
headers,
body: JSON.stringify({
Expand All @@ -98,7 +98,7 @@ export const getDetailProduct = async (
productId: string,
): Promise<GetAllProductsInterface> => {
try {
const res = await fetch(`${base_url}/products/${productId}`, {
const res = await fetch(`${BASE_URL}/products/${productId}`, {
headers,
});
const data = await res.json();
Expand All @@ -114,7 +114,7 @@ export const getAllTransactions = async (): Promise<
GetAllTransactionsInterface[]
> => {
try {
const res = await fetch(`${base_url}/products/transactions/details`, {
const res = await fetch(`${BASE_URL}/products/transactions/details`, {
headers: tokenHeaders,
});
const data = await res.json();
Expand All @@ -134,7 +134,7 @@ export const confirmTransactionAPI = async (
detailId: string,
): Promise<CancelConfirmTransactionAPI> => {
try {
const res = await fetch(`${base_url}/products/ok`, {
const res = await fetch(`${BASE_URL}/products/ok`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -153,7 +153,7 @@ export const cancelTransactionAPI = async (
detailId: string,
): Promise<CancelConfirmTransactionAPI> => {
try {
const res = await fetch(`${base_url}/products/cancel`, {
const res = await fetch(`${BASE_URL}/products/cancel`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -171,7 +171,7 @@ export const cancelTransactionAPI = async (
/** 주문 상세정보 조회 API */
export const getDetailOrderProduct = async (detailId: string) => {
try {
const res = await fetch(`${base_url}/products/transactions/detail`, {
const res = await fetch(`${BASE_URL}/products/transactions/detail`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -188,7 +188,7 @@ export const getDetailOrderProduct = async (detailId: string) => {
/** 계좌 목록 및 잔액 조회 db에서 불러오기 */
export const getAccountDetail = async (): Promise<Bank[]> => {
try {
const res = await fetch(`${base_url}/account`, {
const res = await fetch(`${BASE_URL}/account`, {
headers: tokenHeaders,
});
const data = await res.json();
Expand All @@ -206,7 +206,7 @@ export const buyItemAPI = async (
accountId: string,
): Promise<BuyItemAPI> => {
try {
const res = await fetch(`${base_url}/products/buy`, {
const res = await fetch(`${BASE_URL}/products/buy`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -224,7 +224,7 @@ export const buyItemAPI = async (
/** [결제 페이지] 로그인 한 정보 가져오기 */
export const getUserInfoAPI = async (): Promise<GetUserInfoAPI> => {
try {
const res = await fetch(`${base_url}/auth/me`, {
const res = await fetch(`${BASE_URL}/auth/me`, {
method: 'POST',
headers: tokenHeaders,
});
Expand All @@ -241,7 +241,7 @@ export const addProduct = async (product: AddProduct): Promise<void> => {
const { title, price, description, tags, thumbnailBase64 } = product;

try {
await fetch(`${base_url}/products`, {
await fetch(`${BASE_URL}/products`, {
method: 'POST',
headers: masterKeyHeaders,
body: JSON.stringify({
Expand All @@ -260,7 +260,7 @@ export const addProduct = async (product: AddProduct): Promise<void> => {
/** 단일 상품 삭제 API */
export const deleteProduct = async (id: string): Promise<void> => {
try {
await fetch(`${base_url}/products/${id}`, {
await fetch(`${BASE_URL}/products/${id}`, {
method: 'DELETE',
headers: masterKeyHeaders,
});
Expand All @@ -277,7 +277,7 @@ export const editProduct = async (
product;

try {
await fetch(`${base_url}/products/${product.id}`, {
await fetch(`${BASE_URL}/products/${product.id}`, {
method: 'PUT',
headers: masterKeyHeaders,
body: JSON.stringify({
Expand All @@ -297,7 +297,7 @@ export const editProduct = async (
/**전체 거래 내역 가져오기 API */
export const getAllOrder = async (): Promise<TransactionDetailInterface[]> => {
try {
const res = await fetch(`${base_url}/products/transactions/all`, {
const res = await fetch(`${BASE_URL}/products/transactions/all`, {
method: 'GET',
headers: masterKeyHeaders,
});
Expand All @@ -313,7 +313,7 @@ export const editDoneOrder = async (order: ConfirmOrder): Promise<void> => {
const { detailId, done } = order;

try {
const res = await fetch(`${base_url}/products/transactions/${detailId}`, {
const res = await fetch(`${BASE_URL}/products/transactions/${detailId}`, {
method: 'PUT',
headers: masterKeyHeaders,
body: JSON.stringify({
Expand All @@ -333,7 +333,7 @@ export const editCancelOrder = async (order: ConfirmOrder): Promise<void> => {
const { detailId, isCanceled } = order;

try {
await fetch(`${base_url}/products/transactions/${detailId}`, {
await fetch(`${BASE_URL}/products/transactions/${detailId}`, {
method: 'PUT',
headers: masterKeyHeaders,
body: JSON.stringify({
Expand All @@ -347,7 +347,7 @@ export const editCancelOrder = async (order: ConfirmOrder): Promise<void> => {

/** API : 은행 목록 */
export const getBankList = async (): Promise<GetBankListValue> => {
const res = await fetch(`${base_url}/account/banks`, {
const res = await fetch(`${BASE_URL}/account/banks`, {
method: 'GET',
headers: tokenHeaders,
});
Expand All @@ -358,7 +358,7 @@ export const getBankList = async (): Promise<GetBankListValue> => {

/** API : 계좌 조회 */
export const getUserAccounts = async (): Promise<GetUserAccounts> => {
const res = await fetch(`${base_url}/account`, {
const res = await fetch(`${BASE_URL}/account`, {
method: 'GET',
headers: tokenHeaders,
});
Expand All @@ -369,7 +369,7 @@ export const getUserAccounts = async (): Promise<GetUserAccounts> => {

/** API : 계좌 개설 */
export const createUserAccount = async (bankCode: string): Promise<boolean> => {
const res = await fetch(`${base_url}/account`, {
const res = await fetch(`${BASE_URL}/account`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -389,7 +389,7 @@ export const createUserAccount = async (bankCode: string): Promise<boolean> => {
// API : 계좌 해지
export const deleteAccount = async (e: any): Promise<DeleteAccount> => {
const accountId = e.target.dataset.id;
const res = await fetch(`${base_url}/account`, {
const res = await fetch(`${BASE_URL}/account`, {
method: 'DELETE',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -404,7 +404,7 @@ export const deleteAccount = async (e: any): Promise<DeleteAccount> => {

/** API : Login */
export async function login(): Promise<PersonalInfoLogin> {
const res = await fetch(`${base_url}/auth/login`, {
const res = await fetch(`${BASE_URL}/auth/login`, {
method: 'POST',
headers,
body: JSON.stringify({
Expand All @@ -424,7 +424,7 @@ export async function login(): Promise<PersonalInfoLogin> {

/** API : Logout */
export async function logout(): Promise<boolean> {
const res = await fetch(`${base_url}/auth/logout`, {
const res = await fetch(`${BASE_URL}/auth/logout`, {
method: 'POST',
headers: tokenHeaders,
});
Expand All @@ -438,13 +438,9 @@ export async function authorization(): Promise<Authorization> {
tokenHeaders = createHeaders({
token: localStorage.getItem('marketLogToken'),
});
const res = await fetch(`${base_url}/auth/me`, {
const res = await fetch(`${BASE_URL}/auth/me`, {
method: 'POST',
headers: tokenHeaders,
// headers: {
// ...HEADERS,
// Authorization: `Bearer ${localStorage.getItem('marketLogToken')}`,
// },
});

if (res.ok) {
Expand All @@ -456,7 +452,7 @@ export async function authorization(): Promise<Authorization> {

//사용자 정보 수정 api 사용
export async function submitChangeInfo() {
const res = await fetch(`${base_url}/auth/user`, {
const res = await fetch(`${BASE_URL}/auth/user`, {
method: 'PUT',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -470,7 +466,7 @@ export async function submitChangeInfo() {
}
// 비밀번호 재확인(login api 사용)
export async function personalInfoLogin(auth: any): Promise<PersonalInfoLogin> {
const res = await fetch(`${base_url}/auth/login`, {
const res = await fetch(`${BASE_URL}/auth/login`, {
method: 'POST',
headers: tokenHeaders,
body: JSON.stringify({
Expand All @@ -484,7 +480,7 @@ export async function personalInfoLogin(auth: any): Promise<PersonalInfoLogin> {
}
/** API : 회원가입 */
export async function signup(): Promise<RegisterRes> {
const res = await fetch(`${base_url}/auth/signup`, {
const res = await fetch(`${BASE_URL}/auth/signup`, {
method: 'POST',
headers: headers,
body: JSON.stringify({
Expand All @@ -499,7 +495,7 @@ export async function signup(): Promise<RegisterRes> {

/** API : 사용자 목록 조회 */
export async function getUserList(): Promise<GetUserInfos> {
const res = await fetch(`${base_url}/auth/users`, {
const res = await fetch(`${BASE_URL}/auth/users`, {
method: 'GET',
headers: masterKeyHeaders,
});
Expand Down
8 changes: 4 additions & 4 deletions src/ts/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// dotenv 사용 예시
export const base_url = process.env.BASE_URL;
export const api_key = process.env.API_KEY;
export const user_name = process.env.USER_NAME;
export const admin_email = process.env.ADMIN_EMAIL;
export const BASE_URL = process.env.BASE_URL;
export const API_KEY = process.env.API_KEY;
export const USER_NAME = process.env.USER_NAME;
export const ADMIN_EMAIL = process.env.ADMIN_EMAIL;
1 change: 0 additions & 1 deletion src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ router
handleSearchPage();
},
'/product/:id': (params: Params) => {
// renderSkeletonUIinDetailProductPage();
handleDetailProductPage(params.data.id);
},
'/cart': () => {
Expand Down
5 changes: 3 additions & 2 deletions src/ts/page/admin/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ const setDashBoardChartAmount = (

const thisWeek: number[] = [];

// 최근 일주일의 날짜를 가져옴
for (let i = 0; i < 7; i++) {
thisWeek.unshift(Number(getDate(i).date));
}

// 이번 주 각 날짜에 해당하는 거래의 금액 합계를 계산함
const amountOfthisWeek: number[] = [];

for (let i = 0; i < 7; i++) {
Expand All @@ -108,6 +110,7 @@ const setDashBoardChartAmount = (
);
}

// 차트 렌더링
new Chart(chartAmount, {
type: 'line',
data: {
Expand All @@ -130,8 +133,6 @@ const setDashBoardChartAmount = (
});
};

/** 현재 날짜 가져오기 */

/** 거래, 상품 현황 상태 설정 */
const setCurrentStatus = (
orders: TransactionDetailInterface[],
Expand Down
6 changes: 3 additions & 3 deletions src/ts/page/loginPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $ } from '../utils/dom';
import { admin_email } from '../db';
import { ADMIN_EMAIL } from '../db';
import { router } from '../main';
import { renderPage } from '../utils/render';
import { outlink } from '../importIMGFiles';
Expand Down Expand Up @@ -53,7 +53,7 @@ function displayUserName(personalInfo: PersonalInfoLogin) {
ulLoginHeaderEl.innerHTML = htmlHeaderLogout;

$('#header__user-login-name').innerText = personalInfo.user.displayName;
if (personalInfo.user.email === admin_email) {
if (personalInfo.user.email === ADMIN_EMAIL) {
$('#btnMypage').innerHTML = `
<strong id="header__user-login-name">관리자 페이지로 이동<img class="admin--outlink" src="${outlink}" alt="OutLink"/></span></strong>
`;
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function renderInitHeaderLogin() {
ulLoginHeaderEl.innerHTML = htmlHeaderLogout;

$('#header__user-login-name').innerText = userDisplayName;
if (userEmail === admin_email) {
if (userEmail === ADMIN_EMAIL) {
$<HTMLAnchorElement>('#btnMypage').href = '/admin';
$<HTMLAnchorElement>('#btnMypage').innerHTML = `
<strong id="header__user-login-name">관리자 페이지로 이동
Expand Down
1 change: 1 addition & 0 deletions src/ts/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface getDateInterface {
date: string;
}

/** 현재 날짜 가져오기 */
export const getDate = (prevDateNum: number = 0): getDateInterface => {
const today = new Date();

Expand Down

0 comments on commit 4617f3b

Please sign in to comment.