refactor: cleanup unneeded type casting
[e-mobility-charging-stations-simulator.git] / src / charging-station / ConfigurationKeyUtils.ts
index 72fb88d757ba93565cd6b93574a5914141190a4b..075a497988ae2f5375a665568be67bd7fe8dae82 100644 (file)
@@ -21,7 +21,7 @@ export const getConfigurationKey = (
   key: ConfigurationKeyType,
   caseInsensitive = false
 ): ConfigurationKey | undefined => {
-  return chargingStation.ocppConfiguration?.configurationKey?.find((configElement) => {
+  return chargingStation.ocppConfiguration?.configurationKey?.find(configElement => {
     if (caseInsensitive) {
       return configElement.key.toLowerCase() === key.toLowerCase()
     }
@@ -46,7 +46,7 @@ export const addConfigurationKey = (
   }
   params = { ...{ overwrite: false, save: false }, ...params }
   let keyFound = getConfigurationKey(chargingStation, key)
-  if (keyFound != null && params?.overwrite === true) {
+  if (keyFound != null && params.overwrite === true) {
     deleteConfigurationKey(chargingStation, keyFound.key, {
       save: false
     })
@@ -61,7 +61,7 @@ export const addConfigurationKey = (
       visible: options.visible,
       reboot: options.reboot
     })
-    params?.save === true && chargingStation.saveOcppConfiguration()
+    params.save === true && chargingStation.saveOcppConfiguration()
   } else {
     logger.error(
       `${chargingStation.logPrefix()} Trying to add an already existing configuration key: %j`,
@@ -75,7 +75,7 @@ export const setConfigurationKeyValue = (
   key: ConfigurationKeyType,
   value: string,
   caseInsensitive = false
-): void => {
+): ConfigurationKey | undefined => {
   const keyFound = getConfigurationKey(chargingStation, key, caseInsensitive)
   if (keyFound != null) {
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -90,6 +90,7 @@ export const setConfigurationKeyValue = (
       { key, value }
     )
   }
+  return keyFound
 }
 
 export const deleteConfigurationKey = (
@@ -98,13 +99,13 @@ export const deleteConfigurationKey = (
   params?: DeleteConfigurationKeyParams
 ): ConfigurationKey[] | undefined => {
   params = { ...{ save: true, caseInsensitive: false }, ...params }
-  const keyFound = getConfigurationKey(chargingStation, key, params?.caseInsensitive)
+  const keyFound = getConfigurationKey(chargingStation, key, params.caseInsensitive)
   if (keyFound != null) {
     const deletedConfigurationKey = chargingStation.ocppConfiguration?.configurationKey?.splice(
       chargingStation.ocppConfiguration.configurationKey.indexOf(keyFound),
       1
     )
-    params?.save === true && chargingStation.saveOcppConfiguration()
+    params.save === true && chargingStation.saveOcppConfiguration()
     return deletedConfigurationKey
   }
 }