From 5c4772d3078c5de27529cd29fa8001b1f7da16f1 Mon Sep 17 00:00:00 2001 From: ekachxaidze98 <65679299+ekachxaidze98@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:36:56 +0400 Subject: [PATCH] CORE: url undefined check (#358) --- api/data-provider.js | 4 +++- api/search.js | 4 +++- api/works.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/data-provider.js b/api/data-provider.js index b8659c8..267b10d 100644 --- a/api/data-provider.js +++ b/api/data-provider.js @@ -7,9 +7,11 @@ const requestV3 = (url, ...args) => request(`${API_V3_URL}${url}`, ...args) // eslint-disable-next-line camelcase const fetchMetadata = async (id, search_id) => { + const split = search_id?.split('-') + const isUndefined = split?.some((item) => item === undefined) const { data } = await requestV3( // eslint-disable-next-line camelcase - `/data-providers/${id}${search_id ? `?t=${search_id}` : ''}` + `/data-providers/${id}${!isUndefined ? `?t=${search_id}` : ''}` ) return data } diff --git a/api/search.js b/api/search.js index 9643c0d..b6f10d8 100644 --- a/api/search.js +++ b/api/search.js @@ -5,9 +5,11 @@ const FileDownload = require('js-file-download') export const fetchWorks = async (body) => { // eslint-disable-next-line camelcase const { search_id } = body + const split = search_id?.split('-') + const isUndefined = split?.some((item) => item === undefined) const url = new URL( // eslint-disable-next-line camelcase - `/v3/search/works${search_id ? `?t=${search_id}` : ''}`, + `/v3/search/works${!isUndefined ? `?t=${search_id}` : ''}`, process.env.API_URL ).href const { data: dataWorks } = await apiRequest(url, { diff --git a/api/works.js b/api/works.js index 87a25bb..bd12350 100644 --- a/api/works.js +++ b/api/works.js @@ -2,9 +2,11 @@ import apiRequest from './index' // eslint-disable-next-line camelcase const fetchWork = async (id, search_id) => { + const split = search_id?.split('-') + const isUndefined = split?.some((item) => item === undefined) const url = new URL( // eslint-disable-next-line camelcase - `/v3/works/${id}${search_id ? `?t=${search_id}` : ''}`, + `/v3/works/${id}${!isUndefined ? `?t=${search_id}` : ''}`, process.env.API_URL ).href