Added the language to the graphql create query, Implemented a KlicktippController that has every methode to communicate with Klicktipp, added a Klicktipp config block.

This commit is contained in:
elweyn 2021-09-05 10:38:44 +02:00
parent 0ef60ab92c
commit b376c5639f
3 changed files with 52 additions and 18 deletions

View File

@ -0,0 +1,40 @@
import * as KlicktippAPI from '../apis/KlicktippAPI'
import CONFIG from '../config'
export class KlicktippController {
private klicktippConnector: KlicktippAPI.KlicktippConnector
constructor(service?: string) {
this.klicktippConnector = new KlicktippAPI.KlicktippConnector(service)
}
async signin(email: string, language: string): Promise<boolean> {
const fields = {}
const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN
const result = await this.klicktippConnector.signin(apiKey, email, fields)
return result
}
async signout(email: string, language: string): Promise<boolean> {
const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN
const result = await this.klicktippConnector.signoff(apiKey, email)
return result
}
async userTags(email: string): Promise<any> {
await this.loginKlicktippUser()
const subscriberId = await this.klicktippConnector.subscriberSearch(email)
const result = await this.klicktippConnector.subscriberGet(subscriberId)
console.log('The subscriber with the id: ', subscriberId, result)
return result
}
private async loginKlicktippUser() {
return await this.klicktippConnector.login(CONFIG.KLICKTIPP_USER, CONFIG.KLICKTIPP_PASSWORD)
}
async untagUser(email: string, tagid: string) {
await this.loginKlicktippUser()
return await this.klicktippConnector.untag(email, tagid)
}
}

View File

@ -11,11 +11,6 @@ const server = {
LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://login-server:1201/',
COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://nginx/api/',
GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net',
KLICKTTIPP_API_URL: process.env.KLICKTIPP_API_URL || 'https://api.klicktipp.com',
KLICKTIPP_USER: process.env.KLICKTIPP_USER || 'gradido_test',
KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD || 'secret321',
KLICKTIPP_APIKEY_DE: process.env.KLICKTIPP_APIKEY_DE || 'SomeFakeKeyDE',
KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN || 'SomeFakeKeyEN',
}
const database = {
@ -26,9 +21,17 @@ const database = {
DB_DATABASE: process.env.DB_DATABASE || 'gradido_community',
}
const klicktipp = {
KLICKTTIPP_API_URL: process.env.KLICKTIPP_API_URL || 'https://api.klicktipp.com',
KLICKTIPP_USER: process.env.KLICKTIPP_USER || 'gradido_test',
KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD || 'secret321',
KLICKTIPP_APIKEY_DE: process.env.KLICKTIPP_APIKEY_DE || 'SomeFakeKeyDE',
KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN || 'SomeFakeKeyEN',
}
// This is needed by graphql-directive-auth
process.env.APP_SECRET = server.JWT_SECRET
const CONFIG = { ...server, ...database }
const CONFIG = { ...server, ...database, ...klicktipp }
export default CONFIG

View File

@ -14,11 +14,11 @@ import {
UpdateUserInfosArgs,
} from '../inputs/LoginUserInput'
import { apiPost, apiGet } from '../../apis/HttpRequest'
import { KlicktippConnector } from '../../apis/klicktippAPI'
import { KlicktippController } from '../../apis/KlicktippController'
@Resolver()
export class UserResolver {
private connector: KlicktippConnector = new KlicktippConnector(CONFIG.KLICKTTIPP_API_URL)
private connector: KlicktippController = new KlicktippController(CONFIG.KLICKTTIPP_API_URL)
@Query(() => LoginResponse)
async login(@Args() { email, password }: UnsecureLoginArgs): Promise<LoginResponse> {
@ -83,22 +83,13 @@ export class UserResolver {
password,
emailType: 2,
login_after_register: true,
language: language,
}
const result = await apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
if (!result.success) {
throw new Error(result.data)
}
// const loginSuccessful = await this.connector.login(
// CONFIG.KLICKTIPP_USER,
// CONFIG.KLICKTIPP_PASSWORD,
// )
// if (loginSuccessful) {
const fields = {}
const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN
await this.connector.signin(apiKey, email, fields)
// }
return 'success'
}