From 5713d77b036dedf7c6f6b988283138d317705c34 Mon Sep 17 00:00:00 2001 From: Dominic Kolbe Date: Thu, 28 Oct 2021 13:23:12 +0100 Subject: [PATCH] refactor: move config values --- packages/pubg-frontend/src/constants.ts | 5 ----- packages/pubg-frontend/src/views/Player/index.tsx | 6 +++--- packages/pubg-server/src/api/index.ts | 9 +++++++-- packages/pubg-utils/src/index.ts | 5 +++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/pubg-frontend/src/constants.ts b/packages/pubg-frontend/src/constants.ts index 450d22c8..0514b2b5 100644 --- a/packages/pubg-frontend/src/constants.ts +++ b/packages/pubg-frontend/src/constants.ts @@ -2,10 +2,5 @@ export const APP_NAME = process.env.REACT_APP_NAME ?? "APP_NAME_MISSING"; export const API_BASE = process.env.REACT_APP_API_URL; -export const matchRequestDefaults = { - limit: 50, - offset: 0, -}; - // 5min export const PLAYER_VIEW_UPDATE_INTERVAL = 1000 * 60 * 5; diff --git a/packages/pubg-frontend/src/views/Player/index.tsx b/packages/pubg-frontend/src/views/Player/index.tsx index c81130ec..86050a64 100644 --- a/packages/pubg-frontend/src/views/Player/index.tsx +++ b/packages/pubg-frontend/src/views/Player/index.tsx @@ -17,6 +17,7 @@ import { view } from "@risingstack/react-easy-state"; import { formatDistanceToNow, parseISO } from "date-fns"; import { MatchesRequest } from "pubg-model/types/Match"; import { PlayerRequest } from "pubg-model/types/Player"; +import { PLAYER_MATCHES_REQUEST_DEFAULTS } from "pubg-utils/src"; import React, { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { ApiController } from "../../components/ApiController"; @@ -27,7 +28,6 @@ import { PlayerStatsCardLoading, } from "../../components/PlayerStatsCard"; import { rootstore } from "../../components/store"; -import { matchRequestDefaults } from "../../constants"; import { usePageview } from "../../services/Tracking/usePageview"; import { generateTotalStats } from "../../utils"; @@ -71,8 +71,8 @@ export const Player = view(() => { setMatches(null); const response = await ApiController.getPlayerMatches( id, - matchRequestDefaults.limit, - matchRequestDefaults.offset + PLAYER_MATCHES_REQUEST_DEFAULTS.LIMIT, + PLAYER_MATCHES_REQUEST_DEFAULTS.OFFSET ); if (abortCtrl.signal.aborted) return; if (response.ok) setMatches(response.val); diff --git a/packages/pubg-server/src/api/index.ts b/packages/pubg-server/src/api/index.ts index 6f9630d0..127161b4 100644 --- a/packages/pubg-server/src/api/index.ts +++ b/packages/pubg-server/src/api/index.ts @@ -6,6 +6,7 @@ import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_NOT_FOUND, HTTP_STATUS_TOO_MANY_REQUESTS, + PLAYER_MATCHES_REQUEST_DEFAULTS, } from "pubg-utils/src"; import * as rt from "runtypes"; import { ON_THE_FLY_UPDATE_INTERVAL } from "../constants"; @@ -134,8 +135,12 @@ export const setUpApi = (params: { prefix: string }) => { offset: rt.String.Or(rt.Undefined), }) .check(ctx.query); - const limit = parseInt(query.limit || "50"); - const offset = parseInt(query.offset || "0"); + const limit = parseInt( + query.limit || PLAYER_MATCHES_REQUEST_DEFAULTS.LIMIT.toString() + ); + const offset = parseInt( + query.offset || PLAYER_MATCHES_REQUEST_DEFAULTS.OFFSET.toString() + ); const matches = await PlayerDbController.findMatches( { name: ctx.params.id }, limit, diff --git a/packages/pubg-utils/src/index.ts b/packages/pubg-utils/src/index.ts index ac75519b..037d954b 100644 --- a/packages/pubg-utils/src/index.ts +++ b/packages/pubg-utils/src/index.ts @@ -62,3 +62,8 @@ export const generateNewStatsObj = () => { squadfpp: { ...STATS_OBJ }, }; }; + +export const PLAYER_MATCHES_REQUEST_DEFAULTS = { + LIMIT: 100, + OFFSET: 0, +};