Skip to content

Commit 389465c

Browse files
committed
[sc-11931] resolve CodeRabbit's comments
1 parent 36a0dd0 commit 389465c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/apifetch.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ const executeApiFetch: ExecuteApiFetch = function (
188188
collectAnalytics: settings?.collectAnalytics,
189189
postfixWildcard: settings?.postfixWildcard,
190190
categories: settings?.categories ? settings?.categories.split(',') : undefined,
191-
priceFromCents: settings?.priceFromCents ? parseFloat(settings?.priceFromCents) : undefined,
192-
priceToCents: settings?.priceToCents ? parseFloat(settings?.priceToCents) : undefined,
191+
priceFromCents: settings?.priceFromCents ? parseInt(settings?.priceFromCents, 10) : undefined,
192+
priceToCents: settings?.priceToCents ? parseInt(settings?.priceToCents, 10) : undefined,
193193
dateFrom: settings?.dateFrom,
194194
dateTo: settings?.dateTo,
195195
paging: {
@@ -488,8 +488,9 @@ const executeApiFetch: ExecuteApiFetch = function (
488488

489489
if (settings?.apiMethod === 'POST' && ['search', 'suggest', 'autocomplete'].includes(type)) {
490490
apiEndpoint = 'https://' + apiHostname + '/v1/' + apiPath + '/' + sitekey;
491+
const term = type === 'search' ? decodeURIComponent(keyword) : keyword;
491492
requestPayloadObject = {
492-
term: decodeURIComponent(keyword),
493+
term: decodeURIComponent(term),
493494
...requestPayloadObject
494495
};
495496
apiInstance

src/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ class SettingsManager {
298298
}
299299

300300
setApiMethod(method: ApiMethod): void {
301+
if (method !== 'GET' && method !== 'POST') {
302+
throw new Error("API method must be 'GET' or 'POST'");
303+
}
301304
this.settings.apiMethod = method;
302305
}
303306
}

src/util.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ const generateUUID = (): string => {
5353
return uuidv4().replace(/-/g, '');
5454
};
5555

56-
const isEmptyObject = (obj: object): boolean => {
57-
return Object.keys(obj).length === 0;
56+
const isEmptyObject = (obj: unknown): boolean => {
57+
if (obj == null) {
58+
return true;
59+
}
60+
61+
if (Array.isArray(obj) || Object.prototype.toString.call(obj) !== '[object Object]') {
62+
return true;
63+
}
64+
65+
return Object.keys(obj as Record<string, unknown>).length === 0;
5866
};
5967

6068
export { isFunction, base64, validateSetPagingParams, generateUUID, isEmptyObject };

0 commit comments

Comments
 (0)