From 0553ed310a896ad3795816d9f2dfa869050a80be Mon Sep 17 00:00:00 2001 From: Nghia Tran Date: Thu, 3 Oct 2024 14:08:28 +0700 Subject: [PATCH] Chore: Fix Sonar Audit --- processor/src/commercetools/action.commercetools.ts | 4 ++-- processor/src/utils/app.utils.ts | 6 +++--- processor/src/utils/mollie.utils.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/processor/src/commercetools/action.commercetools.ts b/processor/src/commercetools/action.commercetools.ts index 435b813..9cba639 100644 --- a/processor/src/commercetools/action.commercetools.ts +++ b/processor/src/commercetools/action.commercetools.ts @@ -30,8 +30,8 @@ export const setCustomFields = (fieldName: string, fieldValue: string) => { */ export const addInterfaceInteraction = (params: CreateInterfaceInteractionParams) => { const { sctm_action_type, sctm_request, sctm_response, sctm_id, sctm_created_at } = params; - const interfaceInteractionId = sctm_id ? sctm_id : uuid(); - const interfaceInteractionTimestamp = sctm_created_at ? sctm_created_at : createDateNowString(); + const interfaceInteractionId = sctm_id || uuid(); + const interfaceInteractionTimestamp = sctm_created_at || createDateNowString(); return { action: 'addInterfaceInteraction', diff --git a/processor/src/utils/app.utils.ts b/processor/src/utils/app.utils.ts index be0bb56..c1dd0be 100644 --- a/processor/src/utils/app.utils.ts +++ b/processor/src/utils/app.utils.ts @@ -32,7 +32,7 @@ export function parseStringToJsonObject( try { return JSON.parse(targetedString); } catch { - const errorMessage = `${errorPrefix ? errorPrefix : 'SCTM - PAYMENT PROCESSING'} - Failed to parse the JSON string from the custom field ${fieldName}.`; + const errorMessage = `${errorPrefix || 'SCTM - PAYMENT PROCESSING'} - Failed to parse the JSON string from the custom field ${fieldName}.`; logger.error(errorMessage, { commerceToolsId: commerceToolsId, }); @@ -48,10 +48,10 @@ export function parseStringToJsonObject( * @return {object} - The object with empty properties removed. */ export function removeEmptyProperties(obj: object) { - const clonedObject: { [key: string]: any } = Object.assign({}, obj); + const clonedObject: { [key: string]: any } = { ...obj }; for (const key in clonedObject) { - if (Object.prototype.hasOwnProperty.call(clonedObject, key)) { + if (Object.hasOwn(clonedObject, key)) { const value = clonedObject[key]; if ( diff --git a/processor/src/utils/mollie.utils.ts b/processor/src/utils/mollie.utils.ts index bb9f977..9f3cf89 100644 --- a/processor/src/utils/mollie.utils.ts +++ b/processor/src/utils/mollie.utils.ts @@ -101,7 +101,7 @@ export const calculateDueDate = (input?: string): string => { input = DEFAULT_DUE_DATE + 'd'; } - const match = input.match(DUE_DATE_PATTERN); + const match = DUE_DATE_PATTERN.exec(input); if (match) { const days = parseInt(match[1]);