From 7df35f057b792cc25ca95a3691b86527878096c0 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 4 Apr 2023 17:07:01 +0200 Subject: [PATCH 1/2] Revert "Implement callKlickTippAPI" This reverts commit 51d572f0b795efa54f771a6d19db8675a1efa5cd. --- backend/src/apis/KlicktippController.ts | 178 ++++++++++-------------- 1 file changed, 75 insertions(+), 103 deletions(-) diff --git a/backend/src/apis/KlicktippController.ts b/backend/src/apis/KlicktippController.ts index d414bb9ec..1278b0d9c 100644 --- a/backend/src/apis/KlicktippController.ts +++ b/backend/src/apis/KlicktippController.ts @@ -4,135 +4,107 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ import CONFIG from '@/config' -import LogError from '@/server/LogError' // eslint-disable-next-line import/no-relative-parent-imports import KlicktippConnector from 'klicktipp-api' const klicktippConnector = new KlicktippConnector() -const callKlickTippAPI = (callback: (arg0: any) => any, args: any) => { - if (!CONFIG.KLICKTIPP) { - return true - } - return callback(args) -} - -export const klicktippSignIn = ( +export const klicktippSignIn = async ( email: string, language: string, firstName?: string, lastName?: string, ): Promise => { - return callKlickTippAPI( - ({ fieldFirstName, fieldLastName, language, email }) => { - const fields = { - fieldFirstName, - fieldLastName, - } - const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN - return klicktippConnector.signin(apiKey, email, fields) - }, - { - fieldFirstName: firstName, - fieldLastName: lastName, - language, - email, - }, - ) + if (!CONFIG.KLICKTIPP) { + return true + } + const fields = { + fieldFirstName: firstName, + fieldLastName: lastName, + } + const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN + const result = await klicktippConnector.signin(apiKey, email, fields) + return result } -export const signout = (email: string, language: string): Promise => { - return callKlickTippAPI( - async ({ language, email }) => { - const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN - const result = await klicktippConnector.signoff(apiKey, email) - return result - }, - { - email, - language, - }, - ) +export const signout = async (email: string, language: string): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN + const result = await klicktippConnector.signoff(apiKey, email) + return result } -export const unsubscribe = (email: string): Promise => { - return callKlickTippAPI( - async ({ email }) => { - const isLogin = await loginKlicktippUser() - if (isLogin) { - return klicktippConnector.unsubscribe(email) - } - throw new LogError(`Could not unsubscribe ${email}`) - }, - { - email, - }, - ) +export const unsubscribe = async (email: string): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + const isLogin = await loginKlicktippUser() + if (isLogin) { + return await klicktippConnector.unsubscribe(email) + } + throw new Error(`Could not unsubscribe ${email}`) } -export const getKlickTippUser = (email: string): Promise => { - return callKlickTippAPI( - async ({ email }) => { - const isLogin = await loginKlicktippUser() - if (isLogin) { - const subscriberId = await klicktippConnector.subscriberSearch(email) - return klicktippConnector.subscriberGet(subscriberId) - } - throw new LogError(`Could not get subscriber ${email}`) - }, - { - email, - }, - ) +export const getKlickTippUser = async (email: string): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + const isLogin = await loginKlicktippUser() + if (isLogin) { + const subscriberId = await klicktippConnector.subscriberSearch(email) + const result = await klicktippConnector.subscriberGet(subscriberId) + return result + } + return false } -export const loginKlicktippUser = (): Promise => { - return callKlickTippAPI(() => { - return klicktippConnector.login(CONFIG.KLICKTIPP_USER, CONFIG.KLICKTIPP_PASSWORD) - }, {}) +export const loginKlicktippUser = async (): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + return await klicktippConnector.login(CONFIG.KLICKTIPP_USER, CONFIG.KLICKTIPP_PASSWORD) } -export const logoutKlicktippUser = (): Promise => { - return callKlickTippAPI(() => { - return klicktippConnector.logout() - }, {}) +export const logoutKlicktippUser = async (): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + return await klicktippConnector.logout() } -export const untagUser = (email: string, tagId: string): Promise => { - return callKlickTippAPI( - async ({ email, tagId }) => { - const isLogin = await loginKlicktippUser() - if (isLogin) { - return await klicktippConnector.untag(email, tagId) - } - throw new LogError(`Could not untag ${email}`) - }, - { email, tagId }, - ) +export const untagUser = async (email: string, tagId: string): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + const isLogin = await loginKlicktippUser() + if (isLogin) { + return await klicktippConnector.untag(email, tagId) + } + return false } -export const tagUser = (email: string, tagIds: string): Promise => { - return callKlickTippAPI( - async ({ email, tagIds }) => { - const isLogin = await loginKlicktippUser() - if (isLogin) { - return klicktippConnector.tag(email, tagIds) - } - throw new LogError(`Could not tag ${email}`) - }, - { email, tagIds }, - ) +export const tagUser = async (email: string, tagIds: string): Promise => { + if (!CONFIG.KLICKTIPP) { + return true + } + const isLogin = await loginKlicktippUser() + if (isLogin) { + return await klicktippConnector.tag(email, tagIds) + } + return false } -export const getKlicktippTagMap = (): Promise => { - return callKlickTippAPI(async () => { - const isLogin = await loginKlicktippUser() - if (isLogin) { - return klicktippConnector.tagIndex() - } - throw new LogError(`Could not get tagIndexes`) - }, {}) +export const getKlicktippTagMap = async () => { + if (!CONFIG.KLICKTIPP) { + return '' + } + const isLogin = await loginKlicktippUser() + if (isLogin) { + return await klicktippConnector.tagIndex() + } + return '' } From b00c518863e81e30291eaf10d285efacec1c4b65 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 4 Apr 2023 17:09:32 +0200 Subject: [PATCH 2/2] Implement callKlickTippAPI --- backend/src/apis/KlicktippController.ts | 36 +++++++------------------ 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/backend/src/apis/KlicktippController.ts b/backend/src/apis/KlicktippController.ts index 1278b0d9c..a0fc6e06f 100644 --- a/backend/src/apis/KlicktippController.ts +++ b/backend/src/apis/KlicktippController.ts @@ -17,9 +17,7 @@ export const klicktippSignIn = async ( firstName?: string, lastName?: string, ): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const fields = { fieldFirstName: firstName, fieldLastName: lastName, @@ -30,18 +28,14 @@ export const klicktippSignIn = async ( } export const signout = async (email: string, language: string): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN const result = await klicktippConnector.signoff(apiKey, email) return result } export const unsubscribe = async (email: string): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const isLogin = await loginKlicktippUser() if (isLogin) { return await klicktippConnector.unsubscribe(email) @@ -50,9 +44,7 @@ export const unsubscribe = async (email: string): Promise => { } export const getKlickTippUser = async (email: string): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const isLogin = await loginKlicktippUser() if (isLogin) { const subscriberId = await klicktippConnector.subscriberSearch(email) @@ -63,23 +55,17 @@ export const getKlickTippUser = async (email: string): Promise => { } export const loginKlicktippUser = async (): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true return await klicktippConnector.login(CONFIG.KLICKTIPP_USER, CONFIG.KLICKTIPP_PASSWORD) } export const logoutKlicktippUser = async (): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true return await klicktippConnector.logout() } export const untagUser = async (email: string, tagId: string): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const isLogin = await loginKlicktippUser() if (isLogin) { return await klicktippConnector.untag(email, tagId) @@ -88,9 +74,7 @@ export const untagUser = async (email: string, tagId: string): Promise } export const tagUser = async (email: string, tagIds: string): Promise => { - if (!CONFIG.KLICKTIPP) { - return true - } + if (!CONFIG.KLICKTIPP) return true const isLogin = await loginKlicktippUser() if (isLogin) { return await klicktippConnector.tag(email, tagIds) @@ -99,9 +83,7 @@ export const tagUser = async (email: string, tagIds: string): Promise = } export const getKlicktippTagMap = async () => { - if (!CONFIG.KLICKTIPP) { - return '' - } + if (!CONFIG.KLICKTIPP) return true const isLogin = await loginKlicktippUser() if (isLogin) { return await klicktippConnector.tagIndex()